@dmac said:
removeMaterials takes more time after calling addObservers/removeObservers again. What is taking the time if the observers aren't active?
Some of us are suspicous about the remove_observer()
(I recall some other topics, here at SCF where other people reported slow downs as the number of model entities increased. Do a search on this forum.)
When you are done with an observer instance, set it to nil and run Garbage Collection.
GC.start
Also:
@@watchedFaces.each { |f, o|
needs to be:
@@watchedFaces.each_with_index { |f, o|
if you are using an Array...
... but I think you want to use a Hash instead, where the keys are the object_id of the face objects, and the Hash values are references to the observer instance that is attached to it.
@@watchedFaces = Hash.new model.entities.to_a.each { |e| (@@watchedFaces[e.object_id]=MyEntityObserver.new) if e.instance_of?(Sketchup::Face) }
(Since the entity is getting a 'change' by attaching an observer, it is smart, to iterate an array, rather than the C++ entities collection directly.)
If there are Groups and Components in the model, then the above will only find "free" face objects, not faces nested down in Group or Component hierarchies.