Observer calls missing when using push/pull


#1

Hi,

it’s me again with another observer related problem. This time I’ll provide a ruby snippet right away. :wink:
Okay, so here’s the problem: I’ve attached an EntitiesObserver to the entities of the model, and am attaching EntityObservers to each face that is created. Then I create a rectangle, use push/pull to make a box. So far everything works as expected. But when I use the push/pull tool to grab one of the sides of the box to push or pull it, the only observers that are called are related to the face that I grabbed, not the four faces that are connected to this face and are also changed by the push/pull operation.
If I use the Move tool instead to move one side of the box, the observers for the connected faces are called as expected.

So here’s the code:

require 'sketchup'

module OricAtmos


class MyEntityObserver < Sketchup::EntityObserver
    def onChangeEntity(entity)
        puts("EntityObserver::onChangeEntity: #{entity.to_s} #{entity.entityID}")
    end

    def onEraseEntity(entity)
        puts("EntityObserver::onEraseEntity: #{entity.to_s}, is deleted? #{entity.deleted?}")
    end
end


class MyEntitiesObserver < Sketchup::EntitiesObserver
    def onElementAdded(su_entities, su_entity)
        puts "MyEntitiesObserver(#{self})::onElementAdded: #{su_entities} #{su_entity} #{su_entity.entityID}"
        if su_entity.is_a?(Sketchup::Face)
            #puts "Face: #{su_entity.vertices.map{|v| v.position.to_a}}"
            su_entity.add_observer(MyEntityObserver.new)
        end
    end

    def onElementModified(su_entities, su_entity)
        puts "MyEntitiesObserver(#{self})::onElementModified: #{su_entities} #{su_entity} #{su_entity.entityID}"
        #if su_entity.is_a?(Sketchup::Face)
        #    puts "Face: #{su_entity.vertices.map{|v| v.position.to_a}}"
        #end
    end

    def onElementRemoved(su_entities, su_entity_id)
        puts "MyEntitiesObserver(#{self})::onElementRemoved: #{su_entities} #{su_entity_id}"
    end

    def onEraseEntities(su_entities)
        puts "MyEntitiesObserver(#{self})::onEraseEntities: #{su_entities}"
    end
end


class MyAppObserver < Sketchup::AppObserver
    def expectsStartupModelNotifications()
        return true
    end

    def onNewModel(su_model)
        puts "MyAppObserver::onNewModel: " + su_model.to_s
        su_model.entities.add_observer(MyEntitiesObserver.new())
    end

    def onOpenModel(su_model)
        puts "MyAppObserver::onOpenModel: " + su_model.to_s
        su_model.entities.add_observer(MyEntitiesObserver.new())
    end
end

Sketchup.add_observer(MyAppObserver.new())
end

This is the text output when using the push/pull tool:

MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b519a7bf0> 492
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b519a7bf0>

and this is the output when using move:

MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b5199cf98> 485
MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b519a7bf0> 492
MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b519a7a38> 498
MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b5199f310> 456
MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::Face:0x007f9b519a7448> 457
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b5199f310>
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b5199cf98>
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b519a7bf0>
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b519a7a38>
EntityObserver::onChangeEntity: #<Sketchup::Face:0x007f9b519a7448>
MyEntitiesObserver(#<OricAtmos::MyEntitiesObserver:0x007f9b51994938>)::onElementModified: #<Sketchup::Entities:0x007f9b519949b0> #<Sketchup::AttributeDictionary:0x007f9b519af4e0> 499

Again, I’m using this version of SketchUp:


#2

This happened to me too, I just gave up relying too much on the SU observers :slight_smile: