Window/Component Options

Also, … in testing I’ve verified that if you attach an EntityObserver object to both the DC instance’s and definition’s "dynamic_attributes" dictionary, then when changing editable attributes, the observer’s onChangeEntity callback will fire for both.

This is possible because the Sketchup::AttributeDictionary class is an Sketchup::Entity subclass.


Test example:

class Spy
  def onChangeEntity(entity)
    puts "onChangeEntity: #{entity.inspect}"
  end
end

# With a Dynamic Component instance selected ...
# (I inserted a dynamic picket Fence component instance,
# from the "Dynamic Components Training" collection.)

dc = Sketchup.active_model.selection[0]
#=> #<Sketchup::ComponentInstance:0x000001ab3ff327d0>

# Attaching an observer instance object to the DC component instance:
dc.add_observer(Spy.new)
#=> true

# Attaching an observer instance object to the instance's DC dictionary:
dc.attribute_dictionary("dynamic_attributes").add_observer(Spy.new)
#=> true

# Attaching an observer instance object to the definition's DC dictionary:
dc.definition.attribute_dictionary("dynamic_attributes").add_observer(Spy.new)
#=> true

Then changing the picket spacing value in the “Component Options” dialog
from 5" to 6", the following observer callback output is seen …

#=> 0.023109 seconds to redraw
#=> onChangeEntity: #<Sketchup::ComponentInstance:0x000001ab3ff327d0>
#=> onChangeEntity: #<Sketchup::AttributeDictionary:0x000001ab402112d0>
#=> onChangeEntity: #<Sketchup::AttributeDictionary:0x000001ab3ff32370>

The first change event for dictionaries is for the instance’s attribute dictionary, the
second is for the dynamic component definition’s attribute dictionary.

You will also get change events firing when you use the Scale Tool on a dynamic instance.