Click or drag to resize

LayerTableItem Property

Conceptually, the layer table is an array of layers. The operator[] can be used to get individual layers. A layer is either active or deleted and this state is reported by Layer.IsDeleted.

Namespace:  Rhino.DocObjects.Tables
Assembly:  RhinoCommon (in RhinoCommon.dll)
Syntax
public Layer this[
	int index
] { get; }

Parameters

index
Type: SystemInt32
zero based array index.

Return Value

Type: Layer
Reference to the layer. If layer_index is out of range, the current layer is returned. Note that this reference may become invalid after AddLayer() is called.
Remarks

Detaching a worksession reference model, or purging a linked instance definition, removes its layers but leaves the table slots they occupied empty. The slots cannot be closed up, because table indices are persistent references that objects store - object attributes hold a layer index - so renumbering would repoint existing objects at the wrong layer. Count spans the empty slots, and they accumulate for the life of the document - one per purge.

An index that lands on an empty slot returns the document's default layer rather than throwing. Nothing about that layer says it is a stand-in: it reports the name "Default" and ordinary values for every other property, so enumerating a table that has been purged several times reports several layers that are not there. The one distinguishing mark is the index - a stand-in reports Index -1, never the index you asked for - so test index == Layers[index].Index before treating an entry as real. Enumerating the table with foreach goes through the document manifest rather than the raw table array, so it does not visit empty slots at all and is the safer way to walk the table. See RH-97389.

See Also