|
SketchUp Ruby API Reference |
The Layer class contains methods modifying and extracting information for a layer.
Parent: Entity
Methods: <=>, ==, name, name=, page_behavior, page_behavior=, visible=, visible?
Example Code: layertests.rb
The <=> method is used to compare two layers based on their names.
status = layer1 <=> layer2
layer1 - a Layer object
layer2 - a Layer object
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.
This is used for sorting.
model = Sketchup.active_model
layers = model.layers
status = 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.
status = layer1 == layer2
layer1 - a Layer object
layer2 - a Layer object
status - true if layer1 and layer2 are equal. False if layer1 and layer2 are not equal.
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer1 = layers[0]
layer2 = layers[1]
status = layer1 == layer2
The name method is used to retrieve the name of the layer.
name = layer.name
name - the name of the Layer object
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
name = layer2.name
The name= method is used to set the name of a layer.
name - layer.name = "name"
"name" - the new name for the Layer object
name - the newly set name
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
name = layer2.name="new test layer"
The page_behavior method is used to retrieve the behavior of the layer when new pages are created.
pagebehavior = layer.page_behavior
pagebehavior - a decimal number representing the current behavior of the layer when a new page is created (see comments).
These flags define the behavior of a Layer on a page. Currently there are two behaviors defined.
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
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]# Returns 0 which is LAYER_VISIBLE_BY_DEFAULTpb = layer2.page_behavior
The page_behavior= method is used to set the behavior of a layer for newly created pages.
pagebehavior = layer.page_behavior = pagebehavior
pagebehavior - pagebehavior flags
pagebehavior - a decimal number representing the current behavior of the layer when a new page is created (see comments).
You can also 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.
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
# Set to LAYER_HIDDEN_BY_DEFAULTpb= layer2.page_behavior=(LAYER_HIDDEN_BY_DEFAULT|LAYER_IS_HIDDEN_ON_NEW_PAGES)
The visible= method is used to set the visibility of the layer.
status = layer.visible = visibility
visibility - true if you want the layer to be visible, false if you do not want the layer to be visible
status - true if visible, false if hidden
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
status = layer2.visible=true
The visible? method is used to determine whether the layer is visible.
status = layer.visible?
status - true if visible, false if hidden
model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
status = layer2.visible?