Class: Sketchup::LayersObserver Abstract

Inherits:
Object
  • Object
show all

Overview

This class is abstract.

To implement this observer, create a Ruby class of this type, override the desired methods, and add an instance of the observer to the objects of interests.

This observer interface is implemented to react to layers events.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerAdded(layers, layer)
    puts "onLayerAdded: #{layer.name}"
  end
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
Sketchup.active_model.layers.add("Hello World")

Version:

  • SketchUp 6.0

Instance Method Summary # collapse

Instance Method Details

#onCurrentLayerChanged(layers, layer) ⇒ nil

The #onCurrentLayerChanged method is called when the user selects a different active layer.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onCurrentLayerChanged(layers, layer)
    puts "onCurrentLayerChanged: #{layer.name}"
  end
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
layer = Sketchup.active_model.layers.add("Hello World")
Sketchup.active_model.active_layer = layer

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#onLayerAdded(layers, layer) ⇒ nil

The #onLayerAdded method is called when a new layer is added to a model.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerAdded(layers, layer)
    puts "onLayerAdded: #{layer.name}"
  end
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
Sketchup.active_model.layers.add("Hello World")

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#onLayerChanged(layers, layer) ⇒ nil

The #onLayerChanged method is called when a layer is changed.

Examples:

def onLayerChanged(layers, layer)
  puts "onLayerChanged: #{layer.name}"
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
layer = Sketchup.active_model.layers.add("Hello World")
layer.name = "Hello Universe"

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2014

#onLayerFolderAdded(layers, layer_folder) ⇒ nil

The #onLayerFolderAdded method is called when a layer folder is added to a model.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerFolderAdded(layers, layer_folder)
    puts "onLayerFolderAdded: #{layer_folder.name}"
  end
end

model = Sketchup.active_model
model.layers.add_observer(MyLayersObserver.new)
folder = model.layers.add_folder("Hello World")

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2021.0

#onLayerFolderChanged(layers, layer_folder) ⇒ nil

The #onLayerFolderChanged method is called when a layer folder changes one of its properties.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerFolderChanged(layers, layer_folder)
    puts "onLayerFolderChanged: #{layer_folder.name}"
  end
end

model = Sketchup.active_model
model.layers.add_observer(MyLayersObserver.new)
folder = model.layers.add_folder("Hello World")
folder.name = "Hello Universe"
folder.visible = false

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2021.0

#onLayerFolderRemoved(layers, layer_folder) ⇒ nil

The #onLayerFolderRemoved method is called when a layer folder is removed from a model.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerFolderRemoved(layers, layer_folder)
    puts "onLayerRemoved: #{layer_folder.name}"
  end
end

model = Sketchup.active_model
model.layers.add_observer(MyLayersObserver.new)
folder = model.layers.add_folder("Hello World")
model.layers.remove_folder(folder)

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2021.0

#onLayerRemoved(layers, layer) ⇒ nil

The #onLayerRemoved method is called when a layer is removed from a model.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onLayerRemoved(layers, layer)
    puts "onLayerRemoved: #{layer.name}"
  end
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
layer = Sketchup.active_model.layers.add("Hello World")
Sketchup.active_model.layers.remove(layer)

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0

#onParentFolderChanged(layers, layer) ⇒ nil

Note:

When a folder changes parent #onLayerFolderRemoved and #onLayerFolderAdded triggers.

The #onParentFolderChanged method is called when a layer changes parent folder.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onParentFolderChanged(layers, layer)
    puts "onParentFolderChange: #{layer.name}"
  end
end

model = Sketchup.active_model
model.layers.add_observer(MyLayersObserver.new)
layer = model.layers.add_layer("World")
folder = model.layers.add_folder("Hello")
layer.folder = folder

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 2021.0

#onRemoveAllLayers(layers) ⇒ nil

The #onRemoveAllLayers method is called when all layer are removed from a model.

Examples:

class MyLayersObserver < Sketchup::LayersObserver
  def onRemoveAllLayers(layers)
    puts "onRemoveAllLayers: #{layers}"
  end
end

Sketchup.active_model.layers.add_observer(MyLayersObserver.new)
layer = Sketchup.active_model.layers.add("Hello World")
Sketchup.active_model.layers.remove(layer)

Parameters:

Returns:

  • (nil)

Version:

  • SketchUp 6.0