Load BOMs by Script
Adding a BOM item takes a few clicks per part. For one machine that is fine. For thirty machines it is a job for a script.
system.kanoa.inventory.addAssetBomItem adds one BOM line to one asset. It returns the new assetBomId and a message that is None on success. A BOM line is either a partId or a modelId, never both.
The script rebuilds the Machine 1 BOM from Build an Asset BOM. It does these steps:
- Sets
assetPathtoCoreForge\Philadelphia\Machining\Machine 1and lists the BOM lines as tuples of part number, quantity, unit code, position code and position name. - Looks up the asset id and the SYSTEM user id.
- For each line, looks up the part id with
getPartsand the unit id withgetUnitOfMeasures, then callsaddAssetBomItem. - Prints each part number with its
assetBomIdand message. - Reads the BOM back with
getAssetBomand prints each position, part number and quantity.
- In Configuration → Ops → Assets, select
Machine 1, open its Parts tab, and delete the three BOM rows you added by hand. This lets you see the script rebuild them. - In the Ignition Designer, open the Script Console and paste in
addMachine1Bom.py. - Run the script.
- Check the output. Each line shows a part number, a new
assetBomIdandNone. Then the BOM prints, in the orderT1,S1,C1or similar. - Back on the Parts tab, refresh. The same three rows are there.
addAssetBomItem adds a new line each time, unless bomInfo includes an assetBomId. Passing an existing assetBomId updates that line instead. Before you re-run a load, either clear the old lines or look up the existing ones with getAssetBom and pass their ids.
Many machines at once
To load the same parts onto many machines, wrap the loop in a second loop over asset paths:
machinePaths = [
'CoreForge\\Philadelphia\\Machining\\Machine 1',
'CoreForge\\Philadelphia\\Machining\\Machine 2',
]
for assetPath in machinePaths:
assetId = getId('assetId', system.kanoa.asset.getAssets({'assetPath': assetPath}))
for partNumber, qty, uomCode, positionCode, positionName in bomItems:
# build bomInfo and call addAssetBomItem as in the script
pass
Check which assets getAssets returns for each path before you load.
Keep the BOM lines in a CSV or an ERP export instead of in the script. Read the rows into the same tuple structure and the rest of the script does not change.
Model BOMs
If many machines share a parts list, put it on an equipment model once. system.kanoa.inventory.addModelBomItem works like addAssetBomItem, with modelId in place of assetId. A model BOM line holds either a partId or a childModelId, a sub-assembly modeled as its own model. Read a model BOM with getModelBom(modelId).
system.kanoa.inventory.addModel creates a model, and getModels finds one by modelNumber.
You built a script that loads a bill of materials onto an asset, reads it back, and grows into a bulk load for many machines or a model BOM.