Class: Sketchup::LayerFolder

Inherits:
Entity
  • Object
show all
Includes:
Comparable

Overview

Note:

As of SketchUp 2020 “Layers” were renamed to “Tags” in the UI. The API retains the use of “Layer” for compatibility and is synonymous with “Tag”.

Allows layers to be organized in folders. Folders may have duplicate names.

Version:

  • SketchUp 2021.0

Instance Method Summary # collapse

Methods inherited from Entity

#add_observer, #attribute_dictionaries, #attribute_dictionary, #delete_attribute, #deleted?, #entityID, #get_attribute, #inspect, #model, #persistent_id, #remove_observer, #set_attribute, #to_s, #typename, #valid?

Instance Method Details

#<=>(other) ⇒ Integer?

The #<=> method is used to compare two layer folders based on their names. This enables the Ruby Array#sort method to sort SketchUp layer folders.

Examples:

model = Sketchup.active_model
layers = model.layers
folder1 = layers.add_folder('Folder1')
folder2 = layers.add_folder('Folder2')
comparison = folder1 <=> folder2 # Returns: -1
comparison = folder1 <=> folder1 # Returns: 0
comparison = folder2 <=> folder1 # Returns: 1

Parameters:

  • other (Object)

Returns:

  • (Integer, nil)

    -1 if the receiver should appear before other. 1 if the receiver should appear after other. 0 if the receiver and other are equal. nil if other is not comparable with the receiver.

Version:

  • SketchUp 2021.0

#==(other) ⇒ Boolean

The #== method is used to determine if two layer folders are the same.

Examples:

model = Sketchup.active_model
layers = model.layers
folder1 = layers.add('Folder1')
folder2 = layers.add('Folder2')
equal = folder1 == folder2

Parameters:

  • other (Object)

Returns:

  • (Boolean)

Version:

  • SketchUp 2021.0

#add_folder(name) ⇒ Sketchup::LayerFolder #add_folder(folder) ⇒ Sketchup::LayerFolder

The #add_folder method adds or moves a layer folder.

Examples:

manager = Sketchup.active_model.layers
folder1 = manager.add_folder('Doors')
folder2 = folder1.add_folder('Outer Doors')

Overloads:

Returns:

See Also:

Version:

  • SketchUp 2021.0

#add_layer(layer) ⇒ nil

The #add_layer method adds a layer to a folder.

Examples:

manager = Sketchup.active_model.layers
layer = manager.add_layer('Inner Doors')
folder = manager.add_folder('Doors')

folder.add_layer(layer)

Parameters:

Returns:

  • (nil)

See Also:

Version:

  • SketchUp 2021.0

#count_foldersInteger

The #count_folders method retrieves the number of child folders in the folder.

Examples:

layers = Sketchup.active_model.layers
folder1 = layers.add_folder('Hello')
folder2 = folder1.add_folder('World')
number = folder1.folder_count # Returns: 1

Returns:

  • (Integer)

Version:

  • SketchUp 2021.0

#count_layersInteger Also known as: length, size

The #count_layers method retrieves the number of layers in the folder.

Examples:

layers = Sketchup.active_model.layers
layer = layers.add_layer('World')
folder = layers.add_folder('Hello')
folder.add_layer(layer)
number = folder.layer_count # Returns: 1

Returns:

  • (Integer)

See Also:

Version:

  • SketchUp 2021.0

#each_folder {|folder| ... } ⇒ Object

The #each_folder method is used to iterate through the folders that are direct children to the folder.

Examples:

model = Sketchup.active_model
layers = model.layers
folder1 = layers.add_folder('Hello')
folder1.add_folder('World')
folder1.each_folder { | folder | puts folder.name }

Yields:

Yield Parameters:

Version:

  • SketchUp 2021.0

#each_layer {|layer| ... } ⇒ Object Also known as: each

The #each_layer method is used to iterate through the layers that are direct children to the folder.

Examples:

model = Sketchup.active_model
layers = model.layers
layer = layers.add_layer('World')
folder = layers.add_folder('Hello')
folder.add_layer(layer)
folder.each_layer { | layer | puts layer.name }

Yields:

  • (layer)

Yield Parameters:

Version:

  • SketchUp 2021.0

#folderSketchup::LayerFolder?

