2 Replies Latest reply on Aug 22, 2014 7:18 AM by m_ba

    How to get all open schematic

    m_ba

      Hi,

       

      I would like to perform some actions but only on the open schematics.

       

      Something like:

       

      Dim My_Dx_App As ViewDraw.Application

      Dim My_Documents As Variant

      Dim My_SchematicSheetDocs As ViewDraw.StringList

       

      For Each My_Documents In My_Dx_App.ActiveDocuments.SchematicSheetDocuments.GetAvailableSchematics

                      Set My_SchematicSheetDocs = My_Dx_App.SchematicSheetDocuments.GetAvailableSheets(My_Documents)

                      For Each My_SchematicSheetDoc In My_SchematicSheetDocs

                                      Set My_WorkDoc = My_Dx_App.SchematicSheetDocuments.Open(My_Documents, My_SchematicSheetDoc)

                                      Debug.Print My_WorkDoc.Name + page number

                      Next

      Next

       

       

      I tried with:

      For Each My_WorkDoc In My_Dx_App.OpenBlocks(VDDT_SCHEMATIC)

      But unfortunately, depending how you open the schematic (push into hierarchy or opening the block...), schematics will be listed more than once 

       

      Regards,

        • 1. Re: How to get all open schematic
          Satoru

          Hi m_ba,

           

          Please try a sample code.

           

          Regards,

          Satoru

           

          ##############################################################################

          Sub Open_AllSheet()

              Dim schName

              Dim schDocs, schDoc

              Dim shetList

              Dim i

           

              ' Get Schematic Name

              schName = dxdApp.GetProjectData.GetiCDBDesignRootBlock(dxdApp.GetActiveDesign)

           

              ' Get Schematic Sheet Documents

              Set schDocs = dxdApp.SchematicSheetDocuments

           

              ' Get Sheets List

              Set shetList = schDocs.GetAvailableSheets(schName)

           

              For i = 1 To shetList.GetCount

                  ' Open Schematic Sheet Document

                  Set schDoc = schDocs.Open(schName, shetList.GetItem(i))

           

                  ' Set Active Window

                  Call schDoc.Activate

              Next

          End Sub

          ##############################################################################

          • 2. Re: How to get all open schematic
            m_ba

            thx Saturu!

             

            Code update without duplicates

             

            Private Sub All_Open_Sheets()
            Dim My_Dx_Prj

            Dim My_Documents
            Dim My_SchematicSheetDocs

            Dim My_SchematicSheetDoc
            Dim My_WorkDoc

            Dim My_Components
            Dim My_Component

            Dim My_Schematics_Dictionary
            Set My_Schematics_Dictionary = CreateObject("Scripting.Dictionary")
            Dim My_Schematics_Collection
            Set My_Schematics_Collection = CreateObject("Scripting.Dictionary")
            Dim i

                Set My_Dx_App = GetObject(, "ViewDraw.Application") 'DxDesigner needs to be open!
                If My_Dx_App Is Nothing Then
                    My_Output_Screen vbMsgBox, "Could not connect to DxDesigner Apllication!"
                Else
                    My_Dx_Prj = My_Dx_App.GetActiveDesign 'Check if there's an open project
                    If My_Dx_Prj = "" Then
                        My_Output_Screen My_Output, "No open project found!"
                    Else
               If (My_Dx_App.ActiveView Is Nothing) And ((optbutScope.Value = ScopeActiveSheet) _
                          Or (optbutScope.Value = ScopeOpenSheets) _
                          Or (optbutScope.Value = ScopeBoard)) Then 'Requirements: Project needs to be open and depending of the scoop, also schematics
                My_Output_Screen My_Output, "No View present. Please open a schematic!"
               Else
                i = 0
                Set My_Documents = My_Dx_App.SchematicSheetDocuments 'Return the collection of all open schematics (schematics will be listed as many time they are open!)
                'Build up a collection with 'single' schematics (schematic listed only once) and open in read/write mode
                For Each My_SchematicSheetDoc In My_Documents
                 If My_SchematicSheetDoc.IsReadOnly Then
                  My_Output_Screen My_Output, "WARNING '" & My_SchematicSheetDoc.Name & "' is open in read only mode!"
                 Else
                  If IsEmpty(My_Schematics_Dictionary(My_SchematicSheetDoc.Name)) Then 'Check if the schematic has already be added to the collection
                   i = i + 1
                   'Stucture
                   '   My_Schematics_Dictionary
                   '       Key:    Schematic.Name (String)
                   '       Value:  Number          'just to have a link with the My_Schematics_Collection / otherwise may be set equal to '0'
                   '   My_Schematics_Collection
                   '       Key:    Number
                   '       Value:  Schematic (Object)
                   My_Schematics_Dictionary(My_SchematicSheetDoc.Name) = i '0 'Collection with unique SchematicSheetDocument list
                   My_Schematics_Collection.Add i, My_SchematicSheetDoc 'Collection with unique list of schematic
                  Else
                   My_SchematicSheetDoc.Close True, My_SchematicSheetDoc.Name
                  End If
                 End If
                Next
                Do While i
                 My_Schematics_Collection(i).Activate 'Mandatrory with .ActiveView.Query call (see below)
                 Set My_Components = My_Schematics_Collection(i).Parent.Application.ActiveView.Query(VDM_COMP, VD_ALL) 'Components collection from only Active View
                 '*** perform actions on components
                 My_Output_Screen My_Output, My_Schematics_Collection(i).Name & "... Done!"
                 i = i - 1
                Loop
               End If

                Set My_Schematics_Collection = Nothing
                Set My_Schematics_Dictionary = Nothing
                Set My_Component = Nothing
                Set My_Components = Nothing
                Set My_WorkDoc = Nothing
                Set My_SchematicSheetDoc = Nothing
                Set My_SchematicSheetDocs = Nothing
                Set My_Documents = Nothing
            End Sub