SketchUp  Ruby API Reference 

Class Index

Method Index

Developers Guide

Examples

Layer class

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 

Instance Methods


<=>

The <=> method is used to compare two layers based on their names.

Syntax

status = layer1 <=> layer2 

Arguments

layer1 - a Layer object

layer2 - a Layer object

Return Value

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.

Comments

This is used for sorting.

Example

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.

Syntax

status = layer1 == layer2 

Arguments

layer1 - a Layer object

layer2 - a Layer object

Return Value

status - true if layer1 and layer2 are equal. False if layer1 and layer2 are not equal.

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer1 = layers[0]
layer2 = layers[1]
status = layer1 == layer2

 

 


name 

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

Syntax

name = layer.name 
 

Return Value

name - the name of the Layer object

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
name = layer2.name

 

 


name= 

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

Syntax

name - layer.name = "name" 

Arguments

"name" - the new name for the Layer object

Return Value

name - the newly set name

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
name = layer2.name="new test layer"

 

 


page_behavior 

The page_behavior method is used to retrieve the behavior of the layer when new pages are created.

Syntax

pagebehavior = layer.page_behavior 

Return Value

pagebehavior - a decimal number representing the current behavior of the layer when a new page is created (see comments).

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

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
# Returns 0 which is LAYER_VISIBLE_BY_DEFAULT
pb = layer2.page_behavior

 

 


page_behavior=

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

Syntax

pagebehavior = layer.page_behavior = pagebehavior 

Arguments

pagebehavior - pagebehavior flags

Return Value

pagebehavior - a decimal number representing the current behavior of the layer when a new page is created (see comments).

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.

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
# Set to LAYER_HIDDEN_BY_DEFAULT
pb= layer2.page_behavior=
(LAYER_HIDDEN_BY_DEFAULT|LAYER_IS_HIDDEN_ON_NEW_PAGES)

 

 


visible=

The visible= method is used to set the visibility of the layer.

Syntax

status = layer.visible = visibility 

Arguments

visibility - true if you want the layer to be visible, false if you do not want the layer to be visible

Return Value

status - true if visible, false if hidden

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
status = layer2.visible=true

 

 


visible? 

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

Syntax

status = layer.visible? 
 

Return Value

status - true if visible, false if hidden

Example

model = Sketchup.active_model
layers = model.layers
status = layers.add "test layer"
layer2 = layers[1]
status = layer2.visible?

 

SketchUp  Ruby API Reference: Layer

© Google Inc. 2007 sketchup.google.com