2 Replies Latest reply on Mar 5, 2012 1:20 PM by jim.frederick

    DxDesigner scripting, change net.name to match Component name

    jim.frederick

      I'm looking for some sample .VBS code or suggestions to rename some net names to match the component name that it's attached to. For example, if I have components Cx for x=1 thru 100, I'd like to change all net names for nets connected to pin 1 using a name like Nx - so the net connected to C1 pin 1 would get a name N1 and C2 pin 1 would get a name N2 and so on.

       

      I'm new to DxDesigner automation but I'm familiar with VBS and text manipulation (including regular expressions).

       

      Why I want to do this: I have a matrix of hundreds of components that need to be interconnected. The interconnection algorithm is easy for me to code in .VBS and is certaily easier than manually drawing interconnections by hand.

       

      So, I could use some sample code or suggestions that would help me go thru a list of selected components, determine the component name, find the net connected to a pin on the component and rename that net.

       

      Thanks!

       

      -JF

        • 1. Re: DxDesigner scripting, change net.name to match Component name
          john_dube

          Hi Jim,

           

          Here is a starting point:

           

               ' Loop over every selected component

               For Each comp in ActiveView.Query(VDM_COMP, VD_SELECTED)

                    ' Get the refdes value

                    sRefdes = comp.RefDes

                    ' Loop over every pin-net connection

                    For Each conn in comp.GetConnections

                         ' If there is a net connected to the pin

                         If Not conn.Net Is Nothing Then

                              ' Find the net label

                              For Each seg in conn.Net.GetSegments

                                   If Not conn.Net.GetLabel(seg) Is Nothing Then

                                        ' change the text string property to rename the net

                                        conn.Net.GetLabel(seg).TextString = sRefDes & "_" & conn.CompPin.Number

                                   End If

                              Next

                         End If

                    Next

               Next

           

          Hope this helps,

           

          John

          • 2. Re: DxDesigner scripting, change net.name to match Component name
            jim.frederick

            John-

             

            Thanks! That was extremely helpful and helped me up the learning curve very quickly. Here's what I used...

            DIM VDM_COMP    : VDM_COMP =  128

            DIM VD_SELECTED : VD_SELECTED = 1

            Dim cntReplace : cntReplace=0

            Dim comp ' component

            For Each comp in ActiveView.Query(VDM_COMP, VD_SELECTED) ' Assume components selected.

               DIM sRefdes : sRefdes = comp.RefDes

               If Len(sRefdes)>0  Then ' If there's a refdes...

                  DIM conn ' Connection

                  For Each conn in comp.GetConnections ' For each pin on device...

                     If Not conn.net Is Nothing Then ' If there is a net connected to the pin

                        DIM seg ' Segment

                        For Each seg in conn.net.GetSegments

                           Dim lbl : Set lbl = conn.net.GetLabel(seg)

                           If Not lbl Is Nothing Then

                              Dim refDesNum : refDesNum = right( sRefDes, len(sRefDes)-1 ) ' Get numeric portion of refdes.

                              Dim sColor

                              if 1=conn.CompPin.Number Then sColor="B" else ' pin 1 is B

                              if 2=conn.CompPin.Number Then sColor="G" else ' pin 2 is G

                              if 3=conn.CompPin.Number then sColor="R" end if ' pin 3 is R

                              Dim newTxt : newTxt = sColor & refDesNum ' Something like R200 or B200 etc.

                              lbl.TextString = newTxt ' Apply new text to label.

                              cntReplace = cntReplace + 1

                              MsgBox sRefdes & "." & conn.CompPin.Number & "=" & newTxt & ". (" & cntReplace & ")"

                           Else

                              MsgBox sRefdes & "." & conn.CompPin.Number & " has no label"

                           End If ' if label on net

                        Next ' seg

                     End If ' if net on pin

                  Next ' conn

               End If ' if refdes

            Next ' comp

             

            MsgBox "Done. Replaced " & cntReplace & " labels."