10 Replies Latest reply on Mar 26, 2013 7:27 AM by matheisl.florian

    Netlist report (alphanumerical sort) with vbs script

    cristiano.murtas

      Hello, everyone!
      I'm working on a script to get a netlist in this format:

       

      NetClassNetNamePinCountAll_Ref.Pin (not sorted)
      CHANNELNET_A3JA1.1,CNT1_1.2,JA2.1,
      CHANNELNET_B5C2_1.2,C1_1.2,DUT.54,DUT.328,DUT.250,
      CHANNELNET_C3JA1.3,JA2.3,CNT2_1.2,
      CHANNELNET_D3DUT.432,C4_1.2,CNT2_1.1,

       

       


      The problem is that I can sort only NetName, I don't know how to sort comp.ref.pin (All_Ref.Pin column) information extracted from netlist.

      Here the vbs code used:

       

      '***********************************************************

      ' Get a collection of nets.
      Dim netColl   ' Collection of all nets
      Dim netObj   ' Net object for iteration
      Dim countNet
      Set netColl = pcbDocObj.Nets
      Dim pin

      ' Sort the component collection
         Call netColl.Sort()
        
      countNet = 0


      ' Iterate through all nets
      For Each netObj In netColl
      ' Report information on each net.
      txtStreamObj.Write(netObj.NetClass)
      txtStreamObj.Write(vbTab & netObj.Name)
      countNet = countNet + 1
      txtStreamObj.Write(vbTab & netObj.Pins.Count & vbTab)
         For Each pin In netObj.Pins
          txtStreamObj.Write(pin.component.refdes & "." & pin.name & ",")
         Next
      txtStreamObj.WriteLine()
      Next

      '***********************************************************

       


      Below you can see an example of what I need:

       

      NetClassNetNamePinCountAll_Ref.Pin (sorted)
      CHANNELNET_A3CNT1_1.2,JA1.1,JA2.1,
      CHANNELNET_B5C1_1.2,C2_1.2,DUT.54,DUT.250,DUT.328,
      CHANNELNET_C3CNT2_1.2,JA1.3,JA2.3,
      CHANNELNET_D3C4_1.2,CNT2_1.1,DUT.432,

       


      Any idea, suggestion are appreciated.
      Thanks
      Best regards
      Cris

        • 1. Re: Netlist report (alphanumerical sort) with vbs script
          matheisl.florian

          Hello chris,

           

          perhaps try the sort command for the pin collectin (not tested on my own)

           

          '***********************************************************

          ' Get a collection of nets.
          Dim netColl   ' Collection of all nets
          Dim netObj   ' Net object for iteration
          Dim countNet
          Set netColl = pcbDocObj.Nets
          Dim pin

          ' Sort the component collection
             Call netColl.Sort()
            
          countNet = 0


          ' Iterate through all nets
          For Each netObj In netColl
          ' Report information on each net.
          txtStreamObj.Write(netObj.NetClass)
          txtStreamObj.Write(vbTab & netObj.Name)
          countNet = countNet + 1
          txtStreamObj.Write(vbTab & netObj.Pins.Count & vbTab)
             For Each pin In netObj.Pins.Sort()
              txtStreamObj.Write(pin.component.refdes & "." & pin.name & ",")
             Next
          txtStreamObj.WriteLine()
          Next

          '***********************************************************

           

          Best wishes,

           

          Florian

          • 2. Re: Netlist report (alphanumerical sort) with vbs script
            cristiano.murtas

            Hi Florian,

            thanks for your answer, I've already tried this method but doesn't work.... this is the error msg: "Object not a collection".

            Thks

            Chris

            • 3. Re: Netlist report (alphanumerical sort) with vbs script
              matheisl.florian

              Hi Chris,

               

               

              '***********************************************************

              ' Get a collection of nets.
              Dim netColl   ' Collection of all nets
              Dim netObj   ' Net object for iteration

              Dim PinColl ' Collection of Pins
              Dim countNet
              Set netColl = pcbDocObj.Nets
              Dim pin

              ' Sort the component collection
                 Call netColl.Sort()
                
              countNet = 0


              ' Iterate through all nets
              For Each netObj In netColl
              ' Report information on each net.
              txtStreamObj.Write(netObj.NetClass)
              txtStreamObj.Write(vbTab & netObj.Name)
              countNet = countNet + 1
              txtStreamObj.Write(vbTab & netObj.Pins.Count & vbTab)


                 For Each pin In netObj.Pins

                   PinColl.Add("pin.component.refdes & "." & pin.name")
                  Next

               

              ' Write or search a Collection Sorter, for the collection of pins

              ' e.g. CollectionSorter

              PinColl = CollectionSorter(PinColl)

              For Each pin In PinColl

                   txtStreamObj.Write(pin)

              Next

               

              txtStreamObj.WriteLine()
              Next

              '***********************************************************

               

              Best wishes,

               

              Florian

              • 4. Re: Netlist report (alphanumerical sort) with vbs script
                cristiano.murtas

                Hi Florian,

                I tried with your code but I have this err. msg "Expected Identifier" on this line ---> PinColl.Add("pin.component.refdes & "." & pin.name").

                Can you check?

                Thanks again for your support

                Bye

                Chris

                • 5. Re: Netlist report (alphanumerical sort) with vbs script
                  matheisl.florian

                  Hello Chris,

                   

                  stupid copy&paste

                   

                  ' Replace the first PinColl line with that:

                  PinColl As New Collection

                   

                  PinColl.Add(pin.component.refdes & "." & pin.name)

                   

                   

                  Should work?

                   

                  Best wishes,

                   

                  florian

                  • 6. Re: Netlist report (alphanumerical sort) with vbs script
                    cristiano.murtas

                    Hi Florian,

                    It doesn't work:

                    -  the first line PinColl As New Collection without Dim I have syntax error, with Dim I've this error msg: Expected end of statement

                    - on this line PinColl.Add(pin.component..... I've this error msg: Object required

                    Thks

                    Bye

                    Chris

                    • 7. Re: Netlist report (alphanumerical sort) with vbs script
                      matheisl.florian

                      Hi,

                       

                      Add this to the first lines:

                       

                      Class Collection
                        Private mArray

                        Private Sub Class_Initialize()
                          mArray = Empty
                        End Sub

                        ' Appends the specified element to the end of this list.
                        Public Sub Add(element)
                          If IsEmpty(mArray) Then
                            ReDim mArray(0)
                            mArray(0) = element
                          Else
                            If mArray(UBound(mArray)) <> Empty Then
                              ReDim Preserve mArray(UBound(mArray)+1)       
                            End If
                            mArray(UBound(mArray)) = element
                          End If
                        End Sub
                       
                        Public Sub Sort()
                      arrSortieren = mArray
                      for i = 0 to ubound(arrSortieren)
                         ' The sorting algorithm

                         next
                         mArray = arrSortieren
                      End Sub

                        '  Removes the element at the specified position in this list.
                        Public Sub Remove(index)
                          ReDim newArray(0)
                          For Each atom In mArray
                            If atom <> mArray(index) Then
                              If newArray(UBound(newArray)) <> Empty Then
                                ReDim Preserve newArray(UBound(newArray)+1)
                              End If
                              newArray(UBound(newArray)) = atom
                            End If
                          Next
                          mArray = newArray
                        End Sub

                        ' Returns the number of elements in this list.
                        Public Function Size
                          Size = UBound(mArray)+1
                        End Function

                        ' Returns the element at the specified position in this list.
                        Public Function GetItem(index)
                          GetItem = mArray(index)
                        End Function

                        ' Removes all of the elements from this list.
                        Public Sub Clear
                          mArray = Empty
                        End Sub

                        ' Returns true if this list contains elements.
                        Public Function HasElements
                          HasElements = Not IsEmpty(mArray)
                        End Function

                        Public Function GetIterator
                          Set iterator = New ArrayIterator
                          iterator.SetArray = mArray
                          GetIterator = iterator
                        End Function

                        Public Function GetArray
                          GetArray = mArray
                        End Function

                      End Class

                      Class ArrayIterator
                        Private mArray
                        Private mCursor

                        Private Sub Class_Initialize()
                          mCursor = 0
                        End Sub

                        Public Property Let SetArray(array)
                          mArray = array   
                        End Property

                        Public Function HasNext
                          HasNext = (mCursor < UBound(mArray)+1)
                        End Function

                        Public Function GetNext
                          GetNext = mArray(mCursor)
                          mCursor = mCursor + 1
                        End Function
                      End Class

                       

                      Best wishes,

                       

                      Florian

                      1 of 1 people found this helpful
                      • 8. Re: Netlist report (alphanumerical sort) with vbs script
                        cristiano.murtas

                        Hi Florian,

                        thank you very much for your code but I'm sorry,I don't unserstand how to use it with my previous code.

                        I've tried to add your code in the first line (as you wrote in the mail) but I' ve the same msg error.

                        Could you please show me (in details) how to use your code with my previous code?

                        Thanks again

                        Bye,

                        Chris

                        • 9. Re: Netlist report (alphanumerical sort) with vbs script
                          cristiano.murtas

                          Hi Florian,

                          Thank you very much for your support.

                          After several trials I've found another way and I've changed the code (changes are in red): now it's working.

                           

                           

                          '******

                          ' Get a collection of nets.

                          Dim netColl   ' Collection of all nets

                          Dim netObj   ' Net object for iteration

                          Dim pin

                          Dim pinColl

                           

                          Dim countNet

                          Set netColl = pcbDocObj.Nets

                          Set pinColl = pcbDocObj.Pins

                           

                           

                          ' Sort the component collection

                          Call netColl.Sort()

                          Call pinColl.Sort()

                           

                           

                          countNet = 0

                           

                          ' Iterate through all nets

                          For Each netObj In netColl

                               ' Report information on each net.

                                    txtStreamObj.Write(netObj.NetClass)

                                    txtStreamObj.Write(vbTab & netObj.Name)

                                    countNet = countNet + 1

                                    txtStreamObj.Write(vbTab & netObj.Pins.Count & vbTab)

                           

                           

                                         For Each pin In pinColl

                                              if netObj.Name = pin.Net then

                                                   txtStreamObj.Write(pin.component.refdes & "." & pin.name & ",")

                                              end if

                                         Next

                           

                          txtStreamObj.WriteLine()

                          Next

                          '******

                           

                          Bye

                          Chris

                          • 10. Re: Netlist report (alphanumerical sort) with vbs script
                            matheisl.florian

                            Hi Chris,

                             

                            thats the best solution

                             

                            Best wishes,

                             

                            Florian