Close

Relief for ODA Team in Ukraine

Learn more
ODA Drawings SDK
Organization of Layers

The database stores all layers in the layer table. A layer is a record of the layer table. The layer table is a predefined object that exists in the database initially and cannot be deleted. The database contains a set of predefined layers that also exists initially in the layer table and cannot be deleted. The OdDbLayerTable class is the layer table object that represents the interface for accessing the layer table and manipulates the layers in it. The OdDbLayerTableRecord class is the layer record object that represents the interface for accessing a layer and manipulating its properties. The layer table object has the AcDbLayerTable class name; the layer record object has the AcDbLayerTableRecord class name.

The OdDbLayerTablePtr class is the typified smart pointer to an instance of the layer table and is used for storing and passing references to the layer table object. The OdDbLayerTableRecordPtr class is the typified smart pointer to an instance of the layer and is used for storing and passing references to the layer record object. In the following examples, the pDb variable stores the pointer to the database object.

To get the the layer table, use the getLayerTableId() method of the database object; it does not have arguments and returns the OdDbObjectId instance associated with the layer table object. For example:


OdDbObjectId idLayers = pDb->getLayerTableId();

To manipulate layers, the program must open the layer table object and get a smart pointer to it. If the layer table object is opened in read mode, the program can obtain layers and their properties, but it cannot modify them, add a new layer, or delete an existing layer from the table. If the layer table object is opened in write mode, the program can add a new layer in the table, rename any layer, modify properties of an existing layer, or delete the layer from the table.

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


// Open the layer table object in the read mode
OdDbLayerTablePtr pLayers = idLayers.safeOpenObject(OdDb::kForRead);

// Open the layer table object in the write mode
OdDbLayerTablePtr pLayers = idLayers.safeOpenObject(OdDb::kForWrite);

These operations can be combined in one line:


OdDbLayerTablePtr pLayers = pDb->getLayerTableId().safeOpenObject(OdDb::kForWrite);

The layer table object contains two predefined layers, named "0" and "Defpoints", that are used as default objects for associating with entities. To get the Zero layer, use the getLayerZeroId() method of the database object. To get the Defpoints layer, use the getLayerDefpointsId() method of the database object. These methods return the OdDbObjectId instance associated with the corresponding layer. For example:


OdDbLayerTableRecordPtr pZero = pDb->getLayerZeroId().safeOpenObject();
odPrintConsoleString(L"\nThe Zero layer is \"%ls\"", pZero->getName().c_str());

OdDbLayerTableRecordPtr pDefs = pDb->getLayerDefpointsId().safeOpenObject();
odPrintConsoleString(L"\nThe Defpoints layer is \"%ls\"", pDefs->getName().c_str());

Additionally, the layer table object can contain two system layers with predefined names: "*ADSK_CONSTRAINTS" and "*ADSK_SYSTEM_LIGHTS". These layers are absent by default. To work with these layers, use the getLayerAdskId() method of the database object which requires the layer type as a first mandatory argument of the LayerAdskType enumerator (kLayerConstraints or kLayerSystemLights) and returns the Object ID of the corresponding system layer or OdDb::kNull when the system layer is absent. To create the system layer, specify a True value for the second optional argument of the getLayerAdskId() method. If the system layer is absent, this method creates it with the predefined name. For example:


OdDbLayerTableRecordPtr pConstraints = pDb->getLayerAdskId(OdDb::kLayerConstraints, true).safeOpenObject();
odPrintConsoleString(L"\nThe Constraints layer is \"%ls\"", pConstraints->getName().c_str());

OdDbLayerTableRecordPtr pLights = pDb->getLayerAdskId(OdDb::kLayerSystemLights, true).safeOpenObject();
odPrintConsoleString(L"\nThe SystemLights layer is \"%ls\"", pLights->getName().c_str());

The layer table object has the following specific methods: add() method for adding a new layer to the table, getAt() method for getting an existing layer from the table, has() method for checking whether the layer exists in the table, generateUsageData() method for generating usage data for all layers, and newIterator() method for iterating through layers of the table.

See Also

Working with Layers

Manipulating of Layers

Working with Predefined Tables of Named Records

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