Author Topic: DelphiScript for component parameters  (Read 405 times)

0 Members and 1 Guest are viewing this topic.

Offline DanBAltiumTopic starter

  • Newbie
  • Posts: 1
  • Country: gb
DelphiScript for component parameters
« on: March 15, 2024, 01:32:46 pm »
Hello All!

I'm currently trying to design a unit in Altium with Delphi, but I'm getting confused with the mass of documentation on scripts in Altium's documentation pages.

Basically, I'm trying to design a custom BOM for the components used by iterating through all components on the board, once a component is found, it could iterate through the component to extract all the child objects such as parameters, for example the part number. There are various other custom parameters such as the supplier, wattage, is fitted etc.

I've tried using both board and group iterators which easily manage to find and iterate through components, but for the life of me I cant seem to retrieve any parameters from the component. I'm not sure if its even possible, but if anyone has any ideas please reply! I'm fairly new to programming in Delphi script, but I believe the only thing that's stopping my program from working is the PCB API syntax

Not sure if there are spoilers I could have used, but here's what I have currently:

_______________________________________________________________________________________

Function PopulateParam(sParameter, sParamName, sParamText, sValue : String) : String;

Begin
     If sParamname = sParameter
     Then Result := sParamText
     Else Result := sValue;

End;


Procedure ComponentParameterCount;
Var
    Board      : IPCB_Board;
    Component  : IPCB_Component;
    Parameter  : IPCB_Parameter;
    Iterator   : IPCB_Iterator;
    p_Iterator : IPCB_Iterator;
    ComponentNumber : Integer;
    ParameterNumber : Integer;

    sSupplier  : String;
    sIsFitted  : String;
    SObsolete  : String;

Begin
    ComponentNumber := 0;
    ParameterNumber := 0;

    // Retrieve the current board
    Board := PCBServer.GetCurrentPCBBoard;
    If Board = Nil Then Exit;

    // Retrieve the iterator
    Iterator := Board.BoardIterator_Create;
    Iterator.AddFilter_ObjectSet(MkSet(eComponentObject));
    Iterator.AddFilter_LayerSet(AllLayers);
    Iterator.AddFilter_Method(eProcessAll);

    // Search and count components
    Try
        Component := Iterator.FirstPCBObject;
        While (Component <> Nil) Do
        Begin
            Try
                Inc(ComponentNumber);
                p_Iterator := Component.GroupIterator_Create;
                //p_Iterator.AddFilter_ObjectSet(mkSet(eParameter));
                Parameter := p_Iterator.FirstPCBObject;

                sSupplier  := '';
                sIsFitted  := '';
                SObsolete  := '';

                While (Parameter <> Nil) Do
                Begin
                    Inc(ParameterNumber);
                    sSupplier  := PopulateParam('Supplier', Parameter.Name, Parameter.Value, sSupplier);
                    //sIsFitted  := PopulateParam('NotFitted', Parameter.Name, Parameter.Text, sIsFitted);
                    //sObsolete  := PopulateParam('Obsolete', Parameter.Name, Parameter.Text, sObsolete);
                    Parameter := p_Iterator.NextPCBObject;
                End;
            Finally
            Component.GroupIterator_Destroy(p_Iterator);
            End;
        Component := Iterator.NextPCBObject;
        End;
    Finally
    Board.BoardIterator_Destroy(Iterator);
    End;

    ShowMessage('Component Count = ' + IntToStr(ComponentNumber));
    ShowMessage('Parameter Count = ' + IntToStr(ParameterNumber));

    ShowMessage('Supplier Parameter = ' + (sSupplier));

End;

_______________________________________________________________________________________

This program returns the component count as expected, the parameter count as 0, and if I change the filter 'eParameter', I start getting errors about the undeclared identifier, 'Text'.

Cheers!
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2608
  • Country: us
Re: DelphiScript for component parameters
« Reply #1 on: March 15, 2024, 03:53:16 pm »
I can't help with the delphi, but if you're just trying to creat a BOM that includes custom parameters that's entirely doable with ourjobs.  The BOM export allows you to select parameters from components, PCB, or database to be included and which parameters are used to group components
 
The following users thanked this post: DanBAltium

Offline free_electron

  • Super Contributor
  • ***
  • Posts: 8517
  • Country: us
    • SiliconValleyGarage
Re: DelphiScript for component parameters
« Reply #2 on: April 10, 2024, 04:16:32 pm »
why are you trying to do that with a script. use the outjob , make an excel template and use the special strings. you can format all data exactly the way you want it.
Professional Electron Wrangler.
Any comments, or points of view expressed, are my own and not endorsed , induced or compensated by my employer(s).
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf