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"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:
Returns:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer" layer1 = layers[0] layer2 = layers[1] status = layer1 <=> layer2
The == method is used to determine if two layers are the same.
Arguments:
Returns:
model = Sketchup.active_model layers = model.layers layer1 = layers.add "test layer 1" layer2 = layers.add "test layer 2" status = layer1 == layer2
The name method is used to retrieve the name of the layer.
Returns:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer" name = new_layer.name
The name= method is used to set the name of a layer.
Arguments:
Returns:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer" name = new_layer.name = "new test layer"
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:
Returns:
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
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.
Arguments:
Returns:
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)
The visible= method is used to set if the layer is visible.
Arguments:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer" # Hide the layer. new_layer.visible = false
The visible? method is used to determine if the layer is visible.
Returns:
model = Sketchup.active_model layers = model.layers new_layer = layers.add "test layer" UI.messagebox(new_layer.visible?)