2 Replies Latest reply on Jul 31, 2013 4:52 PM by mcrist

    How do you add a net and attach it to a pin on a symbol?

    mcrist

      We often get Excel spreadsheets with a list of connector pins and signal names that are connected to those pins.  We then have to manually place a connector symbol (which represents a single pin on the connector) and type in the name of the signal and the pin number.  This is a very tedious process.  Instead, I am trying to write a bit of code that will place the connector symbols automatically, create a net attached to the single pin on the symbol, then name the net.

       

      The Excel spreadsheet has 5 columns:

      - Partition (stored in the addpartition variable)

      - Part Number (stored in the addpart variable)

      - Symbol Name (stored in the addsym variable)

      - Pin Number (stored in the addpin variable)

      - Reference Designator (stored in the addref variable)

      - Net Name (stored in the addnet variable)

       

      Placing the symbol works properly with the code below.

       

      '-----

       

      thispart = vdApp.ActiveView.Block.AddPartInstance(addpartition, addpart, addsym, offsetx, offsety)

      thispart.Refdes = addrefdes

      thispart.Selected = True

       

      '-----

       

      I think I need to have a pin object to use the vdApp.ActiveView.Block.AddNet function properly.  However, when I try to determine the pin on the symbol to connect to using Query, I get 0 objects for pins.  I have also tried with a type mask of VDM_PIN with no luck (0 objects). 

      '-----

       

       

      mypins = vdApp.Query(ViewDraw.VdObjectTypeMask.VDM_COMPPIN, ViewDraw.VdAllOrSelected.VD_SELECTED)

       

       

       

       

      For obj As Integer = 1 To mypins.Count

           thisobj = mypins.Item(obj)

       

       

       

           If thisobj.Type = ViewDraw.VdObjectType.VDTS_COMPPIN Then

                attachpin = mypins.Item(obj)

           End If

       

       

      Next

       

      '-----

       

       

       

       

      How can I get the pin object from the symbol that I just placed?  Also, in the code below, am I using the vdApp.ActiveView.Block.AddNet function properly?

       

      thisnet = vdApp.ActiveView.Block.AddNet(offsetx + 80, offsety, offsetx + 100, offsety, attachpin,Nothing, ViewDraw.VdBusOrWire.VD_WIRE)

       

      thisnet.AddLabel(thisnet.GetSegments(), addnet, 0, 0)

       

       

       

       

       

       

       

       

       

       

       

       

       

       

        • 1. Re: How do you add a net and attach it to a pin on a symbol?
          john_dube

          Hi,

           

          Go through the connections on the component object returned by AddPartInstance.

           

          Another way to accomplish this would be to select the component, call the "stub" command and then walk the nets to relabel or delete as needed.

           

          John

          1 of 1 people found this helpful
          • 2. Re: How do you add a net and attach it to a pin on a symbol?
            mcrist

            Thanks John, I realized that I was trying to make it too hard.  I already had the component instance I needed (thispart).  This is what I ended up changing the code to:

             

            ' Add the part from the file as specified

            thispart = vdApp.ActiveView.Block.AddPartInstance(addpartition, addpart, addsym, offsetx, offsety)

            thispart.Refdes = addrefdes

            thispart.Selected = True

              

             

            ' Get the list of connections on the part we just added

            conns = thispart.GetConnections()

            conn = CType(conns.Item(Int(addconn)), ViewDraw.IVdConnection)

            attachpin = conn.CompPin

             

            thisnet = vdApp.ActiveView.Block.AddNet(offsetx + 80, offsety, offsetx + 100, offsety, attachpin, Nothing, ViewDraw.VdBusOrWire.VD_WIRE)

            segs = thisnet.GetSegments()

            seg = CType(segs.Item(1), ViewDraw.IVdSegment)

            segloc = seg.Location(1)

            thisnet.AddLabel(seg, addnet, segloc.X + 5, segloc.Y + 1)

             

            thispart.Selected = False

            thispart = Nothing