Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Organization of Scales

The database stores all named scales in the scale dictionary. The named scale is the item of the scale dictionary. The scale dictionary is the standard dictionary object of the database that is placed in the root drawing dictionary and has the unified dictionary interface for manipulating scales. The "ACAD_SCALELIST" keyword identifies the scale dictionary object in the root.

The OdDbScale class is the scale object that represents the interface for accessing a scale and manipulating its properties. The OdDbDictionary class is used as a container for storing scales. The scale object has the AcDbScale class name, and the scale dictionary object has the AcDbDictionary class name.

The OdDbScalePtr class is the typified smart pointer to an instance of the scale and is used for storing and passing of references to the scale object. In examples, the pDb variable store the pointer to the database object.

To get the scale dictionary, use the getScaleListDictionaryId() method of the database object that has a one argument — the preset status as a Boolean value — and returns the OdDbObjectId instance associated with the scale dictionary object. For example:


OdDbObjectId idScales = pDb->getScaleListDictionaryId();

When the scale dictionary exists in the database, this method returns the Object ID of the existing dictionary independent of the preset status (True or False). When the scale dictionary is absent from the database and the preset status is False, this method returns OdDb::kNull. When the scale dictionary is absent from the database and the preset status is True, this method creates a new dictionary, adds it in the root drawing dictionary, associates the "ACAD_SCALELIST" name with it, assigns a unique ID, and returns the Object ID of the created dictionary. The preset status is an optional argument and is True by default.

For example, to check the availability of the scale dictionary and get its ID:


OdDbObjectId idScales = pDb->getScaleListDictionaryId(false);
if(idScales.isNull())
  odPrintConsoleString(L"\nThe scale's dictionary is absent in the database\n");
else
  odPrintConsoleString(L"\nThe scale's dictionary has ID = %s\n", idScales.getHandle().ascii().c_str());

For example, to get the existing scale dictionary or create a new dictionary if it is absent from the database:


OdDbObjectId idScales = pDb->getScaleListDictionaryId(true);

To check the availability of the scale dictionary and get its ID, you can also use the root drawing dictionary. For example:


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

if(pRoot->has("ACAD_SCALELIST"))
{
  OdDbObjectId idScales = pRoot->getAt(L"ACAD_SCALELIST");
  
  odPrintConsoleString(L"\nThe scale's dictionary has ID = %s\n", idScales.getHandle().ascii().c_str());
}
else odPrintConsoleString(L"\nThe scale's dictionary is absent in the database\n");

To manipulate scales, the program must open the scale dictionary object and get a smart pointer to it. If the scale dictionary is opened in read mode, the program can obtain the scale objects and their properties. If the scale dictionary is opened in write mode, the program can add a new scale in the dictionary, rename any scale, modify properties of an existing scale, or delete the scale from the dictionary.

To get the smart pointer to the scale dictionary object, declare a variable of the OdDbDictionaryPtr type and use the safeOpenObject() method of the obtained OdDbObjectId object. This method requires one argument — the mode to be opened as a value of the OdDb::OpenMode enumerator (kForRead, kForWrite, or kForNotify) — and returns a smart pointer to the object. For example:


// Open the scale's dictionary in the read mode
OdDbDictionaryPtr pScales = idScales.safeOpenObject(OdDb::kForRead);

// Open the scale's dictionary in the write mode
OdDbDictionaryPtr pScales = idScales.safeOpenObject(OdDb::kForWrite);

These operations can be united in one line:


OdDbDictionaryPtr pScales = pDb->getScaleListDictionaryId(true).safeOpenObject(OdDb::kForWrite);

The scale dictionary has the standard dictionary interface for manipulating scale objects.

See Also

Working with Scales

Specific Properties of Scales

Manipulating Objects of the Scale Dictionary

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