1 Reply Latest reply on Aug 11, 2017 9:06 AM by Patrick.Cashman

    VB Script to Export Parts list information to Excel.




      Does anyone know of a script that can export a Partslist (similar to xDxDesigner) from the xPCB Layout?

      I need Columns for Item Number, Refdes (Grouped), Value, Description etc.




      Charl Peters

        • 1. Re: VB Script to Export Parts list information to Excel.

          I put this together.  It may need a few tweaks to get exactly what you want, but it's mostly what you are looking for:


          (note: assumes you already have a reference to doc (PCB document).  Also, this is done in vb.net; for vbscript you'll have to make some adjustments. Finally, the save_file routine will be up to you)


              Sub export_PL_bom()

                  Dim comps As MGCPCB.Components

                  Dim comp As MGCPCB.Component

                  Dim pl As New Dictionary(Of String, String())

                  Dim pn, value, desc As String

                  Dim str As New StringBuilder

                  Dim props As MGCPCB.Properties

                  Dim prop As MGCPCB.Property

                  Dim ary() As String

                  Dim row As String

                  Dim n, i As Integer


                  comps = doc.Components(0)

                  For Each comp In comps

                      If Not comp.RefDes = "" Then

                          pn = comp.PartNumber

                          props = comp.Properties

                          For Each prop In props

                              value = ""

                              If prop.Name = "Value" Then

                                  value = prop.Value

                              End If

                              If value = "" Then value = "value"



                              desc = ""

                              If prop.Name = "Description" Then

                                  desc = prop.Value

                              End If

                              If desc = "" Then desc = "description"




                          If Not pl.ContainsKey(pn) Then

                              ReDim ary(3)

                              ary(0) = 1

                              ary(1) = value

                              ary(2) = desc

                              ary(3) = comp.RefDes

                              pl.Add(pn, ary)


                              ReDim ary(3)

                              ary = pl(pn)

                              ary(0) = ary(0) + 1

                              ary(3) = ary(3) & ", " & comp.RefDes

                              pl(pn) = ary

                          End If

                      End If




                  Dim kvp As KeyValuePair(Of String, String())

                  str.Length = 0

                  str.AppendLine("ITEM" & vbTab & "PART NO" & vbTab & "QTY" & vbTab & "REFS" & vbTab & "VALUE" & vbTab & "DESCRIPTION")

                  n = 1

                  For Each kvp In pl

                      row = n & vbTab & kvp.Key

                      ary = kvp.Value

                      For i = 0 To UBound(ary)

                          row = row & vbTab & ary(i)



                      n = n + 1



                  save_file(str.ToString, "Save the BOM file:", "")

              End Sub