My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

Layer

class

Parent: Entity

Introduction

SketchUp 6.0+

The Layer class contains methods modifying and extracting information for a layer.

By default, a SketchUp model has one layer, Layer 0 (zero), which is the base layer. You can't delete or rename Layer 0. Unlike certain other CAD software packages, Entities associated with different layers in SketchUp still intersect with each other. (If you want collections of entities to not intersect, place them in Groups instead.)

Layers are commonly used to organize your model and control the visibility of related groups and components. For example, you could make all of your wall and roof entities different groups, associate layers with those groups, and then hide those layers so as to display just the floor plan in the model.

You can programatically create a new layer by calling the Layers.add method.

     model = Sketchup.active_model
     layers = model.layers
     new_layer = layers.add "test layer"

Methods

Layer.<=>SketchUp 6.0+

The <=> method is used to compare two layers based on their names. You could use this for sorting if you're building a list of layer names.

Arguments:

layer1
A Layer object.
layer2
A Layer object.

Returns:

status
-1 if layer 1 is less than layer 2. 1 if layer 2 is less than layer 1. 0 if layer 1 and layer 2 are equal.
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 layer1 = layers[0]
 layer2 = layers[1]
 status = layer1 <=> layer2

Layer.==SketchUp 6.0+

The == method is used to determine if two layers are the same.

Arguments:

layer1
A Layer object.
layer2
A Layer object.

Returns:

status
true if layer1 and layer2 are equal. false if layer1 and layer2 are not equal.
 model = Sketchup.active_model
 layers = model.layers
 layer1 = layers.add "test layer 1"
 layer2 = layers.add "test layer 2"
 status = layer1 == layer2

Layer.nameSketchUp 6.0+

The name method is used to retrieve the name of the layer.

Returns:

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

Layer.name=SketchUp 6.0+

The name= method is used to set the name of a layer.

Arguments:

name
The new name for the Layer object.

Returns:

name
the newly set name
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 name = new_layer.name = "new test layer"

Layer.page_behaviorSketchUp 6.0+

The page_behavior method is used to retrieve the behavior of the layer when new pages are created. For example, you may want your layer to be visible or hidden by default in any new pages (aka Scenes) created by the user.

A page keeps a list of layers that do not have their default behavior. If a layer is not in that list, then it is set to its default visibility determined by one of these flags:

  • LAYER_VISIBLE_BY_DEFAULT 0x0000,
  • LAYER_HIDDEN_BY_DEFAULT 0x0001.
  • Returns:

    pagebehavior
    a decimal number representing the current behavior of the layer when a new page is created (see comments).
     model = Sketchup.active_model
     layers = model.layers
     new_layer = layers.add "test layer"
    
     # Returns 0 which is LAYER_VISIBLE_BY_DEFAULT
     pb = new_layer.page_behavior

Layer.page_behavior=SketchUp 6.0+

The page_behavior= method is used to set the behavior of a layer for newly created pages.

You can set these flags to control the visibility of a layer on newly created pages.

  • LAYER_USES_DEFAULT_VISIBILITY_ON_NEW_PAGES: 0x0000,
  • LAYER_IS_VISIBLE_ON_NEW_PAGES: 0x0010,
  • LAYER_IS_HIDDEN_ON_NEW_PAGES: 0x0020.


To create a layer which is only visible on a single page, you can set its page behavior flags to LAYER_HIDDEN_BY_DEFAULT | LAYER_IS_HIDDEN_ON_NEW_PAGES

When you Update a page (as opposed to creating a new page) the current visibility of the layer is used.

Arguments:

pagebehavior
Pagebehavior flags.

Returns:

pagebehavior
a decimal number representing the current behavior of the layer when a new page is created (see comments).
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"

 # Set to LAYER_HIDDEN_BY_DEFAULT
 pb = new_layer.page_behavior=(LAYER_HIDDEN_BY_DEFAULT |
   LAYER_IS_HIDDEN_ON_NEW_PAGES)

Layer.visible=SketchUp 6.0+

The visible= method is used to set if the layer is visible.

Arguments:

is_visible
The new visibility setting.
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"

 # Hide the layer.
 new_layer.visible = false

Layer.visible?SketchUp 6.0+

The visible? method is used to determine if the layer is visible.

Returns:

true if the layer is visible
 model = Sketchup.active_model
 layers = model.layers
 new_layer = layers.add "test layer"
 UI.messagebox(new_layer.visible?)