I agree that I would expect the change events to kick off when entities are moved or transformed.
However, the current observer system was implemented very close to the metal many years ago.
Lets look at what happens with this sample script:
module Example
class TestEntitiesObserver < Sketchup::EntitiesObserver
def onElementAdded(entities, entity)
puts "EntitiesObserver.onElementAdded(#{entities}, #{entity})"
end
def onElementRemoved(entities, entity)
puts "EntitiesObserver.onElementRemoved(#{entities}, #{entity})"
end
def onElementModified(entities, entity)
puts "EntitiesObserver.onElementModified(#{entities}, #{entity})"
end
end # class TestEntitiesObserver
class TestEntityObserver < Sketchup::EntityObserver
def onChangeEntity(entity)
puts "EntityObserver.onChangeEntity(#{entity})"
end
def onEraseEntity(entity)
puts "EntityObserver.onEraseEntity(#{entity})"
end
end # class TestEntityObserver
# Example.start_observing
def self.start_observing
model = Sketchup.active_model
model.entities.clear!
model.entities.remove_observer(@entities_observer) if @entities_observer
@entities_observer = TestEntitiesObserver.new
model.entities.add_observer(@entities_observer)
@edge = model.entities.add_line([0,0,0], [9,9,9])
@entity_observer = TestEntityObserver.new
@edge.add_observer(@entity_observer)
@edge.start.add_observer(@entity_observer)
@edge.end.add_observer(@entity_observer)
end
end # module
# Here I use the Move tool to move the Edge. Observe that the onChangeEntity for
# the Vertex trigger. This is because when you move something you change the
# position property of the vertices.
# (The AttributeDictionary is an odd one. Looks like noise that should not be
# there.)
EntityObserver.onChangeEntity(#<Sketchup::Vertex:0x0000000cf1bdd0>)
EntityObserver.onChangeEntity(#<Sketchup::Vertex:0x0000000cf1bda8>)
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::AttributeDictionary:0x0000000cfc9bd8>)
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::AttributeDictionaries:0x0000000cfc9c00>)
# Here I toggle the various Soft, Smooth, Hidden properties of the edge.
# The edge itself triggers here because the property is actually on the edge.
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Edge:0x0000000cf1bfb0>)
EntityObserver.onChangeEntity(#<Sketchup::Edge:0x0000000cf1bfb0>)
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Edge:0x0000000cf1bfb0>)
EntityObserver.onChangeEntity(#<Sketchup::Edge:0x0000000cf1bfb0>)
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Edge:0x0000000cf1bfb0>)
EntityObserver.onChangeEntity(#<Sketchup::Edge:0x0000000cf1bfb0>)
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Edge:0x0000000cf1bfb0>)
EntityObserver.onChangeEntity(#<Sketchup::Edge:0x0000000cf1bfb0>)
# Another odd one - creating a layer sends out a change event. I see this with
# any other entities as well. I think it's the core setting up the relationships
# which in turn trigger a change. Noise that I don't think is needed.
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Layer:0x0000000d1320d8>)
# Here I change the layer property.
EntitiesObserver.onElementModified(#<Sketchup::Entities:0x0000000ceb0918>, #<Sketchup::Edge:0x0000000cf1bfb0>)
EntityObserver.onChangeEntity(#<Sketchup::Edge:0x0000000cf1bfb0>)
So while it might not be intuitive, there is a logic. You move something you change the vertices - not the properties of the edges or faces that share the vertices. While I agree that it would be convenient in many case for the notifications to cascade through to the “owner(s)” - this is the current situation.
The reason that the EntitiesObserver doesn’t trigger on the vertex changes is that Entities doesn’t really own the vertices. They have shared ownership by the edges and faces that use it - their lifespan is implicit. Delete a face and you don’t delete its edges, but delete an edge and you delete the vertices because they have no standalone representation in SketchUp.
I hope this sheds some light on things.
“Desired” isn’t the correct word here. As I mentioned briefly, the observers where originally implemented close to the metal. Too close i my opinion and they are a source of pain. We are aware of that. We are looking into ways to ease this pain.