Drawings SDK Developer Guide > Working with .dwg Files > Working with Databases > Working with Database Containers > Working with Predefined Tables of Named Records > Working with Specific Predefined Tables of Named Records > Layers Table > Specific Properties of Layers
Specific Properties of Layers

Each layer 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 record object. In the examples below, the pLayer variable stores a pointer to a layer record object.

Color property

The color property of the layer is used when the color of an entity that belongs to the layer is set to the ByLayer value. The layer color can be defined either as an RGB-value using the byColor method or as an ACI-value using the byACI method (1 ≤ Index ≤ 255) or Foreground method (Index = 7). The None method defines invisible entities for the layer. Other color methods are not applicable for the layer color. The layer record object defines the color as the OdCmColor object. The color is set to the Foreground value (index 7) by default.

To get the color, use the color() method of the layer record object; it does not have arguments and returns the OdCmColor instance. For example:


OdCmColor color = pLayer->color();

OdString sInfo;
switch(color.colorMethod())
{
  case OdCmEntityColor::kByColor:
    sInfo.format(L"byRGB (Red = %d, Green = %d, Blue = %d)", color.red(), color.green(), color.blue());
    break;
  case OdCmEntityColor::kByACI:
    if(color.colorIndex() == 7)
      sInfo.format(L"B|W");
    else
      sInfo.format(L"byACI (Index = %d)", color.colorIndex());
    break;
  case OdCmEntityColor::kForeground:
    sInfo.format(L"B|W");
    break;
  case OdCmEntityColor::kNone:
    sInfo.format(L"None");
    break;
}
odPrintConsoleString(L"\nLayer color = %x : %s", color.color(), sInfo.c_str());

To set the color, use the setColor() method of the layer record object which requires one argument — the color value as the OdCmColor instance — and does not return a value. For example:


// Set the layer color to (Red = 10, Green = 25, Blue = 14)
OdCmColor color1;
color1.setRGB(10, 25, 14);
pLayer->setColor(color1);

// Set the layer color to (Index = 34)
OdCmColor color2;
color2.setACI(34);
pLayer->setColor(color2);

To get the color index or equivalent index of an RGB-value, use the colorIndex() method of the layer record object; it does not have arguments and returns the color index as the OdInt16 value. For example:


OdInt16 idxColor = pLayer->colorIndex();
odPrintConsoleString(L"\nLayer color index = %d", idxColor);

To set the color index, use the setColorIndex() method of the layer record object which requires one argument — the index as the OdInt16 value — and does not return a value. For example:


pLayer->setColorIndex(34);

The color index must be in the range of 1 to 255. Other index values generate an exception. The setColorIndex() method sets the color method to byACI.

Lineweight property

The lineweight property of the layer is used when the lineweight of an entity that belongs to the layer is set to the kLnWtByLayer value. The OdDb::LineWeight enumerator defines the available values of the lineweight. The kLnWtByLayer and kLnWtByBlock values are not applicable for the layer record object. The lineweight is set to the kLnWtByLwDefault value (-3) by default.

To get the lineweight, use the lineweight() method of the layer record object; it does not have arguments and returns the value of the OdDb::LineWeight enumerator. For example:


OdDb::LineWeight lwValue = pLayer->lineweight();

if(lwValue == OdDb::kLnWtByLwDefault)
  odPrintConsoleString(L"\nLineweight = kLnWtByLwDefault");
else 
{ 
  OdString sInfo;
  sInfo.format(L"kLnWt000%d", lwValue);
  odPrintConsoleString(L"\nLineweight = %s", (sInfo.left(5) + sInfo.right(3)));
}

To set the lineweight, use the setLineWeight() method of the layer record object which requires one argument — the value of the OdDb::LineWeight enumerator — and does not return a value. For example:


pLayer->setLineWeight(kLnWt030);

Transparency property

The transparency property of the layer is used when the transparency of an entity that belongs to the layer is set to ByLayer value. The layer transparency can be defined as an Alpha-value (1 ≤ Alpha ≤ 255). Other transparency methods are not applicable for layer transparency. The layer record object defines the transparency as the OdCmTransparency object. The transparency is set to the byAlpha = 100% value (solid) by default.

To get the transparency, use the transparency() method of the layer record object; it does not have arguments and returns the OdCmTransparency instance. For example:


OdCmTransparency clarity = pLayer->transparency();

