Drawings SDK Developer Guide > Working with .dwg Files > Introduction > Basics of Database Operations and Database Objects > Overview of Layers
Overview of Layers

Creating layers

In a database, layers are stored as layer table records in the layer table. By default the layer table contains one record, layer 0. To create a new layer, create a new OdDbLayerTableRecord object and put it in the OdDbLayerTable object. Note that the layer name must be set before it's added to the layer table.


OdDbLayerTablePtr pLayers = pDb->getLayerTableId().safeOpenObject(OdDb::kForWrite);
OdDbLayerTableRecordPtr pLayer = OdDbLayerTableRecord::createObject();
pLayer->setName("My Layer");
OdDbObjectId layerId = pLayers->add(pLayer);

Layer properties

The OdDbLayerTableRecord class provides methods for accessing a set of layer properties that affect the display of their associated entities. Here is the list with examples of properties and methods to access them:

  • On/Off property. If the layer is off, graphics are not displayed. To access the property use the following methods:
    
    void OdDbLayerTableRecord::setIsOff(bool off);
    bool OdDbLayerTableRecord::isOff() const;
    
  • Frozen/Thawed property. If the layer is frozen, graphics are not regenerated. To access the property use the following methods:
    
    void OdDbLayerTableRecord::setIsFrozen(bool frozen);
    bool OdDbLayerTableRecord::isFrozen() const;
    
  • Locked/Unlocked property. If the layer is locked, entities on this layer cannot be modified. Use the following methods to lock/unlock layers:
    
    void OdDbLayerTableRecord::setIsLocked(bool locked);
    bool OdDbLayerTableRecord::isLocked() const;
    

Each layer also controls the properties of entities on that layer that are set to the ByLayer value. When an entity is drawn, it can use the linetype, lineweight, material, color, and transparency of the associated layer table record.

  • Color property. Defines the color of the entity if the entity color is set to the ByLayer value. Use the following methods to control the color of the layer:
    
    OdCmColor OdDbLayerTableRecord::color() const;
    void OdDbLayerTableRecord::setColor(const OdCmColor &color);
    
  • Linetype property. Defines the linetype of entities on the layer. Use the following methods:
    
    void OdDbLayerTableRecord::setLinetypeObjectId(OdDbObjectId linetypeId);
    OdDbObjectId OdDbLayerTableRecord::linetypeObjectId() const;
    

Iterating through layers inside the layer table

For iterating through layer table records, the mechanism of iterators is used (see also Accessing Database Objects). Use OdDbSymbolTableIterator objects for bidirectional traversing between records within the layer table. For example, to get information about each layer (where pLayers is a smart pointer for the Layer Table object).

The following function illustrates how to access records from the layer table and get information about each layer.


void dumpLayers(OdDbDatabase* pDb)
{
  /**********************************************************************/
  /* Get a SmartPointer to the LayerTable                               */
  /**********************************************************************/
  OdDbLayerTablePtr pTable = pDb->getLayerTableId().safeOpenObject();

  /**********************************************************************/
  /* Get a SmartPointer to a new SymbolTableIterator                    */
  /**********************************************************************/
  OdDbSymbolTableIteratorPtr pIter = pLayers->newIterator();

  /**********************************************************************/
  /* Step through the LayerTable                                        */
  /**********************************************************************/
  for (pIter->start(); !pIter->done(); pIter->step())
  {
    /********************************************************************/
    /* Open the LayerTableRecord for Reading                            */
    /********************************************************************/
    OdDbLayerTableRecordPtr pRecord = pIter->getRecordId().safeOpenObject();

    /********************************************************************/
    /* Dump the LayerTableRecord                                        */
    /********************************************************************/
    printf("Name: %ls\n", toString(pRecord->getName()).c_str());
    printf("On: %ls\n", toString(!pRecord->isOff()).c_str());
    printf("Locked: %ls\n", toString(pRecord->isLocked()).c_str());
    printf("Color: %ls\n", toString(pRecord->color()).c_str());
    printf("Linetype: %ls\n", toString(pRecord->linetypeObjectId()).c_str());
    printf("\n");
  }
}

See Creating Layers topic to get an example of creating layers procedure.

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