ODA Mechanical SDK: Use Symbol Libraries

Dmytro Kabenok

April 30, 2021

Overview

ODA Mechanical SDK works with symbol libraries, which allow you to save frequently used symbols in a library and insert them in a drawing with preconfigured values. In addition to adding and removing symbols from a library, you can also edit and rename symbols. You can also set a symbol library as the default.

The following symbols support a symbol library:

  • Edge symbols
  • Feature control frame symbols
  • Surface texture symbols
  • Welding symbols

To access the symbol libraries, use the following global functions (listed in the order of the symbols above):

  • include "AmdtEdgeLibrary.h"
    bool getAcmEdgeLibrary(OdDbObjectId& libId, OdDbDatabase* pDb, bool bCreateIfNotExist = true);
  • include "AmdtFCFLibrary.h"
    bool getAcmFCFLibrary(OdDbObjectId& libId, OdDbDatabase* pDb, bool bCreateIfNotExist = true);
  • include "AmdtSurfTextLibrary.h"
    bool getAcmSurfaceTextureLibrary(OdDbObjectId& libId, OdDbDatabase* pDb, bool bCreateIfNotExist = true); 
  • include "AmdtWeldingLibrary.h"
    bool getAcmWeldingLibrary(OdDbObjectId& libId, OdDbDatabase* pDb, bool bCreateIfNotExist = true);

Where:

  • libId — Object ID of the symbol library to be returned if successful.
  • pDb — Pointer to a database.
  • bCreateIfNotExist — If this flag is true, the symbol library is created if it does not exist.

Examples

Example of creating a new library object based on a feature control frame:

OdDbDatabasePtr pDb = ... // get the database

OdDbObjectId libId;
// find and get the ID of the library
if (!getAcmFCFLibrary(libId, pDb, true)) 
  return;

AmdtFCFLibraryPtr pFCFLib = AmdtFCFLibrary::cast(libId.openObject(OdDb::kForWrite));
if (pFCFLib.isNull())
  return;

// create and initialize an AcmFCF symbol for saving it to the library as a template
AcmFCFPtr pFCF = AcmFCF::createObject();
pFCF->setSymbolDefaults(pDb);
pFCF->setAllAround(true);
pFCF->setSymbol(Acm::kProfileLine);
pFCF->setSymbol2(Acm::kStraightness);

// add a new item to the library
OdDbObjectId itemId;
pFCFLib->appendItem(L"FCFSymbTemplate", pFCF, itemId, true);

Example of creating a new library object in an alternative way:

AmdtFCFLibraryPtr pFCFLib = ... // get the library as in previous code example

// create and initialize an AcmFCF symbol for saving it to the library as a template
AcmFCFPtr pFCF = AcmFCF::createObject();
pFCF->setSymbolDefaults(pDb);
pFCF->setAllAround(true);
pFCF->setSymbol(Acm::kCylindricity);
pFCF->setValue(Acm::FCFProjectedZone, L"projectedZone");

// create and initialize AmdtFCFLibObject using settings from AcmFCF
AmdtFCFLibObjectPtr pFCFLibObj = AmdtFCFLibObject::createObject();
pFCFLibObj->set(pFCF->subSymbol(), L"FCFSymbTemplate2", L"ISO", L"AcmFCFStdISO");

// add a new item to the library
OdDbObjectId itemId;
pFCFLib->appendItem(pFCFLibObj, itemId, false);
pFCFLib->appendItem(L"FCFSymbTemplate", pFCF, itemId, true);

Example of updating a symbol library object:

AmdtFCFLibraryPtr pFCFLib = ... // get the library as in previous code example

// find symbol
OdDbObjectId libObjId;
if (!pFCFLib->find(L"FCFSymbTemplate", L"ISO", L"AcmFCFStdISO", libObjId, false))
  return;

AmdtFCFLibObjectPtr pFCFLibObj = AmdtFCFLibObject::cast(libObjId.openObject(OdDb::kForWrite));
if (pFCFLibObj.isNull())
  return;

// create a new AcmFCF for updating the symbol library object
AcmFCFPtr pFCF2 = AcmFCF::createObject();
pFCF2->setSymbolDefaults(pDb);
pFCF2->setAllAround(false);
pFCF2->setSymbol(Acm::kCircularity);

// update the symbol library object
pFCFLibObj->setObject(pFCF2->subSymbol());

Example of creating an AcmFCF symbol based on a library object:

OdDbObjectId libObjId = ... // get the library object ID as in previous code example

AmdtFCFLibObjectPtr pFCFLibObj = AmdtFCFLibObject::cast(libObjId.openObject(OdDb::kForWrite));
if (pFCFLibObj.isNull())
  return;

// create a new AcmFCF symbol
AcmFCFPtr pFCF = AcmFCF::createObject();
pFCF->setSymbolDefaults(pDb);

// load template settings
pFCFLib->loadItem(L"FCFSymbTemplate", pFCF);

Example of setting a symbol library as the default:

AmdtFCFLibraryPtr pFCFLib = .. // get the library as in the first code example

pFCFLib->setIsDefaultItem(L"FCFSymbTemplate", L"ISO", L"AcmFCFStdISO", true);