Mechanical SDK: Using the Standard Manager (Part 1 of 2)

Dmytro Kabenok

March 07, 2019

AcmStandardManager provides functionality for interacting with standards and serves as a bridge between AcmStandard (base class for all «global» mechanical standards) and AcmSymbol (base class for mechanical entities such as AcmFCF, AcmTaper, AcmBalloon and so on) related classes. The manager is mainly used when mechanical symbols are being created to get the appropriate settings for a symbol, regardless of its location.

The phrase «global» is used here because in addition to these standards there are also symbol standards. Symbol standards store a set of parameters for a specific mechanical symbol, in particular to supply graphics. For example, AcmTaperStd standard contains data for an AcmTaper symbol. As for the AcmStandard class, it serves as a container that holds objects for all symbol-related classes.

Accessing the manager

To use AcmStandardManager, just include following file:

#include "AcmStandardManager.h"

And call this function:

AcmStandardManagerPtr pStdMgr = getAcmStdMgr();

Getting a standard’s ID or name

AcmStandardManager provides quite a few methods for getting a standard.

The easiest way to get the ID of a certain standard is to call the AcmStandardManager::getStd method with the following params:

  • stdId – OdDbObjectId of the standard that is searched for.
  • stdName – Name of standard.
  • pDb – Pointer to database.

If there is no such standard in a drawing, it returns eInvalidInput.

OdDbObjectId stdId;
OdString stdName(L"DIN");
Acm::ErrorStatus errorStatus = pStdMgr->getStd(stdName, stdId, pDb);

To get the name of the current standard, call the AcmStandardManager::getCurrent method with OdString and a pointer to the database as parameters. It will return the eAcMeFail result if no standard is correctly set as current.

OdString currStdName;
errorStatus = pStdMgr->getCurrent(currStdName, pDb);

There is also an alternative method to get the current standard, but in this case it returns an identifier of the standard. If you pass the bool flag bCreate as true (as it is set by default) and the standard is absent from the database, it will be created and initialized using default values.

OdDbObjectId currStdId;
errorStatus = pStdMgr->getCurrent(currStdId, pDb, true);

If it is necessary to get an array of all identifiers of the standards that are present in a database, use the AcmStandardManager::getStandards method. If the database does not contain any standards, eStandardIsNotLoaded is returned as the result.

OdDbObjectIdArray stdIds;
errorStatus = pStdMgr->getStandards(stdIds, pDb);

The AcmStandardManager::getAllStandardNames method fills an array with names of all standards that are either present in the database or are available for creating.

OdStringArray stdNames; 
errorStatus = pStdMgr->getAllStandardNames(stdNames);

Also for AcmStandardManager, the getDefaultStd method is available, which returns the name of the default standard. The value depends on the measurement set for the database. If the measurement is set as OdDb::kMetric, the default name is «ISO», otherwise it is «ANSI». Basically, this method is used for creating a default standard for a new database or converting a common database to mechanical.

OdString defaultStdName;
pStdMgr->getDefaultStd(defaultStdName, pDb);

Setting a standard as current

AcmStandardManager has two methods that can set a standard as the current one.

The first method takes the identifier of the standard and a pointer to the database as input parameters. If input OdDbObjectId is not the ID of a standard or the standard is not located in the database, it returns eBad or eObjectNotInDatabase as the result. The measurement set for the database can be changed if the old current standard was ANSI or if it became such. It also updates the global section and detail view styles in the database.

OdDbObjectId newCurrentStdId = // get stdId, for example by using getStd method
errorStatus = pStdMgr->setCurrent(newCurrentStdId, pDb);

The second method for setting a standard as current takes an OdString value and a link to the database as input parameters. If the input standard name is valid but the standard does not exist in the database, it is created, initialized using default values, and set as current.

OdString newCurrentStdName(L"BSI"); 
errorStatus = pStdMgr->setCurrent(newCurrentStdName, pDb);

The next article in this series describes adding a standard and performing various operations with standards.