7 Replies Latest reply on Nov 3, 2011 7:18 PM by linlin893

    Sharing my scripts for PADS Logic/Layout 9.2

    rtennill

      First let me start off by saying that I have created all these scripts using the automation documentation available with both Logic and Layout along with some extra help from various forums and web discussions. As such they have some bugs and limitations which may or may not be documented. It is HIGHLY RECOMMENDED that you test these scripts out on a copy of a design first before fully trusting any and all changes that are made.

       

      I will post each script as a reply to this one so that I can discuss each one and allow room for replies.

        • 1. Re: Sharing my scripts for PADS Logic/Layout 9.2
          rtennill

          Sorry everyone that was interested in this discussion! I have been extremely busy on software development instead of hardware / design so it slipped from my to do list. Here is one script that I found extremely helpful for a current FPGA based design. There are some restrictions but I believe that I have discussed those fairly well in the header comments but post questions as a reply if there are any.

           

          <code>

          'This script automates the naming of routing vias used to breakout from fine pitch BGA packages

          ' The script will automatically add the prefix "Z_" to each via and use the existing net name as

          ' the suffix.

           

          'USAGE: to use this script you must first place via "parts" on each net that will use the routing vias

          '             Once all vias are added to the design select all via parts using the project explorer "part types"

          '             With all the components selected run the script and enjoy not having to name them all by hand!

           

          ' NOTES: With a little extra work this script could be used to rename any kind of part with any kind of prefix

          '                but that isn't a task that I have had to tackle just yet.

          Sub Main

           

              On Error GoTo error_handler

              Dim err_count As Integer

              Let err_count = 0

              Let show_Debug = 0

           

              ' Ex2: Get all selected objects of all types

              Set objs = ActiveDocument.GetObjects(,,True)

           

              If show_Debug = 1 Then

                  MsgBox "Selected: " & objs.Count & " selected objects."

                   MsgBox "Obj 1: " & objs.Item(1).Pins(1)

               End If

           

              If objs.count >= 1 Then

                  For n = 1 To objs.Count Step 1

                      If objs.ItemType(n) = plogObjectTypeComponent Then

           

                           'debug code

                           If show_Debug = 1 Then

                              Debug.Print n

                           End If

           

                           Set pin_id = objs.Item(n).Pins(1)

           

                           'debug code

                           If show_Debug = 1 Then

                              Debug.Print pin_id        

                              MsgBox "Obj 2: " & pin_id.Net.Name

                           End If

           

                           Dim net_name As String

                           Let net_name = pin_id.Net.Name

           

                           'debug code

                           If show_Debug = 1 Then

                              Debug.Print net_name

                           End If

           

                           Let objs.Item(n).Name = "Z_" & pin_id.Net.Name

                       End If

           

                   Next n

           

              Else

                  MsgBox "No components are selected. Please select 1 or more parts to rename and try again."

                  Exit Sub

              End If

           

               If err_count <> 0 Then

                   Debug.Print "total errors: " & err_count

                   MsgBox "errors or items not renamed: " & err_count

               Else

                   MsgBox "all parts sucessfully renamed"   

               End If

           

               Exit Sub

           

          error_handler: Debug.Print "Error = ";Err.Description

              Let err_count= err_count +1

              Err.Clear

              Resume Next

           

           

          End Sub

           

          </code>

          • 2. Re: Sharing my scripts for PADS Logic/Layout 9.2
            rtennill

            Another useful script that provides some great improvements over the build in attributes editor.

             

            <code>

             

            'Bulk of this script code is a sample provided with Pads Logic install.

            'Code modified by Ryan Tennill @ Distant Focus Corporation, 18Nov2010

            '

            'Modified this code to improve on the usefulness of being able to see attributes without clicking through

            'multiple windows. The goal is to provide a single interface that allows the user to view and set all

            'attributes of a component as they are selected interactively in a schematic.

            'Original implementation used a dropbox thus only showing a single attribute at a time.

            '

            'This script does not prevent setting attributes for more than one part type at a time!

             

            Dim attribNames$()

            Dim attribVals$()

            Dim parts As objects

            Dim attrsEqual As Boolean

            Dim prevItem As String

            Dim item As Integer

            Dim activeBox As String

            Dim partName As String

             

            Sub Main

             

                'this line is the only way that I have found to handle the cancel button or close window operation

                'Sax Basic doesn't handle this in a particularly reasonable way so I simply jump to a label

                'at the end of the main sub.

                On Error GoTo error_handler

             

                Begin Dialog UserDialog 0,0,560,336,"Less Suckass Attributes Editor",.dialogfunc ' %GRID:10,7,1,1

                    OKButton 360,266,110,21

                    Text 170,28,100,21,"&Part Name:",.Text1

                    Text 30,63,140,14,"&Attribute Name",.Text2

                    Text 200,63,140,14,"&Attribute Value",.Text3

                    TextBox 280,28,260,21,.partName

                    PushButton 230,266,110,21,"&Set",.SetBtn

                    PushButton 50,266,110,21,"&Add",.AddBtn

                    PushButton 50,308,110,21,"&Del",.DelBtn

                    ComboBox 20,84,160,175,attribNames(),.Names

                    ComboBox 190,84,350,175,attribVals(),.Vals

                    CancelButton 280,301,120,21

                End Dialog

             

                Dim dlg As UserDialog

                Dialog dlg

                error_handler:

            End Sub

             

            Function dialogfunc(DlgItem$, Action%, SuppValue%)  As Boolean

                Select Case Action%

                Case 1 ' Dialog box initialization

                    Document_SelectionChange 

                Case 2 ' Value changing or button pressed

                     'Debug.Print "DlgValue=" & DlgValue("Names")

                    If DlgItem$ = "AddBtn" Then

                        AddNewAttribute

                           dialogfunc = True

                    ElseIf DlgItem$ = "DelBtn" Then

                        DelAttribute

                           dialogfunc = True

                    ElseIf DlgItem$ = "SetBtn" Then

                        SetNewValue

                           dialogfunc = True

                    Else

                           dialogfunc = False

                    End If

             

                Case 3 ' TextBox or ComboBox text changed

                        'Debug.Print "action=3" & " suppValue=" & SuppValue & " DlgValue=" & DlgValue("Names")

                Case 4 ' Focus changed

             

                    If DlgItem$ = "Names" Then

                        item = DlgValue("Names")

                        activeBox = "Names"

                        attrsEqual = True 'to enable Set button

                        'Debug.Print "item=" & item & " action=4 " & DlgText("Names") & " DlgValue=" & DlgValue("Names")

                        UpdateButtons

                    ElseIf DlgItem$ = "Vals" Then

                        item = DlgValue("Vals")

                        activeBox = "Vals"

                        attrsEqual = True 'to enable Set button

                        'Debug.Print "item=" & item & " action=4 " & DlgText("Vals") & " DlgValue=" & DlgValue("Vals")

                        UpdateButtons

                     End If

             

                Case 5 ' Idle

                End Select

            End Function

             

             

            Sub RefreshList(Optional CurItemName As String = "")

                prevEnable = DlgEnable (-1)

                DlgEnable -1, parts.Count < 10

                ReDim attribNames(0)

                ReDim attribVals(0)

                CurItem = 0

                'DlgText -1, "Attributes"

                If parts.Count <> 0 Then '= 1 Then

                    Set attrs = parts(1).Attributes

                    ReDim attribNames(parts(1).Attributes.Count)

                    ReDim attribVals(parts(1).Attributes.Count)

             

                    'DlgText -1, "Attributes of part " & parts(1).Name

                    For i=1 To attrs.Count

                        attribNames(i-1) = Attrs(i).Name

                        attribVals(i-1) = Attrs(i).Value

                        If attribNames(i-1) = CurItemName Then  CurItem = i-1

                    Next

             

                End If

                DlgListBoxArray "Names",attribNames$()

                DlgListBoxArray "Vals",attribVals$()

                'DlgValue "partName", CurItem

                   'UpdateValue

                DlgEnable -1, prevEnable

                   UpdateButtons

            End Sub

             

            Public Sub UpdateButtons

             

                nm = DlgText("partName")

                count = parts.Count

                DlgEnable "AddBtn", count <> 0

                DlgEnable "DelBtn", count <> 0 And nm <> ""

                DlgEnable "SetBtn", count <> 0  And nm <> "" And attrsEqual

                DlgEnable "Names", count <> 0

                DlgEnable "Vals", count <> 0

                DlgEnable "partName", count <> 0

            End Sub

             

            ' Set new value for current attribute in each part

            ' RT: new value is accepted in the text box portion of the combobox,

            '     use activeBox$ and item% to determine which element to change.

            Sub SetNewValue

                ReDim aBox$(parts(1).Attributes.Count)

                prevEnable = DlgEnable (-1)

                DlgEnable -1, parts.Count < 10

             

                Dim attrs As Attributes

                UpdateProgress parts.Count, "Setting attribute value for selected parts..."

             

                'determine which box is being set so the correct value is changed (attribute or value)

                'an value -1 for 'item' indicates that no item was selected in the active box before text was entered

                'or a button was pushed.

                '-how to handle when user puts text in a box before selecting anything and then clicks SET?

                '

                If (item = -1) Then

                        MsgBox "Please select an item in a list before trying to set a new value"

                        DlgText activeBox,""

                        Exit Sub

                ElseIf activeBox = "Names" And DlgText("Names")<>"" Then

                    newVal = attribVals(item)

                    nm = DlgText("Names")

                ElseIf activeBox = "Vals" Then

                    newVal = DlgText("Vals")

                    nm = attribNames(item)

                End If

             

                'apply update to all the selected parts

                'RT: should be more careful about mixing part types here also...

                For Each part In parts

                    Set attrs = part.Attributes

                    If attrs(nm) Is Nothing Then    'attribute doesn't exist, add it.

                        attrs.Add(nm, newVal)

                    Else

                        attrs(nm) = newVal

                    End If

                    UpdateProgress 1

                Next

                UpdateProgress 0

                RefreshList

             

                DlgEnable -1, prevEnable

            End Sub

             

            ' Add new attribute in each part

            ' RT: need to also add a place in the attribVals() list that corresponds to the newly added attribute

            '     intend to do this by inserting a space character as placeholder which the user can then modify

            ' RT: need some feedback on what would be the preferred method for adding information?

            '     1) use a new dialog and enter an attribute name/value pair at same time

            '     2) add new attribute with inputbox, then set by typing into textbox portion of combobox

            '     3) user enters text in both the name and value text boxes then clicks add

             

            Sub AddNewAttribute

                ItemName = DlgText("partName")

                If parts.Count > 1 Then

                    caption = "Add Attribute to Selected Parts"

             

            ' RT: only dealing with a single part type right now.

            '    Else

            '        caption = "Add Attribute to Parts " & parts(1).Name

             

                End If

                NewName = InputBox("Enter the name:", caption)

                If NewName <> ""  Then

                    prevEnable = DlgEnable (-1)

                    DlgEnable -1, parts.Count < 10

                    UpdateProgress parts.Count, "Adding attribute to selected parts..."

                    For Each part In parts

                        Set attrs = part.Attributes

                        If attrs(NewName) Is Nothing Then attrs.Add(NewName," ")

                        UpdateProgress 1

                    Next

                    UpdateProgress 0

                    RefreshList NewName

                    DlgFocus "partName"

                    DlgEnable -1, prevEnable

                End If

            End Sub

             

            ' Delete attribute from each part

            Sub DelAttribute

                prevEnable = DlgEnable (-1)

                DlgEnable -1, parts.Count < 10

                ItemName = DlgText("Names")

                UpdateProgress parts.Count, "Deleting attribute from selected parts..."

                For Each part In parts

                    Set attrs = part.Attributes

                    If Not attrs(ItemName) Is Nothing Then

                        attrs.Delete(ItemName)

                    End If

                    UpdateProgress 1

                Next

                UpdateProgress 0

                RefreshList

                DlgEnable -1, prevEnable

            End Sub

             

            Public Sub Document_SelectionChange()

                Set parts = ActiveDocument.GetObjects(plogObjectTypeComponent,"",True)

                If parts.Count <> 0 Then

                    DlgText "partName", parts(1).Attributes("Manufacturer #").Value

                    RefreshList prevItem

                End If

            End Sub

             

            Sub UpdateProgress(Optional count As Long, Optional msg As String = "")

                Static  sCurrent, sPercent, sTotal As Long

                If count > 0 And msg <> "" Then

                    StatusBarText = msg

                    sCurrent = 0

                    sPercent = 0

                    sTotal = count

                ElseIf count > 0 Then

                    sCurrent =     sCurrent + count

                Else

                    ProgressBar = -1

                    StatusBarText = ""

                    Exit Sub

                End If

                NewProg = sCurrent * 100 / sTotal

                If sPercent <> NewProg Then

                    sPercent = NewProg

                    ProgressBar = sPercent

                End If

            End Sub

             

            </code>

            • 3. Re: Sharing my scripts for PADS Logic/Layout 9.2
              artwork.master1

              Hi rtennill , we can't see your allegates, why? Do you have included in your message?

              Bye for now and thanks.

              Livio


              • 4. Re: Sharing my scripts for PADS Logic/Layout 9.2
                rtennill

                Sometimes I need to look at two similar components to see what is different about them. It's tough to do this unless they are clearly named something different but somtimes it's only an attribute that is off. This script presents a useful interface for comparing two parts' attributes. The parts don't have to be similar at all, there is no enforcement that you only compare resistors with resistors so it can also function as a two part attribute inspector if you want to get fancy.

                 

                <code>

                 

                Sub Main

                 

                    'This script provides a side-by-side comparison of item attributes.

                    'each attribute is selectable by clicking in the list or using the keyboard for the first letter

                    'each attribute is listed with the attribute name to allow for parts with a different number of

                    'attributes to be accurately compared.

                    'todo: good way to handle more than 2 items at once i.e. dynamic dialog and lists

                    On Error GoTo error_handler

                 

                    Set objs = ActiveDocument.GetObjects(,,True)

                    If (objs.ItemType(1) = plogObjectTypeComponent) And (objs.ItemType(2) = plogObjectTypeComponent) Then

                        Set obj1attrib = objs.Item(1).Attributes

                        Set obj2attrib = objs.Item(2).Attributes

                 

                        Dim obj1attrib_count As Integer

                        Dim obj2attrib_count As Integer

                 

                        obj1attrib_count = obj1attrib.Count

                        obj2attrib_count = obj2attrib.Count

                 

                        Dim list1$()

                        ReDim list1$(obj1attrib_count)

                        Dim list2$()

                        ReDim list2$(obj2attrib_count)

                 

                        'build first part's attribute list

                        For i = 1 To obj1attrib_count

                            list1$(i) = obj1attrib.Item(i).Name & ":" & obj1attrib.Item(i)

                        Next i

                 

                        'build second parts attribute list

                        For i = 1 To obj2attrib_count

                            list2$(i) = obj2attrib.Item(i).Name & ":" & obj2attrib.Item(i)

                        Next i

                 

                        'display the two assembled lists

                    Begin Dialog UserDialog 740,280 ' %GRID:10,7,1,1

                        ComboBox 20,35,340,182,list1(),.attrib1

                        ComboBox 380,35,340,182,list2(),.attrib2

                        OKButton 270,231,190,35

                        Text 30,14,280,14,objs.Item(1).Name,.Text1

                        Text 390,14,280,14,objs.Item(2).Name,.Text2

                        CancelButton 650,252,80,21

                    End Dialog

                        Dim dlg As UserDialog

                        Dialog dlg

                    End If  

                 

                    error_handler:

                 

                End Sub

                </code>

                • 5. Re: Sharing my scripts for PADS Logic/Layout 9.2
                  rtennill

                  After looking at how long the last post was with the code pasted, I have decided to just upload the scripts in an archive. As always use at your own risk since they were created to work in my particular situation.

                  • 6. Re: Sharing my scripts for PADS Logic/Layout 9.2
                    jduquette

                    I like to ASCII export the parts from the library and then use BeyondCompare view them side by side to see what is different.  Your script is a nice GUI approach.

                    • 7. Re: Sharing my scripts for PADS Logic/Layout 9.2
                      linlin893

                      hello,

                      I'm strange to the script,I want to achieve the file with script.Can you help me ?  Thanks

                      1) Enter the Library Manager.

                      2) Select Parts

                      3) Click "List to File" button

                      4) Make sure at least "Part Name" and "Logic Decal" are in the selected attributes list

                      5) Click "Run"

                      6) Save it as either a .lst or a .csv file

                      7) In the file you can sarch for parttypes using a specific Logic Decal