Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Root Drawing Dictionary

The database contains a root drawing dictionary that exists initially. The root drawing dictionary stores information about all dictionaries, which contain various objects of a drawing. The root drawing dictionary contains only dictionaries and associates a unique text keyword (name) with each dictionary that it contains. For example, the dictionary of layouts has the "ACAD_LAYOUT" name, the dictionary of materials has the "ACAD_MATERIAL" name, the dictionary of plot settings has the "ACAD_PLOTSETTINGS" name, the dictionary of groups has the "ACAD_GROUP" name, etc. Each dictionary contains the database objects of the defined and identical type. The number of dictionaries is unlimited. New dictionaries can be added both in the root dictionary and in the contained dictionaries. The root drawing dictionary forms the first level of the tree-shape hierarchical structure of database objects and is the owner for the dictionaries that it contains.

Dictionaries give drawings the ability to store objects of different types, add new types of objects, embed custom objects, attach various data to objects, extend the database in a flexible way without restructuring the format. In the following examples, the pDb variable stores a pointer to the database object.

To get the root drawing dictionary, use the getNamedObjectsDictionaryId() method of the database object; it does not have arguments and returns the OdDbObjectId instance associated with the root dictionary object. For example:


OdDbObjectId idRoot = pDb->getNamedObjectsDictionaryId();

To get a smart pointer to the root drawing dictionary, declare a variable of the OdDbDictionaryPtr type and use the safeOpenObject() method of the obtained OdDbObjectId object. The root dictionary is the predefined object and the erase status is not applicable for it. Therefore, the safeOpenObject() method requires only the open mode as a value of the OdDb::OpenMode enumerator (kForRead, kForWrite, or kForNotify) and returns the smart pointer to the dictionary object. For example:


// Open the root dictionary object in the read mode
OdDbDictionaryPtr pRoot = idRoot.safeOpenObject(OdDb::kForRead);

// Open the root dictionary object in the write mode
OdDbDictionaryPtr pRoot = idRoot.safeOpenObject(OdDb::kForWrite);

These operations can be combined in one line:


OdDbDictionaryPtr pRoot = pDb->getNamedObjectsDictionaryId().safeOpenObject(OdDb::kForWrite);

To iterate through the root drawing dictionary, use the newIterator() method that creates the dictionary iterator. For example, to print information about all slaved dictionaries, traverse the iterator and use the name() method for each item:


odPrintConsoleString(L"\nThe root dictionary contains %d dictionaries:", pRoot->numEntries());

OdDbDictionaryIteratorPtr itSubDict = pRoot->newIterator(); 
while(!itSubDict->done())
{
  odPrintConsoleString(L"\n%s-\"%s\"", itSubDict->objectId().getHandle().ascii(), itSubDict->name().c_str());
  itSubDict->next();
}

To iterate through objects of slaved dictionaries, use nested statements that contain iterators for each sub-dictionary. For example, to print the content of objects in alphabetical order, create the iterator with the OdRx::kDictSorted argument and traverse the iterator for each contained dictionary:


OdDbDictionaryIteratorPtr itObject;

for(itSubDict = pRoot->newIterator() ; !itSubDict->done() ; itSubDict->next())
{
  itObject = ((OdDbDictionaryPtr) itSubDict->getObject())->newIterator(OdRx::kDictSorted)
  
  while(!itObject->done())
  {
    odPrintConsoleString(L"\nH=%s, Name: \"%s\" Class: %s", itObject->objectId().getHandle().ascii(), 
                         itObject->name().c_str(), itObject->getObject()->isA()->name().c_str());
    itObject->next();
  }
}

To create a new dictionary and add it to the root drawing dictionary, use the pseudo-constructor of the dictionary object and the setAt() method of the dictionary object. For example:


OdDbDictionaryPtr pDict = OdDbDictionary::createObject();

pRoot->setAt("MY_DICT", pDict);

odPrintConsoleString(L"\n%s-\"MY_DICT\" Style=%d, %s", pDict->handle().ascii(), pDict->mergeStyle(),
                     ((pDict->isTreatElementsAsHard()) ? L", Hard-Owner" : L", Soft-Owner"), pDict->numEntries());

To get a sub-dictionary of the root drawing dictionary, use the getAt() method which requires the unique name and returns the Object ID of the specified dictionary or OdDb::kNull if the name is absent. For example:


OdDbObjectId idDict = pRoot->getAt("MY_DICT");

if(!idDict.isNull())
{
  OdDbDictionaryPtr pDict = idDict.safeOpenObject();
  odPrintConsoleString(L"\n%s-\"MY_DICT\" Style=%d, %s, Count=%d", pDict->handle().ascii(), pDict->mergeStyle(),
                       ((pDict->isTreatElementsAsHard()) ? L", Hard-Owner" : L", Soft-Owner"), pDict->numEntries());
}

See Also

Working with Dictionaries of Objects

Root Run-Time Dictionary

Creating the Database Dictionary

Adding, Naming, and Removing Objects

Getting and Checking Objects and Names

Example of Selecting a Dictionary from the Root Drawing Dictionary

Copyright © 2002 – 2022. Open Design Alliance. All rights reserved.