OdString sInfo;
if(clarity.method() == OdCmTransparency::kByAlpha)
{
  sInfo.format(L"byAlpha = %d", clarity.alpha());
}
odPrintConsoleString(L"\nLayer transparency = %x : %s", clarity.color(), sInfo.c_str());

To set the transparency, use the setTransparency() method of the layer record object which requires one argument — the transparency value as the OdCmTransparency instance — and does not return a value. For example:


// Set the layer transparency to (Alpha = 230)
OdCmTransparency clarity1;
clarity1.setAlpha(230);
pLayer->setTransparency(clarity1);

// Set the layer transparency to 50%
OdCmTransparency clarity2;
clarity2.setAlphaPercent(50);
pLayer->setTransparency(clarity2);

Linetype property

The linetype property of the layer is used when the linetype of an entity that belongs to the layer is set to the ByLayer value. The "ByLayer" and "ByBlock" linetypes are not applicable for the layer. The layer object stores the ID of the linetype object with which it is associated. The layer is associated with the "Continuous" linetype by default.

To get the linetype, use the linetypeObjectId() method of the layer record object; it does not have arguments and returns the OdDbObjectId instance associated with the linetype record object. Then, use the safeOpenObject() method which returns the smart pointer to the linetype record object. For example:


OdDbObjectId idLinetype = pLayer->linetypeObjectId();

OdDbLinetypeTableRecordPtr pLinetype = idLinetype.safeOpenObject();

odPrintConsoleString(L"\nLayer is associated with linetype = %x : %s", 
                     idLinetype.getHandle().ascii().c_str(), pLinetype->getName().c_str());

To set the linetype, use the setLinetypeObjectId() method of the layer record object which requires one argument — the ID of the linetype record object as the OdDbObjectId instance — and does not return a value. The specified object ID must not be OdDb::kNull. The database stores all linetypes in the linetype table. To get the linetype, use the getLinetypeTableId() method of the database object which returns the Object ID of the linetype table object, and use the getAt() method of the linetype table object which returns the Object ID of the linetype record object using its name. For example:


OdDbLinetypeTablePtr pLinetypes = pLayer->database()->getLinetypeTableId().safeOpenObject();

OdDbObjectId idLinetype = pLinetypes->getAt("DASH");

if(!idLinetype.isNull()) pLayer->setLinetypeObjectId(idLinetype);

Material property

The material property of the layer is used when the material of an entity that belongs to the layer is set to the ByLayer value. The materials named "ByLayer" and "ByBlock" are not applicable for a layer. The layer object stores the ID of the material object with which it is associated. The layer is associated with the "Global" material by default.

To get the material, use the materialId() method of the layer record object; it does not have arguments and returns the OdDbObjectId instance associated with the material object. Then, use the safeOpenObject() method to return the smart pointer to the material object. For example:


OdDbObjectId idMaterial = pLayer->materialId();

OdDbMaterialPtr pMaterial = idMaterial.safeOpenObject();

odPrintConsoleString(L"\nLayer is associated with material = %x : %s", 
                     idMaterial.getHandle().ascii().c_str(), pMaterial->name().c_str());

To set the material, use the setMaterialId() method of the layer record object which requires one argument — the Object ID of the material object as the OdDbObjectId instance — and does not return a value. The specified Object ID must not be OdDb::kNull. The database stores all materials in the dictionary. To get the material, use the getMaterialDictionaryId() method of the database object which returns the Object ID of the material's dictionary, and use the getAt() method of the dictionary which returns the Object ID of the material object using its name. For example:


OdDbDictionaryPtr pMaterials = pLayer->database()->getMaterialDictionaryId(().safeOpenObject();

OdDbObjectId idMaterial = pMaterials->getAt("METAL");

if(!idMaterial.isNull()) pLayer->setMaterialId(idMaterial);

Description property

The description property of the layer stores arbitrary text for the layer, for example, comments for understanding the purpose of the layer. The description is an empty string by default.

To get the description, use the description() method of the layer record object; it does not have arguments and returns the description as an OdString value. For example:


odPrintConsoleString(L"\nDescription: %s", pLayer->description().c_str());

To set the description, use the setDescription() method of the layer record object which requires one argument — an OdString value — and does not return a value. For example:


OdString sDesc = L"Information about Layer";
pLayer->setDescription(sDesc);

See Also

Working with Layers

Status of Layers

Example of Working with the Layer Record Object

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