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

Dmytro Kabenok

March 28, 2019

This is the second article in a series about using the Standard Manager in Mechanical SDK. For the previous article and overview details about standards, see Part 1.

Adding a standard

Two methods are available for adding a standard.

The first method allows you to create a standard automatically using the following params:

  • stdId – Returned as OdDbObjectId of the new standard.
  • baseStdName – Name of the standard with settings that are used as default during initialization.
  • stdName – Name of new standard (if empty, the name of the standard will be the same as the name in the dictionary).
  • bool – The flag bSetCurrent disables or enables setting the standard as current.
  • pDb – Pointer to the database.

If baseStdName is not valid (standard is not registered), it returns eInvalidInput.

OdDbObjectId stdId;
OdString baseStdName(L"ISO");
OdString stdName(L"CustomStd");
bool bSetCurrent = true;
errorStatus = pStdMgr->addStandard(stdId, stdName, baseStdName, bSetCurrent, pDb);

The second method allows you to add a standard to a database, but creating the standard relies entirely on the user. This method is generally used for case-specific initializations or when creating a custom standard. The parameters are almost the same as for the previous method:

  • stdId – Returned as OdDbObjectId if added to the database object.
  • pStd – Pointer to the standard.
  • bool – Flag bSetCurrent is set to true for setting the new standard as current.
  • pDb – Pointer to the database.
OdDbObjectId stdId;
AcmStandard* pStd = //create one from registered standards or custom
bool bSetCurrent = true;
errorStatus = pStdMgr->addStandard(stdId, pStd, bSetCurrent, pDb);

The following picture shows the physical representation of adding a new standard to a database when using the first addStandard method. It is a custom standard based on ISO with a set of symbol standards.

 

123

Removing a standard

A standard can be removed easily using the AcmStandardManager::removeStandard method, which takes an OdDbObjectId as an input parameter. A standard can be removed only if it is not in use anywhere (that is, not a single mechanical symbol in model space was created on this standard); otherwise eStandardIsReferenced is returned as the result.

OdDbObjectId stdId;
errorStatus  = pStdMgr->getStd(L"CustomStd", stdId, pDb);
errorStatus  = pStdMgr->removeStandard(stdId);

Additional manager methods

AcmStandardManager::renameStd renames a standard. It also renames the dependent section and detail view styles in the database.

OdDbObjectId stdId = // get standard id for renaming
OdString newName(L"MechStd");
errorStatus = pStdMgr->renameStd(stdId, newName);

AcmStandardManager::numStandards returns the count of standards already added to the database.

int stdCount = pStdMgr->numStandards(pDb);

There is also another way to create a standard: copy it using AcmStandardManager:: registerStdBasedOn. This creates a full copy of a standard but with a new name. The name must be unique in the database.

OdDbObjectId baseStdId = // get existed standard id for copying
OdDbObjectId copiedStdId;
OdString name(L"CopyOf");
errorStatus = pStdMgr->registerStdBasedOn(baseStdId, name, copiedStdId);

AcmStandardManager::getRegisteredStd fills the array with pointers to OdRxClass objects, derived from the base class. If the baseClass parameter is empty, AcmStandard is used by default.

OdDbVoidPtrArray rxObjArray;
OdString baseClass(L"AcmStandardISO");
errorStatus = pStdMgr->getRegisteredStd(baseClass, rxObjArray);

For regeneration of symbols that depend only on the current standard, AcmStandardManager:: updateSymbols can be used. If the input array is NULL, it regenerates all symbols depending on the current standard; otherwise it regenerates only those that are in the array.

OdDbObjectIdArray* pSymbolsIds = NULL;
errorStatus = pStdMgr->updateSymbols(pDb, pSymbolsIds);

AcmStandardManager:: attachReactor and AcmStandardManager:: removeReactor methods attach and detach the AcmStdReactor to the standard manager. This class is used to track interactions with the standard and to receive notifications if something happens to the standard.

This is the end of the series of articles about using standards in Mechanical SDK, but watch the blog for more articles about Mechanical.