My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

Layers

class

Parent: Entity

Introduction

SketchUp 6.0+

The Layers collection allows you to see and manage all of the layers in a model. You get a pointer to the Layers object from within the Model.

     model = Sketchup.active_model
     layers = model.layers

Methods

Layers.[]SketchUp 6.0+

The [] method is used to retrieve a layer by index or name.

Arguments:

index_or_name
A number representing the layer's index in an array of Layer objects, or the name of the layer.

Returns:

layer
a Layer object
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 layer_by_number = layers[1]
 layer_by_name = layers["test layer"]

Layers.addSketchUp 6.0+

The add method is used to add a new layer.

If you give the name of a Layer that is already defined, it will return the existing Layer rather than adding a new one.

Arguments:

layer_name
The name of the added layer.

Returns:

layer
the new Layer object
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"

Layers.add_observerSketchUp 6.0+

The add_observer method is used to add an observer to the layers collection.

Arguments:

observer
An observer.

Returns:

success
true if successful, false if unsuccessful.
 layers = Sketchup.active_model.layers
 status = layers.add_observer observer

Layers.atSketchUp 6.0+

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

Returns:

nil
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 layer_by_number = layers.at(1)
 layer_by_name = layers.at("test layer")

Layers.countSketchUp 6.0+

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

Returns:

layer_count
the number of layers in the collection
 model = Sketchup.active_model
 layers = model.layers
 count = model.layers.count
 UI.messagebox("You have " + count.to_s + " layers in your model.")

Layers.eachSketchUp 6.0+

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

Returns:

layer
a variable that will hold each Layer object as they are found.
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 layers.each {| layer | UI.messagebox layer }

Layers.lengthSketchUp 6.0+

The length method retrieves the number of layers.

Returns:

layer_count
the number of layers in the collection
 model = Sketchup.active_model
 layers = model.layers
 length = model.layers.length
 UI.messagebox("You have " + length.to_s + " layers in your model.")

Layers.purge_unusedSketchUp 6.0+

The purged_unused method is used to remove unused layers.

Returns:

success
true if successful, false if unsuccessful.
 layers = Sketchup.active_model.layers
 status = layers.purge_unused

Layers.remove_observerSketchUp 6.0+

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

Arguments:

observer
An observer.

Returns:

success
true if successful, false if unsuccessful.
 layers = Sketchup.active_model.layers
 status = layers.remove_observer observer

Layers.unique_nameSketchUp 6.0+

The unique_name method can be used to get a string that will be a unique layer name inside this collection.

Arguments:

base_name
(optional) The base name to build the unique name from.

Returns:

name
the unique name
 model = Sketchup.active_model
 layers = model.layers
 # Will return "Joe" since there are probably no other layers named that.
 # Or might return something like "Joe #2" if there is already a layer
 # named Joe.
 good_name = layers.unique_name "Joe"