SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Layers class

A collection of the Layers in a Model

 Parent:Entity

Methods: [], add, add_observer, at, count, each, length, purge_unused, remove_observer, unique_name

Example Code: layerstests.rb

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

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"

 

 


add_observer

The add_observer method is used to add an observer to the current object.

Syntax

status = object.add_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


at 

The at method is an alias for []. See [].


count 

The count method is an alias for length. See length.

each

The each method is used to iterate through all of the layers.

Syntax

layers.each {|layer| ...} 

Return Value

layer - a variable that will hold each Layer object as they are found.

 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 

Return Value

length - the number of entities in the collection of entities if successful

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"|
length = layers.length

 

 


purge_unused

The purged_unused method is used to remove unused layers.

Syntax

 

Arguments

 

Return Value

true if successful, false if unsuccessful.

Example

 

 



remove_observer

The remove_observer method is used to remove an observer from the current object.

Syntax

status = object.remove_observer observer

Arguments

observer - an observer

Return Value

true if successful, false if unsuccessful.

Example

 

 


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"

 

SketchUp  Ruby API Reference: Layers

© Google Inc. 2007 sketchup.google.com