All entities have an associated layer. The database always contains at least one layer (layer 0). As with linetypes, you can specify a layer for an entity. If you do not specify a layer, the default database layer value is used for a new entity.
Each layer also has associated properties, which include frozen/thawed, on/off, locked/unlocked, color, linetype, and viewport (see "Container Objects"). When an entity's color or linetype is BYLAYER, the value of the layer property is used for the entity.
If a layer value is specified for an entity, the current database layer value is ignored.
The setLayer() function enables you to set the layer for an entity, either by name or by object ID.
The layer() function returns the name of the current entity layer.
The layerId() function returns the object ID for the current layer (an object of type AcDbLayerTableRecord).