Introduction to Bill of Materials in Teigha Mechanical

Andrii Morozov
July 11, 2017

Tags: mechanical getting started

Teigha Mechanical has a service (service class) named BOM Manager that provides an interface for Bill of Materials tables, parts, and components in a drawing. BOM Manager also provides an interface for BOM rows and their data.

A Bill of Materials collects all the data from a mechanical structure and its parts and represents that data in a table. BOM Manager works with different sources of data such as BOM rows and data entries and can be created and called just like any service:

OdRxClassPtr pService = odrxServiceDictionary()->getAt(L"AcmBOMManager");  
AcmBOMManagerPtr pBOMMgr = pService->create();

Basically, a Bill of Materials is a special dictionary. AcmBom entries can be found in AcmDictionary.

image1

Figure 1 – List of BOM Tables

BOM Manager works with objects in an open drawing or database, and usually it takes OdDbObjectId as a parameter. Here is a list of implemented BOM Manager methods:

OdResult getItemData(const OdDbObjectId& itemId, OdString& itemNo, OdUInt32& numOfItems, OdMapStringToString& valueMap, const OdDbObjectId& bomStdId);
OdResult getAllBomTables(OdDbObjectIdArray& array, bool xrefed, OdDbDatabase * pHostDb);
OdResult removeAttribute(const OdDbObjectId& itemId, const OdString attribute);
OdResult getBomTable(OdString name, OdDbObjectId& aBomTableId, OdDbDatabase * pDb);
OdResult getPartData(const OdDbObjectId& referenceId, OdUInt32& numOfItems, OdMapStringToString& valueMap);
OdResult setPartData(const OdDbObjectId& referenceId, OdUInt32 numOfItems, const OdMapStringToString& valueMap, bool flag);

BOM Manager: getAllBomTables example

The getAllBomTables method gets all BOM tables for an entire drawing and BOM tables from xreference files (optionally). In the next diagram, there are three types of BOMs shown in an example file:

  • Main BOM Table with the name “MAIN”
  • Assembly BOM Table with the name “COMPONENT ASSEMBLY BOM”
  • Title border BOM Table with the name “TITLE BORDER BOM”
image2

The first parameter is an array of OdDbObjectId elements with IDs of BOM tables. The second parameter determines whether to take (or not take) BOM tables from xreferenced files. The last parameter pHostDb determines the database that should be searched for BOM tables.

OdResult getAllBomTables(OdDbObjectIdArray& array, bool xrefed, OdDbDatabase * pHostDb);

getAllBomTables usage example:

OdDbObjectIdArray objIdArr;
pBOMMgr->getAllBomTables(objIdArr, useXrefs, pDb);

getAllBomTables example output:

List of BOM Tables for d:\listOfBoms2.dwg : MAIN COMPONENT ASSEMBLY BOM TITLE BORDER BOM

BOM Manager: getBomTable example

The getBomTable method returns the OdDbObjectId of a BOM table with a given name. The first parameter is a BOM name. The third parameter is a database pointer where the BOM table is located.

OdResult getBomTable(OdString name, OdDbObjectId& aBomTableId, OdDbDatabase * pDb);

getBomTable usage example:

OdString bomName(L"MAIN");
OdDbObjectId bomTableId;
OdResult result = pBOMMgr->getBomTable(bomName, bomTableId, pDb);
if (result == eOk)
{
  AcmBomPtr pBom = AcmBom::cast(bomTableId.safeOpenObject());
  odPrintConsoleString(pBom->getBomName());
  odPrintConsoleString(L"\n");
  odPrintConsoleString(pBom->getDbHandle().ascii());
  odPrintConsoleString(L"\n");
  return eOk;
}

getBomTable example output:

MAIN 34B

BOM Manager: getPartData example

The getPartData method works with part references. It gets the data held by a part reference and part reference data entry. getPartData takes the OdDbObjectId of a part reference as an input parameter, and the number of items (QTY field) and map of property values are output parameters. The getPartData method checks BOM standards, and if a property is empty, it returns the default BOM standard value (if it exists).

OdResult getPartData(const OdDbObjectId& referenceId, OdUInt32& numOfItems, OdMapStringToString& valueMap);

getPartData usage example:

OdUInt32 numOfItems;
OdMapStringToString valueMap;
result = pBOMMgr->getPartData(partRefObjId, numOfItems, valueMap);

getPartData example output:

BOM_UNITS : ea DESCR : description is missing MATERIAL : Stainless NAME : OP9101SL STANDARD : ISO TOTAL_MASS : =IF(ISBLANK(MASS),BLANK,QTY*MASS)

BOM Manager: getItemData example

The getItemData method works with BOM rows (rows that reflect or contain part data or component data) or with a part list group item. The workflow is similar to getPartData. getItemData takes an OdDbObjectId of the object that you want to get item data for (BOM row or part list group item) as an input parameter. Item number, number of items (QTY), and a map of property values are output parameters.

OdResult getItemData(const OdDbObjectId& itemId, OdString& itemNo, OdUInt32& numOfItems, OdMapStringToString& valueMap, const OdDbObjectId& bomStdId);

getItemData usage example:

OdString itemNo; OdUInt32 numOfItems; OdMapStringToString valueMap; pBOMMgr->getItemData(bomRowId, itemNo, numOfItems, valueMap);

getItemData example output:

1 4 BOM_UNITS : ea DESCR : description is missing MATERIAL : Stainless NAME : OP9101SL STANDARD : ISO

Conclusion

BOM Manager is a service that allows you to work with mechanical components, parts, and BOM rows. BOM Manager works with different user data holders such as part references and data entries but in most cases BOM Manager works as a global get\set service for parts and components. More BOM examples can be found in the Examples\TmBomEx project.

All posts