1 Reply Latest reply on Apr 12, 2017 7:18 AM by daniel.liggett@halliburton.com

    Add part to schematic - from Excel?




      Anyone know how to select a parttype name in Excel - and then add the part to a PADS Logic schematic?


      I am considering this process:

      1) Selecting a parttype name in an Excel spreadsheet.

      2) Click on a button (macro) in Excel will add the selected part to PADS Logic.
          Just as when clicking 'Add part' directly in Logic.

         Take a look at the attached image.




        • 1. Re: Add part to schematic - from Excel?

          I found a way to do it using Basic Scripts if you don't mind launching the Excel file from Basic Scripts and then clicking on the Part Name to launch the placement.  The action of placing the part is controlled by a custom macro for each part to be placed.  The Part Name is assumed to be in column 2 of the spreadsheet.  Spreadsheet was generated from File > Library > Parts button > List to File > select attributes to export > Run > save as CSV.


          Perhaps the code below will point you in the right direction.


          Dan Liggett




          ' Place_Part_from_Library_Index.bas

          ' 2017_03-17 (Dan Liggett)

          ' Watches the XLS file for a click (change of selection) in column 2 (Part Name).

          ' The Part Name is grabbed and fed to the Add Part From Library dialog in PADS Logic, from which it finds, selects and Adds to the current sheet in Logic.


          Dim WithEvents xl As Excel.Application
          Dim procSel As Boolean
          Dim Title As String
          Dim objFSO As Object
          Dim objFile As Object

          Sub Main
          If Application.Name <> "PADS Logic" Then
               Dim App As Object
               Set App = CreateObject("Excel.Application")
               App.Visible = True
               Exit Sub
          End If

          Title = "Place Part from Library Index"

          On Error Resume Next
          Set xl =  GetObject(,"Excel.Application")
          On Error GoTo 0
          If xl Is Nothing Then
            Set xl =  New Excel.Application
            Set xlBook = xl.Workbooks.Open("<YOUR_PATH_AND_FILENAME_HERE.XLS>", 0, True) 'read only
            Set xlBook = xl.Workbooks.Open("<YOUR_PATH_AND_FILENAME_HERE.XLS>", 0, True) 'read only
          End If
              xl.Visible= True
              procSel = True
              If MsgBox ("WHILE THIS MESSAGE IS ON THE SCREEN:" & vbCr & _
                               vbCr & _
                               "Selecting a Part Name in Excel will attempt to place that part in PADS Logic." & vbCr & _
                               vbCr & _
                               "Press Yes to close Index with " & Title & vbCr & _
                               "Press No to only close " & Title, _
                                4, Title) = vbYes Then
            'Close Index
          End If
          Set xlBook = Nothing
          Set xl = Nothing                   
          End Sub
          Private Sub xl_SheetSelectionChange(Sh As Object, Target As Range)
          If Not procSel Then Exit Sub 'avoid recursion
              procSel = False
          ActiveDocument.SelectObjects ( ,, False)
          Set aRange = xl.Intersect(xl.ActiveSheet.UsedRange, Target.Cells)
          If Not aRange Is Nothing Then
            For Each cell In aRange
             objName = Str(cell)
             If objName <> "" Then
              If Target.Column = 2 Then ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''ASSUMES PART NAME IN COLUMN 2 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
               'MsgBox (objName, , "Placing . . .")   
               macFile = DefaultFilePath & "\" & "@PrtPlc@.mcr"
                  If Not Dir$(macFile) = "" Then Kill macFile
                  Set objFSO = CreateObject("Scripting.FileSystemObject")
                  Set objFile = objFSO.CreateTextFile(macFile, True)
               'Write macro and then run it
                  objFile.WriteLine("Application.ExecuteCommand(" & Chr(34) & "Add Part" & Chr(34) & ")") 'Chr(34) is double quote
                  objFile.WriteLine("DlgAddPart.Library = " & Chr(34) & "(All Libraries)" & Chr(34) )
                  objFile.WriteLine("DlgAddPart.Filter = " & Chr(34) & objName & Chr(34) )
                  objFile.WriteLine("DlgAddPart.Apply.Click()" )
                  objFile.WriteLine("If Len(DlgAddPart.Items.Text) Then" )
                  objFile.WriteLine("  DlgAddPart.Add.Click()" )
                  objFile.WriteLine("Else" )
                  objFile.WriteLine("  MsgBox  " & Chr(34) & "Selected Part NOT found in listed Libraries:" & Chr(34) & " & Chr(10) & Chr(10) & " & Chr(34) & objName & Chr(34) & ",," & Chr(34) & Title & Chr(34) )   
                  objFile.WriteLine("End If" )
                  objFile.WriteLine("DlgAddPart.Close.Click()" )
               RunMacro(macFile, "")
              End If
             End If
          End If 
              procSel = True
          End Sub