Hello,
I would like to have an observer to register changes to the entities so I can call functions in my plugin on the C++ side. I have the following snippet to attach an observer to the model in my .rb file:
class myExtSketchupObserver < Sketchup::EntitiesObserver
def onElementModified(entities, entity)
if entity.is_a?(Sketchup::Face)
SUEX_myExt.onElementModified(entity)
end
end
end
Sketchup.active_model.entities.add_observer(myExtSketchupObserver.new)
Then I use the observer to call other methods in the C++ code:
rb_define_module_function(mSUEX_myExt, "onElementModified", VALUEFUNC(DoOnElementModified), -1);
and,
static VALUE DoOnElementModified(int argc, VALUE* argv, VALUE klass)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
VALUE entity;
if (argc > 0)
{
rb_scan_args(argc, argv, "1", &entity);
//TODO - parse the argv
//call other extension functions
}
return true;
}
Couple of questions:
-
I would like to be able to track what has changed so this would be a good spot for me to collect the persistent IDs of the entities maybe?
-
If there is a cube and you pull on a face then
DoOnElementModified
gets triggered 5 times (1 for the pulled face 4 for the connected ones). I would like to know when the last call is. I also have aDoOnTransactionCommit
override in C++ by attaching aSketchup::ModelObserver
, this gets called twice before AND twice afterDoOnElementModified
. (4 times in total) is there some pattern I can use to determine the last call on this function? -
What is the best way to parse the arguments in C++? say I want to input:
SUEX_myExt.onElementModified(entity, num_faces)
how would I then parse theargv
so that I have anSUEntitiesRef
and anint
? -
On a tangent note: if I add an override also for
onElementAdded
then I don’t thinkonElementModified
is called? I tried to attach them on separate observers and also override both methods in one observer. Is there a way to use both functions?
Thank you,
Ege