2 Replies Latest reply on Apr 7, 2015 1:01 PM by Patrick.Cashman

    Through VB/C# get all vias from the active document


      Hello All,


                      I have PCB Design were I have 125 vias when I zoomed the design then at  that point I have 15 vias.So when I run the script I should get 15 vias only not 125 which reduces the time.How can this be achieved through script.Kindly help me.



      Thanks & Regards,


        • 1. Re: Through VB/C# get all vias from the active document

          If you are talking about Xpedition, Vias are a collection and these are the collection methods exposed:




          I guess you could get the zoom extents, and walk through the vias collection and throw out the ones that are not inside the display coordinates.  I usually have the user select or mark or highlight the ones they are interested in.



          • 2. Re: Through VB/C# get all vias from the active document

            The following code is for vb.net.  If you use vbs or another language, it will be slightly different:  It assumes that doc is the PCB document object, and has been declared and initialized elsewhere.


            Sub get_vias()


                     Dim view As MGCPCB.View

                     Dim ext As MGCPCB.Extrema

                     Dim pstks

                     Dim pstk As MGCPCB.PadstackObject

                     Dim n As Integer

                     Dim vias As MGCPCB.Vias

                     Dim via As MGCPCB.Via




                     view = doc.ActiveViewEx

                     ext = view.Extrema


                     pstks = doc.Pick(ext.MinX,ext.MinY,ext.MaxX, ext.MaxY, 1, , True, False)


                     n = 0

                     For Each pstk In pstks

                         If pstk.Type = 2 Then

                             n = n + 1

                             pstk.Selected = True

                         End If



                     Debug.Print("found " & n & " vias")


                     vias = doc.Vias(1)


                     For Each via In vias

                         Debug.Print("via on net " & via.Net.Name & " found at " & via.PositionX & "," & via.PositionY)




                 End Sub

            The pick method of the document object is the key. The layerobjects argument of the pick method is not needed in this case, so it is omitted. The last two arguments (visible and get items on components) are also optional and could also probably be left out.


            The trick to using the pick method is to only select a generic object type as the receiving variable (pstks in this case). If you try to use a data type with this variable, it won't work.  When you later iterate through the selected items, you use a typed variable (pstk) to do that, and then you get all the appropriate properties and methods of that data type.


            If you have a design with many vias, this method will be much faster than iterating through all the vias in the design.