DelphiScript for component parameters - Page 1
Forum section: electronics / general

author: DanBAltium
author_rank: Newbie
timestamp: March 15, 2024, 01:32:46 pm
content: 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 syntaxNot sure if there are spoilers I could have used, but here's what I have currently:_______________________________________________________________________________________Function PopulateParam(sParameter, sParamName, sParamText, sValue : String) : String;BeginIf sParamname = sParameterThen Result := sParamTextElse Result := sValue;End;Procedure ComponentParameterCount;VarBoard : 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;BeginComponentNumber := 0;ParameterNumber := 0;// Retrieve the current boardBoard := PCBServer.GetCurrentPCBBoard;If Board = Nil Then Exit;// Retrieve the iteratorIterator := Board.BoardIterator_Create;Iterator.AddFilter_ObjectSet(MkSet(eComponentObject));Iterator.AddFilter_LayerSet(AllLayers);Iterator.AddFilter_Method(eProcessAll);// Search and count componentsTryComponent := Iterator.FirstPCBObject;While (Component <> Nil) DoBeginTryInc(ComponentNumber);p_Iterator := Component.GroupIterator_Create;//p_Iterator.AddFilter_ObjectSet(mkSet(eParameter));Parameter := p_Iterator.FirstPCBObject;sSupplier := '';sIsFitted := '';SObsolete := '';While (Parameter <> Nil) DoBeginInc(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;FinallyComponent.GroupIterator_Destroy(p_Iterator);End;Component := Iterator.NextPCBObject;End;FinallyBoard.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!

author: ajb
author_rank: Super Contributor
timestamp: March 15, 2024, 03:53:16 pm
content: 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

author: free_electron
author_rank: Super Contributor
timestamp: April 10, 2024, 04:16:32 pm
content: 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.