Contact Us
Contact our corporate or local offices directly.
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
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.
The Bill Of Materials object is represented by an instance of IBomManager/IActiveBomManager:
IBomManagerFactory.GetManagerForDocument(srcDoc)
IBomManagerFactory.GetManagerForDocumentPcb(srcDoc, pcbDoc)
IBomManagerFactory.GetManagerForProject(project)
IBomManagerFactory.GetManagerForProjectPcb(project, pcbDoc)
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.
IBomComponentList components = bomManager.GetSchema().GetComponents()
IBomComponentList
is a list of IBomComponent
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()
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(..);
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 ‘=’
IBomParameterDefinitionList columns = bomManager.GetSchema().GetParameterDefinitions()
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()
The point where you can configure the BOM is:
IBomManagerOptions o = bomManager.GetOptions()
...or for ActiveBOM:
IActiveBomManagerOptions ao = activeBomManager.GetOptions();
o.SetAutoGroup(false); o.SetGroupOrder(""); ao?.SetMultiVariant(false);
o.SetAutoGroup(true); o.SetGroupOrder(""); ao?.SetMultiVariant(true);
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;
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.
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).
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
.
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());
Contact our corporate or local offices directly.