The #folder method is used to return the parent layer folder of a layer folder.

Examples:

model = Sketchup.active_model
layers = model.layers
folder1 = layers.add_folder('Folder1')
parent_folder = folder1.folder # Returns: nil

folder2 = folder1.add_folder('Folder2')
parent_folder = folder2.folder # Returns: folder1

Returns:

Version:

  • SketchUp 2021.0

#folder=(parent) ⇒ Object

The #folder= method is used to set the parent layer folder of a layer folder.

This will trigger onLayerFolderRemoved followed by onLayerFolderAdded.

Examples:

model = Sketchup.active_model
layers = model.layers
folder1 = layers.add_folder('Folder1')
folder2 = layers.add_folder('Folder2')

folder2.folder = folder1

Parameters:

  • parent (Sketchup::LayerFolder, nil)

    nil will make the the folder a direct child to the layer manager.

Version:

  • SketchUp 2021.0

#foldersArray<Sketchup::LayerFolder>

The #folders returns the direct child-folders of the folder.

Examples:

manager = Sketchup.active_model.layers
folder1 = manager.add_folder('Doors')
folder2 = folder1.add_folder('Windows')
folders = folder1.folders

Returns:

Version:

  • SketchUp 2021.0

#layersArray<Sketchup::Layer>

The #layers method retrieves the child layers of a folder.

Examples:

manager = Sketchup.active_model.layers
folder = manager.add_folder('Hello')
folder.add_layer(manager.add_layer('World'))
folder.add_layer(manager.add_layer('Universe'))

layers = folder.layers

Returns:

Version:

  • SketchUp 2021.0

#nameString Also known as: display_name

The #name method gets the name of the folder.

Examples:

manager = Sketchup.active_model.layers
folder = manager.add_folder('Doors')
name = folder.name

Returns:

Version:

  • SketchUp 2021.0

#name=(name) ⇒ Object

The #name= method sets the name of the folder.

Examples:

manager = Sketchup.active_model.layers
folder = manager.add_folder('Doors')
folder.name = 'Windows'

Parameters:

Raises:

  • (ArgumentError)

    if name is empty.

Version:

  • SketchUp 2021.0

#remove_folder(folder) ⇒ nil

The #remove_folder method removes the folder from the model. All children are preserved, but move up one level.

Examples:

manager = Sketchup.active_model.layers
folder1 = manager.add_folder('Doors')
folder2 = manager.add_folder('Outer Doors')
folder1.remove_folder(folder2)

Parameters:

Returns:

  • (nil)

Raises:

  • (ArgumentError)

    if the folder is not a direct child of the receiver.

Version:

  • SketchUp 2021.0

#remove_layer(layer) ⇒ nil

The #remove_layer method removes a layer from a folder. The layer will be parent to the layer manager.

Examples:

manager = Sketchup.active_model.layers
layer = manager.add_layer('Inner Doors')
folder = manager.add_folder('Doors')
folder.add_layer(layer)

folder.remove_layer(layer)

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2021.0

#visible=(visible) ⇒ Object

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

Examples:

model = Sketchup.active_model
layers = model.layers
folder = layers.add('Hello')
folder.visible = false

Parameters:

  • visible (Boolean)

Version:

  • SketchUp 2021.0

#visible?Boolean

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

Examples:

model = Sketchup.active_model
layers = model.layers
folder = layers.add('Hello')
folder.visible? # Returns: true

Returns:

  • (Boolean)

Version:

  • SketchUp 2021.0

#visible_on_new_pages=(visible) ⇒ Object

The #visible_on_new_pages= method is used to set if the layer folder is by default visible on new pages.

Examples:

model = Sketchup.active_model
layers = model.layers
folder = layers.add_folder('Hello')
folder.visible_on_new_pages = false
page = model.pages.add('My Page')
model.pages.select_page = page # `folder` will now be hidden.

Parameters:

  • visible (Boolean)

Version:

  • SketchUp 2021.0

#visible_on_new_pages?Boolean

The #visible_on_new_pages? method is used to determine if the layer folder is by default visible on new pages.

Examples:

model = Sketchup.active_model
layers = model.layers
folder = layers.add_folder('Hello')
folder.visible_on_new_pages? # Returns: true

Returns:

  • (Boolean)

Version:

  • SketchUp 2021.0