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!