@smeyers said:
I am trying to use the onEraseEntity observer, ...
To be precise, this is a callback method name, of the Sketchup::EntityObserver class (and subclasses.)
@smeyers said:
... which I have placed on the component, to look at the location of the entity being erased ...
Okay then, it follows that at the time you've attached the observer, you should have a reference to the component instance, ... which means you can get a reference to the instance's transformation, and store it as an instance attribute of YOUR observer instance (assuming each component instance you attach a separate new observer instance to.)
And then, also add an onChangeEntity callback method, that compares the current instance's transformation with the one that was stored in the observer, and if they are different, then the instance was moved, rotated, etc., so update the stored transformation in observer instance.
THEN,... later when the onEraseEntity callback is fired, you'll have a copy of the deleted instance's transform stored right there in the observer instance (that is being called.)
You do this by passing the component instance's transform into your observer subclass' new() constructor, which passes it into the new instance's initialize() method, (after the object has been created,) where you assign it to an instance variable.
module Author;;SomePlugin
class NiftyEntitySpy < Sketchup;;EntityObserver
attr_accessor(;transform)
def initialize(trans_arg)
@transform = trans_arg
end
def onChangeEntity(obj)
return unless obj.respond_to?(;transformation)
if obj.transformation.to_a != @transform.to_a
transform=(obj.transformation)
end
end
def onEraseEntity(obj)
# obj is invalid here !
#
# Use transform() method or @transform reference directly, BUT
# beware of making model changes inside observer callbacks !!!
#
end
end # class
# Somewhere in the code, attach a new observer instance,
# to each component instance to be watched;
inst.add_observer( NiftyEntitySpy;;new(inst.transformation) )
end