Class: Sketchup::MaterialsObserver

Inherits:
Object
  • Object
show all
Defined in:
lib/materialsobserver.rb

Overview

This observer interface is implemented to react to Materials events. 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 interest. The callback onMaterialRemoveAll has been deprecated, we recommend using onMaterialRemove instead.

Examples:

# This is an example of an observer that watches the materials collection 
# for new materials and shows a messagebox.
class MyMaterialsObserver < Sketchup::MaterialsObserver
  def onMaterialAdd(materials, material)
    UI.messagebox("onMaterialAdd: " + material.to_s)
  end
end

# Attach the observer.
Sketchup.active_model.materials.add_observer(MyMaterialsObserver.new)

See Also:

Since:

  • SketchUp 6.0

Instance Method Summary collapse

Instance Method Details

#onMaterialAdd(materials, material) ⇒ nil

The onMaterialAdd method is invoked whenever a Sketchup::Material is added.

Examples:

def onMaterialAdd(materials, material)
  UI.messagebox("onMaterialAdd: " + material.to_s)
end

Since:

  • SketchUp 6



41
42
# File 'lib/materialsobserver.rb', line 41

def onMaterialAdd(materials, material)
end

#onMaterialChange(materials, material) ⇒ nil

The onMaterialChange method is invoked whenever a Sketchup::Material's texture image is altered.

Examples:

def onMaterialChange(materials, material)
  UI.messagebox("onMaterialChange: " + material.to_s)
end

Since:

  • SketchUp 6



60
61
# File 'lib/materialsobserver.rb', line 60

def onMaterialChange(materials, material)
end

#onMaterialRefChange(materials, material) ⇒ nil

The onMaterialRefChange method is invoked whenever the number of entities that a material is painted on changes. This could be due to the user manually painting something, but it could also be when faces are split, pasted, push-pulled, deleted, etc.

Examples:

def onMaterialRefChange(materials, material)
  UI.messagebox("onMaterialRefChange: " + material.to_s)
end

Since:

  • SketchUp 6



81
82
# File 'lib/materialsobserver.rb', line 81

def onMaterialRefChange(materials, material)
end

#onMaterialRemove(materials, material) ⇒ nil

The onMaterialRemove method is invoked whenever a Sketchup::Material is deleted.

Examples:

def onMaterialRemove(materials, material)
  UI.messagebox("onMaterialRemove: " + material.to_s)
end

Since:

  • SketchUp 6



99
100
# File 'lib/materialsobserver.rb', line 99

def onMaterialRemove(materials, material)
end

#onMaterialRemoveAllObject

Deprecated.

Since:

  • SketchUp 6.0



103
104
# File 'lib/materialsobserver.rb', line 103

def onMaterialRemoveAll
end

#onMaterialSetCurrent(materials, material) ⇒ nil

The onMaterialSetCurrent method is invoked whenever a different Sketchup::Material is selected in the Materials dialog.

Examples:

def onMaterialSetCurrent(materials, material)
  UI.messagebox("onMaterialSetCurrent: " + material.to_s)
end

Since:

  • SketchUp 6



124
125
# File 'lib/materialsobserver.rb', line 124

def onMaterialSetCurrent(materials, material)
end

#onMaterialUndoRedo(materials, material) ⇒ nil

Note:

Due to a bug, this callback does not fire in SU6 or SU7. You can use the ModelObserver.onTransactionStart to capture all undo events.

The onMaterialUndoRedo method is invoked whenever a material is altered and then those changes are undone or redone.

Examples:

def onMaterialUndoRedo(materials, material)
  UI.messagebox("onMaterialUndoRedo: " + material.to_s)
end

Since:

  • SketchUp 6.0



144
145
# File 'lib/materialsobserver.rb', line 144

def onMaterialUndoRedo(materials, material)
end