Electronic – BOM style output for library in Altium

altium

I have done a bit of searching and haven't found a solution so I am going to ask here.

Does anyone know how to get Altium to print out a spreadsheet of all components in a schematic library including their user defined parameters?

I know I can place all the components in a library onto a schematic and create a BOM but I would think that there would be an easier and cleaner solution. My goal here is to create a spreadsheet containing all the parts of a library so I can sort them by their part number parameter.

Best Answer

Script below.

You will need to open the script in Altium, then open your SchLib file, then Use the DXP -> Run Script menu option (the SchLib file MUST be open when you run it). Double click the function name, not the Filename or it will now run.

The script will generate a file named d:\symbolreport.txt (you can change the file name at the very bottom of the script).

Example output:

KINGBRIGHT_KP-1608SGC;Notes;*
KINGBRIGHT_KP-1608SGC;Alternative;*
KINGBRIGHT_KP-1608SGC;CheckedByOn;GoPe/2014-11-25
KINGBRIGHT_KP-1608SGC;CreatedByOn;LiTh/2014-11-05
KINGBRIGHT_KP-1608SGC;Value;GrĂ¼n
KINGBRIGHT_KP-1608SGC;Comment;DIKP-1608SGC-S10
VISHAY_TLMS1000-GS08;Notes;*
VISHAY_TLMS1000-GS08;Alternative;*
VISHAY_TLMS1000-GS08;CheckedByOn;LiTh/2014-11-24
VISHAY_TLMS1000-GS08;CreatedByOn;GoPe/2014-11-20
VISHAY_TLMS1000-GS08;Value;Rot
VISHAY_TLMS1000-GS08;Comment;DITLMS1000-S12

The output is named a CSV file with the ";" as separator character if you want to import it to Excel.

Procedure PrintDataForSchLibItems();
Var
  DocType       : WideString;
  SchComponent  : ISch_Component;
  SchLib        : ISch_Lib;
  SchDoc        : ISCh_Doc;
  SchIterator   : ISch_Iterator;

  AnObject      : ISch_GraphicalObject;
  LibName       : TDynamicString;
  Iterator      : ISch_Iterator;
  PartCount     : Integer;
  ReportInfo    : TStringList;

  Document : IServerDocument;

Begin
    If SchServer = Nil Then Exit;

    // Obtain the Client interface so can get the Kind property.
    DocType := UpperCase(Client.CurrentView.OwnerDocument.Kind);
    If DocType <> 'SCHLIB' Then
    Begin
        ShowWarning('This is not a Library document!');
        Exit;
    End;

    // Obtain the schematic library interface
    SchLib := SchServer.GetCurrentSchDocument;
    If SchLib = Nil Then Exit;

    // Create a TStringList object to store data
    ReportInfo := TStringList.Create;
    ReportInfo.Clear;

    // Obtain schematic library filename
    LibName := SchLib.DocumentName;
    LibName := ExtractFileName(LibName);

    // Create an iterator to look for symbols within the library
    SchIterator := SchLib.SchLibIterator_Create;
    SchIterator.AddFilter_ObjectSet(MkSet(eSchComponent));
    PartCount := 0;

    Try
        SchComponent := SchIterator.FirstSchObject;
        While SchComponent <> Nil Do
        Begin
            // Look for child objects associated with this symbol.
            Iterator := SchComponent.SchIterator_Create;
            Iterator.AddFilter_ObjectSet(MkSet(eParameter));
            Try
                AnObject := Iterator.FirstSchObject;
                While AnObject <> Nil Do
                Begin
                   // Limit to a specific parameter only
                    If AnObject.Name = 'CreatedByOn' Then
                    Begin
                       ReportInfo.Add(SchComponent.LibReference + ';' +  AnObject.Name + ';' + AnObject.Text);
                    End;

                    // look for the next item of a symbol
                    AnObject := Iterator.NextSchObject;
                End;

                PartCount := 0;
            Finally
                SchComponent.SchIterator_Destroy(Iterator);
            End;

            SchComponent := SchIterator.NextSchObject;
        End;
    Finally
        SchLib.SchIterator_Destroy(SchIterator);
    End;

    ReportInfo.SaveToFile('D:\SymbolReport.txt');

    ReportInfo.Free;
End;