class Layers

Parent: Entity | Class Index
Methods: [], add, at, count, each, length, unique_name |
Sample Code:layerstests.rb |

A collection of the Layers in a Model

Instance Methods

[]
The [] method is used to retrieve a layer by index or name
Syntax:
layer = layers[index] layer = layers["name"]
Arguments:
index - a number representing the layer's index in an array of Layer objects "name" - the name of the layer
Return Value:
layer - a Layer object
Comments:
Example:
model = Sketchup.active_model layers = model.layers status = layers.add "test layer" layer1 = layers[0]

add
The add method is used to add a new layer.
Syntax:
layer = layers.add("layer name")
Arguments:
"layer name" - the name of the added layer
Return Value:
layer - the new Layer object
Comments:
If you give the name of a Layer that is already defined, it will return the existing Layer rather than adding a new one.
Example:
model = Sketchup.active_model layers = model.layers status = layers.add "test layer"

at
The at method is an alias for []. See [].
Syntax:
Arguments:
Return Value:
Comments:
Example:

count
The count method is an alias for length. See length.
Syntax:
count = layers.count
Arguments:
Return Value:
Comments:
Example:

each
The each method is used to iterate through all of the layers.
Syntax:
layers.each {|layer| ...}
Arguments:
Return Value:
layer - a variable that will hold each Layer object as they are found.
Comments:
Example:
model = Sketchup.active_model layers = model.layers status = layers.add "test layer" layers.each {| layer | UI.messagebox layer }

length
The length method retrieves the number of layers.
Syntax:
length = layers.length
Arguments:
Return Value:
length - the number of entities in the collection of entities if successful
Comments:
Example:
model = Sketchup.active_model layers = model.layers status = layers.add "test layer"| length = layers.length

unique_name
The unique_name method generates a unique layer name.
Syntax:
newname = layers.unique_name <basename>
Arguments:
<basename> - (optional) basename used as part of the generated name
Return Value:
newname - the new layer name
Comments:
With no arguments it generates a new unique name using the default base. With a basename String passed in, it will generate a new unique name that uses the given base as a prefix. For example you could get a Layer name that starts with the string "Walls" with the command: name = layers.unique_name "Walls". You could then use this new unique name to add a new Layer.
Example:
model = Sketchup.active_model layers = model.layers status = layers.add "test layer" uniquename = layers.unique_name "walls"