7 Replies Latest reply on Aug 3, 2010 6:04 AM by french

    DxDesigner automation in vb.net

    french

      In this example the call comp.SymbolBlock.ChangeComponent changes every instance of the old component on the current sheet once the first component is found that meets the stated criteria.  The way this is written one would expect that this call should only change the current component.  This really wouldnt be an issue if I didn't need to move the onsheet components after the swap so that the net and pin connect correctly.  How do I change a component from type "A" to type "B" but do them one at a time?

       

      DxDesigner version EE7.9

       

          Private Sub FindOffPage()
              Dim schmObj As ViewDraw.IStringList
              Dim sheetObj As ViewDraw.IStringList
              Dim compObj As ViewDraw.IVdObjs
              Dim comp As ViewDraw.Component
              Dim loc As ViewDraw.IVdPoint
              Dim compName As String

       

              'Get the list of schematics in project
              schmObj = appDX.SchematicSheetDocuments.GetAvailableSchematics

       

              'Iterate through each schematic
              For x = 1 To schmObj.GetCount

       

                  'Get list of sheets in current schematic
                  sheetObj = appDX.SchematicSheetDocuments.GetAvailableSheets(schmObj.Item(x))

       

                  'Iterate through each sheet in current schematic
                  For y = 1 To sheetObj.GetCount

       

                      appDX.SchematicSheetDocuments.Open(schmObj.GetItem(x), sheetObj.GetItem(y))

       

                      'Get collection of all components on current sheet
                      compObj = appDX.ActiveView.Query(ViewDraw.VdObjectTypeMask.VDM_COMP, ViewDraw.VdAllOrSelected.VD_ALL)

       

                      'Iterate through each component in current sheet
                      For z = 1 To compObj.Count

       

                          comp = compObj.Item(z)
                          compName = comp.SymbolBlock.GetName(ViewDraw.VdNameType.FULL_PATH_FROM_BLOCK)

       

                          'Test if current component is type offpage
                          Select Case compName

       

                              Case "offpage_out"
                                  Try
                                      comp.SymbolBlock.ChangeComponent(compName, "offsheet")
                                  Catch
                                  End Try

       

                              Case "offpage_in"
                                  Try
                                      comp.SymbolBlock.ChangeComponent(compName, "onsheet")
                                      'loc = comp.GetLocation()
                                      'comp.SetLocation(loc.X - 1, loc.Y)
                                  Catch
                                  End Try

       

                          End Select
                         
                      Next

       

                      appDX.SchematicSheetDocuments.Close()

       

                  Next

       

              Next

       

          End Sub

        • 1. Re: DxDesigner automation in vb.net
          john_dube

          Hi French,

           

          Set the Selected property of the component to true, then call ChangeComponent with the first argument of "< Selected Components >", then set the Selected property to false, and continue the loop.

           

          By the way, you want to call the ChangeComponent method on the schematic block (ActiveView.Block), not the symbol block (Comp.SymbolBlock).

           

          John

          • 2. Re: DxDesigner automation in vb.net
            french

            Okay so I am still a little bit confused here.  I added comp.selected = true and switched to using ChangeComponent from block (Don't understand what the difference is though).  The part that Im not getting is the "call ChangeComponent with the first argument of "< Selected Components >"".  ChangeComponent wants strings passed to it and Im not seeing a method to act on only selected components.  What am I missing?

             

             

            Select Case compName

             

                 Case "offpage_out"

             

                 Try

                      comp.Selected =True

                      appDX.ActiveView.Block.ChangeComponent(compName,"offsheet")

                 Catch

             

                 End Try

             

                 Case "offpage_in"

             

                 Try

                      comp.Selected =True

                      appDX.ActiveView.Block.ChangeComponent(compName,"onsheet")

            Catch

             

            End Try

             

            End Select

            comp.Selected =False

            • 3. Re: DxDesigner automation in vb.net
              john_dube

              From the DxDesigner Automation Reference:

               

              The special string "< Selected Components >" will cause all the components on the selected list

              to be replaced by the new component. This method returns False on a normal failure and it
              throws an Automation exception if the special string is used and there are not any components
              on the selected list.

               

              So instead of using the symbol name, which replaces all instances of that symbol, just select the component, and use the special string.

               

              John

              1 of 1 people found this helpful
              • 4. Re: DxDesigner automation in vb.net
                french

                Got it working now.  Thanks for the clarification, and the quick answers John!

                • 5. Re: DxDesigner automation in vb.net
                  french

                  John,

                   

                  When I run the following code I get the following error in Dx and Im not sure why.  Your assistance to the problem would be appreciated.  The error is thrown during the SetLocation command.

                   

                  Commit Database Transaction Rejected, Reloading Project.

                   

                  Case "offpage_in"

                   

                  Try

                       comp.Selected =True

                       appDX.ActiveView.Block.ChangeComponent("< Selected Components >", "onsheet")

                       appDX.ActiveView.Block.DeSelectAll()

                       loc = comp.GetLocation()

                       comp.SetLocation(loc.X - 35, loc.Y)

                   

                  Catch

                   

                  End Try

                   

                  • 6. Re: DxDesigner automation in vb.net
                    john_dube

                    Hi French,

                     

                    I think the comp object becomes stale when you run the ChangeComponent method.  It's strange that you can get the location after calling ChangeComponent, but you cannot move the component.

                     

                    Your best bet would be to do the ChangeComponent first (I guess that eliminates the requirement to only work with the selected component), then do the Query and move the off"onsheet" components, like this:

                     

                    ActiveView.Block.ChangeComponent "offpage_in", "onsheet"

                    For Each Comp in ActiveView.Query(VDM_COMP, VD_ALL)

                         If comp.SymbolBlock.GetName(ViewDraw.VdNameType.FULL_PATH_FROM_BLOCK) = "offpage_in" Then

                              loc = comp.GetLocation()

                              comp.SetLocation(loc.X - 35, loc.Y)

                         End If

                    Next

                     

                    John

                    1 of 1 people found this helpful
                    • 7. Re: DxDesigner automation in vb.net
                      french

                      Yeah that makes sense the item stored is no longer valid since I changed it.  It is indeed strange that I was able to pull the location of the new component with that command.  If it had thrown the error at me when I was trying to pull the location I probably would have realized that the current component I was working with was no longer valid.  Thats my excuse and Im sticking with it : )

                       

                      Thanks again John, everything is working like a champ now.