Layer

LAYER (DXF Reference) definition, defines attribute values for entities on this layer for their attributes set to BYLAYER.

Important

A layer assignment is just an attribute of a DXF entity, it’s not an entity container, the entities are stored in layouts and blocks and the assigned layer is not important for that.

Deleting a layer entry does not delete the entities which reference this layer!

Subclass of

ezdxf.entities.DXFEntity

DXF type

'LAYER'

Factory function

Drawing.layers.new()

See also

Basic concepts of Layers and Tutorial for Layers

class ezdxf.entities.Layer
dxf.handle

DXF handle (feature for experts)

dxf.owner

Handle to owner (LayerTable).

dxf.name

Layer name, case insensitive and can not contain any of this characters: <>/\":;?*|=` (str)

dxf.flags

Layer flags (bit-coded values, feature for experts)

1

Layer is frozen; otherwise layer is thawed; use is_frozen(), freeze() and thaw()

2

Layer is frozen by default in new viewports

4

Layer is locked; use is_locked(), lock(), unlock()

16

If set, table entry is externally dependent on an xref

32

If both this bit and bit 16 are set, the externally dependent xref has been successfully resolved

64

If set, the table entry was referenced by at least one entity in the drawing the last time the drawing was edited. (This flag is for the benefit of AutoCAD commands. It can be ignored by most programs that read DXF files and need not be set by programs that write DXF files)

dxf.color

Layer color, but use property Layer.color to get/set color value, because color is negative for layer status off (int)

dxf.true_color

Layer true color value as int, use property Layer.rgb to set/get true color value as (r, g, b) tuple.

(requires DXF R2004)

dxf.linetype

Name of line type (str)

dxf.plot

Plot flag (int). Whether entities belonging to this layer should be drawn when the document is exported (plotted) to pdf. Does not affect visibility inside the CAD application itself.

1

plot layer (default value)

0

don’t plot layer

dxf.lineweight

Line weight in mm times 100 (e.g. 0.13mm = 13). Smallest line weight is 13 and biggest line weight is 200, values outside this range prevents AutoCAD from loading the file.

ezdxf.lldxf.const.LINEWEIGHT_DEFAULT for using global default line weight.

(requires DXF R13)

dxf.plotstyle_handle

Handle to plot style name?

(requires DXF R13)

dxf.material_handle

Handle to default Material.

(requires DXF R13)

rgb

Get/set DXF attribute dxf.true_color as (r, g, b) tuple, returns None if attribute dxf.true_color is not set.

layer.rgb = (30, 40, 50)
r, g, b = layer.rgb

This is the recommend method to get/set RGB values, when ever possible do not use the DXF low level attribute dxf.true_color.

color

Get/set layer color, preferred method for getting the layer color, because dxf.color is negative for layer status off.

description

Get/set layer description as string

transparency

Get/set layer transparency as float value in the range from 0 to 1. 0 for no transparency (opaque) and 1 for 100% transparency.

is_frozen() bool

Returns True if layer is frozen.

freeze() None

Freeze layer.

thaw() None

Thaw layer.

is_locked() bool

Returns True if layer is locked.

lock() None

Lock layer, entities on this layer are not editable - just important in CAD applications.

unlock() None

Unlock layer, entities on this layer are editable - just important in CAD applications.

is_off() bool

Returns True if layer is off.

is_on() bool

Returns True if layer is on.

on() None

Switch layer on (visible).

off() None

Switch layer off (invisible).

get_color() int

Use property Layer.color instead.

set_color(value: int) None

Use property Layer.color instead.

rename(name: str) None

Rename layer and all known (documented) references to this layer.

Warning

The DXF format is not consistent in storing layer references, the layers are mostly referenced by their case-insensitive name, some later introduced entities do reference layers by handle, which is the safer way in the context of renaming layers.

There is no complete overview of where layer references are stored, third-party entities are black-boxes with unknown content and layer names could be stored in the extended data section of any DXF entity or in XRECORD entities. Which means that in some rare cases references to the old layer name can persist, at least this does not invalidate the DXF document.

Parameters:

name – new layer name

Raises:
  • ValueErrorname contains invalid characters: <>/":;?*|=`

  • ValueError – layer name already exist

  • ValueError – renaming of layers '0' and 'DEFPOINTS' not possible

get_vp_overrides() LayerOverrides

Returns the LayerOverrides object for this layer.

LayerOverrides

class ezdxf.entities.LayerOverrides

This object stores the layer attribute overridden in Viewport entities, where each Viewport can have individual layer attribute overrides.

Layer attributes which can be overridden:

  • ACI color

  • true color (rgb)

  • linetype

  • lineweight

  • transparency

Get the override object for a certain layer by the Layer.get_vp_overrides() method.

It is important to write changes back by calling commit(), otherwise the changes are lost.

Important

The implementation of this feature as DXF structures is not documented by the DXF reference, so if you encounter problems or errors, ALWAYS provide the DXF files, otherwise it is not possible to help.

has_overrides(vp_handle: str | None = None) bool

Returns True if attribute overrides exist for the given Viewport handle. Returns True if any attribute overrides exist if the given handle is None.

commit() None

Write Viewport overrides back into the Layer entity. Without a commit() all changes are lost!

get_color(vp_handle: str) int

Returns the AutoCAD Color Index (ACI) override or the original layer value if no override exist.

set_color(vp_handle: str, value: int) None

Override the AutoCAD Color Index (ACI).

Raises:

ValueError – invalid color value

get_rgb(vp_handle: str) RGB | None

Returns the RGB override or the original layer value if no override exist. Returns None if no true color value is set.

set_rgb(vp_handle: str, value: RGB | None)

Set the RGB override as (red, gree, blue) tuple or None to remove the true color setting.

Raises:

ValueError – invalid RGB value

get_transparency(vp_handle: str) float

Returns the transparency override or the original layer value if no override exist. Returns 0.0 for opaque and 1.0 for fully transparent.

set_transparency(vp_handle: str, value: float) None

Set the transparency override. A transparency of 0.0 is opaque and 1.0 is fully transparent.

Raises:

ValueError – invalid transparency value

get_linetype(vp_handle: str) str

Returns the linetype override or the original layer value if no override exist.

set_linetype(vp_handle: str, value: str) None

Set the linetype override.

Raises:

ValueError – linetype without a LTYPE table entry

get_lineweight(vp_handle: str) int

Returns the lineweight override or the original layer value if no override exist.

set_lineweight(vp_handle: str, value: int) None

Set the lineweight override.

Raises:

ValueError – invalid lineweight value

discard(vp_handle: str | None = None) None

Discard all attribute overrides for the given Viewport handle or for all Viewport entities if the handle is None.