BOM Engine Interfaces
The Altium SDK Bill Of Materials (BOM) Interfaces allow the creation and management of project BOM data and associated parameters.
The BOM 2.0 Engine is available in the Altium SDK 4.0. Its main class is the BOM Manager (IBomManager
) , called for a specific document data source type by the IBomManagerFactory ( EDP.Utils.GetBomManagerFactory()
).
A BOM 2.0 Engine example project is included with the Altium Developer installation. In the default Altium Developer installation, the C# (CSharp) BOMPanel example location is: C:\ProgramData\Altium\
[host Altium software]\Extensions\Altium Developer\SDK4.0\CSharp\Examples\BOMPanel
BOM usage via the Altium SDK
Start
The very entry point for using the BOM (Bill Of Materials) via the Altium SDK is IBomManagerFactory
.
To get an instance of the BOM Factory, use EDP.Utils.GetBomManagerFactory()
method.
Get Bill Of Materials
The Bill Of Materials object is represented by an instance of IBomManager/IActiveBomManager:
- for any document (SCH / PCB / BOMDOC) as a source of components:
IBomManagerFactory.GetManagerForDocument(srcDoc)
- for SCH / BOMDOC as a source of components with a PCB document as an additional source of PCB parameters:
IBomManagerFactory.GetManagerForDocumentPcb(srcDoc, pcbDoc)
- for a whole project:
IBomManagerFactory.GetManagerForProject(project)
- for a whole project with a PCB document as an additional source of PCB parameters:
IBomManagerFactory.GetManagerForProjectPcb(project, pcbDoc)
IBomManager / IActiveBomManager
Depending on the options above, you will get an instance of EDP.IBomManager
or EDP.IActiveBomManager
.
To check which one you have, cast the instance to IActiveBomManager
:
var activeBomManager = bomManager as IActiveBomManager;
...and check the result for a null.
Retrive the BOM content
Get rows
IBomComponentList components = bomManager.GetSchema().GetComponents()
IBomComponentList
is a list of IBomComponent
Get 'original' components of row
First, check if a row (IComponent
) is actually a group – that is, it contains more than one component: row.IsGroup()
Then cast it to a group and get its components: row.AsGroup().GetComponents()
Get row columns (parameter) values
Getting column parameter values for a given IBomComponent
row.
Get row parameters dictionary:
IBomParameterDictionary params = row.GetParameters()
...and use the dictionary’s methods like:
bool TryGetParameter(string argName, out IBomParameter argParameter)
...or:
GetStrValue(..), GetIntValue(..);
Get column aliases
For an ActiveBOM document, column aliases (custom names) can be specifed.
If you have IActiveBomManager
(not just the IBomManager
) you are able to access:
string aliases = activeBomManager.GetOptions().GetColumnsAliases()
This string should be parsed – split with a ‘|’ char and then received pairs with ‘=’
Get list of all columns (parameters)
IBomParameterDefinitionList columns = bomManager.GetSchema().GetParameterDefinitions()
Get list of custom columns
For an ActiveBOM document, Custom Columns can be created. They are presented in IBomParameterDefinitionList
along with other (auto-generated) columns. If a dedicated list is needed for some reason, it can be obtained with:
activeBomManager.GetOptions().GetCustomColumns()
Set up the required BOM
The point where you can configure the BOM is:
IBomManagerOptions o = bomManager.GetOptions()
...or for ActiveBOM:
IActiveBomManagerOptions ao = activeBomManager.GetOptions();
Flat view mode
o.SetAutoGroup(false); o.SetGroupOrder(""); ao?.SetMultiVariant(false);
Consolidated
o.SetAutoGroup(true); o.SetGroupOrder(""); ao?.SetMultiVariant(true);
Sorting
Assume there is a:
IList<Tuple<string, ListSortDirection>> sortOrderParams;
Where the first item is Name of Parameter, and the second is Sort Direction.
...then to apply the following setting to BOM usage:
o.SortOrder.Set(sortOrderParams); o.AutoSort = sortOrderParams.Count == 0;
Avoid affecting BOMs in the rest of Altium Designer
It's advisable to save the BOM Manager Options before they are modified:
IBomManagerOptions options var savedState = options.GetState();
When all the required data have been collected, restore the options:
options.RestoreState(savedState);
Using a try-finally clause is recommended.
Modify BOM content
Set line number for row
Setting line numbers is possible for ActiveBOM only:
IActiveBomManager activeBomManager = ... // create BomManager for .BomDoc IBomComponent component = ... // find component in BOM schema var catalogId = component.GetParameters().GetStrValue("%CATALOGID%"); var catalog = activeBomManager.GetCatalog(); var catalogItem = catalog.FindItem(catalogId); catalogItem.SetLineNumber("...");
To update BOM schema after changing line numbers in catalog items, call bomManager.UpdateSchema
(note - this will recreate the whole BOM schema).
Add custom row
To add a custom row in ActiveBOM:
IActiveBomManager activeBomManager = ... // create BomManager for .BomDoc var catalog = activeBomManager.GetCatalog(); var catalogItem = catalog.AddCustomRow();
To set parameters for a created custom row use catalogItem
methods SetComment
, SetDescription
, SetLineNumber
(or GetParameters().SetValue
methods to set any parameter).
To update BOM schema after a creating custom row call bomManager.UpdateSchema
.
Save ActiveBOM document
After any modification you may wish to save the ActiveBOM document (*.BomDoc
), which can be done as follows:
IDocument document = ... // get ActiveBOM document var serverDocument = document.DM_ServerDocument(); serverDocument.DoFileSave(document.DM_DocumentKind());