Skip to main content

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.

Machine 1 BOM script

The script rebuilds the Machine 1 BOM from Build an Asset BOM. It does these steps:

  1. Sets assetPath to CoreForge\Philadelphia\Machining\Machine 1 and lists the BOM lines as tuples of part number, quantity, unit code, position code and position name.
  2. Looks up the asset id and the SYSTEM user id.
  3. For each line, looks up the part id with getParts and the unit id with getUnitOfMeasures, then calls addAssetBomItem.
  4. Prints each part number with its assetBomId and message.
  5. Reads the BOM back with getAssetBom and prints each position, part number and quantity.
Run the BOM script
  1. 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.
  2. In the Ignition Designer, open the Script Console and paste in addMachine1Bom.py.
  3. Run the script.
  4. Check the output. Each line shows a part number, a new assetBomId and None. Then the BOM prints, in the order T1, S1, C1 or similar.
  5. Back on the Parts tab, refresh. The same three rows are there.
Reference Materials: addAssetBomItem

Adds a new Bill-of-Materials line item to a specific installed asset instance, or updates an existing one when assetBomId is supplied inside bomInfo. An asset BOM entry lets a particular unit's actual composition diverge from (or extend) its model-level BOM. for example recording a non-standard part actually installed at a position, or a position that only exists on this asset. As with model BOM items, partId and modelId are mutually exclusive, so each entry represents either a part or a referenced model at that position, not both.


Parameters​

bomInfo Dictionary

- assetBomIdIntegerNot required, pass to update
- assetIdInteger
- enabledBooleanNot required
- modelIdIntegerNot required, mutually exclusive with partId
- notesStringNot required
- parentBomIdIntegerNot required
- partIdIntegerNot required, mutually exclusive with modelId
- positionCodeStringNot required
- positionNameStringNot required
- quantityFloat
- uomIdInteger

userId Integer:Id of the user executing the function


Returns​

assetBomId Integer
message String None if success


Example​

# Add a part to an asset's BOM
bomInfo = {
'assetId': 7734,
'partId': 8891,
'quantity': 1.0,
'uomId': 1,
'positionCode': 'P1-A',
'positionName': 'Drive Shaft Bearing',
'enabled': True,
'notes': 'Replaced with heavy-duty bearing during last overhaul'
}
userId = system.kanoa.security.getIDPUserId({'userName': 'SYSTEM'})
assetBomId, message = system.kanoa.inventory.addAssetBomItem(bomInfo, userId)
print assetBomId, message
Running it twice adds duplicates

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.

Load from a file

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.

Reference Materials: addModelBomItem

Adds a new Bill-of-Materials (BOM) line item to an equipment model, or updates an existing one when modelBomId is supplied inside bomInfo. A model BOM entry describes a single component position within the model's catalog-level structure, either a raw part (partId) or a nested child model (childModelId), along with the quantity and unit of measure required at that position. Because partId and childModelId are mutually exclusive, each BOM item represents either a purchased/stocked part or a sub-assembly modeled as its own equipment model, never both.


Parameters​

bomInfo Dictionary

- childModelIdIntegerNot required, mutually exclusive with partId
- enabledBooleanNot required
- modelBomIdIntegerNot required, pass to update
- modelIdInteger
- notesStringNot required
- parentBomIdIntegerNot required
- partIdIntegerNot required, mutually exclusive with childModelId
- positionCodeStringNot required
- positionNameStringNot required
- quantityFloat
- uomIdInteger

userId Integer:Id of the user executing the function


Returns​

modelBomId Integer
message String None if success


Example​

bomInfo = {
'modelId': 1042,
'partId': 8891,
'quantity': 2.0,
'uomId': 1,
'positionCode': 'P1-A',
'positionName': 'Drive Shaft Bearing',
'enabled': True,
'notes': 'Standard replacement bearing for this position'
}
userId = system.kanoa.security.getIDPUserId({'userName': 'SYSTEM'})
modelBomId, message = system.kanoa.inventory.addModelBomItem(bomInfo, userId)
print modelBomId, message
Reference Materials: getAssetBom

Returns the fully flattened Bill-of-Materials for a specific installed asset instance, given its assetId inside paramsDict. Like getModelBom, this resolves any nested BOM structure into a single flat dataset. The resulting BOM reflects the asset's own overrides/extensions layered on top of (or in place of) its model-level BOM. This is a getter function and returns the dataset directly, not a (result, message) tuple.


Parameters​

paramsDict Dictionary

- assetIdInteger

Returns​

data pyDataset


Example​

# Full flattened BOM for an asset
assetId = 3139
data = system.kanoa.inventory.getAssetBom({'assetId': assetId})
data = system.kanoa.utilities.convertDatasetToJSON(data)

for i, row in enumerate(data):
print 'Row %i'%i
for k,v in row.items():
print k,v

break #Just limiting to returning the columns from the first record for display purposes
>>>
Row 0
notes None
modelId None
partId 26
assetTypeName cell
positionCode None
positionName None
path Filler
assetId 3139
assetPath Kanoa Bottling Co\Tempe\Packaging Hall\Bottling Line 1\Filler
sourceModelNumber None
sourceModelDescription None
sourceManufacturerName None
partCategoryPath Bearings
uomCode EA
quantity 5.0
partPath Bearings\AAA111
uomId 1
sourceModelBomId None
depth 1
partDescription sklgmlkrgm
assetName Filler
uomName Each
partNumber AAA111
assetBomId 14
>>>

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.