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

In a database, layers are stored as layer table records in the layer table. To create a new layer, create a new OdDbLayerTableRecord object and put it in the OdDbLinetypeTable object.

The following code fragment creates a new layer in the database and sets some of its properties.


  /**********************************************************************/
  /* Open the Layer Table                                               */
  /**********************************************************************/
  OdDbLayerTablePtr pLayers = pDb->getLayerTableId().safeOpenObject(OdDb::kForWrite);

  /**********************************************************************/
  /* Create a Layer Table Record                                        */
  /**********************************************************************/
  OdDbLayerTableRecordPtr pLayer = OdDbLayerTableRecord::createObject();

  /**********************************************************************/
  /* Layer must have a name before adding it to the table.              */
  /**********************************************************************/
  pLayer->setName("My Layer");

  /**********************************************************************/
  /* Add the record to the table.                                       */
  /**********************************************************************/
  OdDbObjectId layerId = pLayers->add(pLayer);

  /**********************************************************************/
  /* Set the Color.                                                     */
  /**********************************************************************/
  pLayer->setColorIndex(5);
  
  /**********************************************************************/
  /* Set the layer frozen.                                              */
  /**********************************************************************/
  pLayer->setIsFrozen(true);
Copyright © 2002 – 2020. Open Design Alliance. All rights reserved.