Detect changes in geometry?
-
Hi,
Is there some way to detect when model geometry is changed, but to ignore all other changes in the model (materials, layers etc).
For example entities adding and deleting can be detected with Sketchup::EntitiesObserver::onElementAddedand Sketchup::EntitiesObserver::onElementRemoved, but these observers won't detect when some of the surfaces in the model is modified (eg. scaled, rotated, moved).
Sketchup::EntitiesObserver::onElementModified is not good solution because it catches all modifications on element and not only geometry ones.Why do I need this?
In my plugin I calculate some sun-shadow properties related to the model. Calculation doesn't block Sketchup, so user can explore model in the meantime. It takes few minutes to calculate results. When/if geometry is changed, calculations should be repeated. So I want my plugin to know when to repeat calculations, and when to keep existing results.Related to this question:
If not possible to detect geometry-only changes, is there some way to "froze model", so it can't be changed (but can be explored) while in calculation mode?
Once user exists calculation mode for my plugin, model should be unfrozen and changes possible again.Thanks in advance,
Marija -
You could try:
model=Sketchup.active_model model.start_operation('process')
First ensure that the 'active_entities' IS the model.entities beforehand by using:
model.close_active until model.active_entities==model.entities
to exit any edit mode...
gp=model.entities.add_group(model.entities.to_a) gp.locked=true
making everything frozen.
Do the processing...
After the process is done you use:
model.abort_operation
to undo the temporary group/lock ?
BUT you'll need to test this with the 'process' - if that is undone by the abort try using 'undo' send_actions ? OR a a last resort...
gp.locked=false gp.explode
BUT that takes time to do... -
You can use the ToolsObserver to detect when the Move, Rotate and Scale tools has performed an action.
-
@maricanis said:
Calculation doesn't block Sketchup, so user can explore model in the meantime.
How are you doing this? Ruby C Extension?@maricanis said:
Related to this question:
If not possible to detect geometry-only changes, is there some way to "froze model", so it can't be changed (but can be explored) while in calculation mode?
Once user exists calculation mode for my plugin, model should be unfrozen and changes possible again.Afraid not.
-
@thomthom said:
@maricanis said:
Calculation doesn't block Sketchup, so user can explore model in the meantime.
How are you doing this? Ruby C Extension?I run some external programs, so I put commands to run in a batch file and run it with UI.openURL(batch_file). It opens black cmd prompt screen, but in general works good. I tried to remove/avoid black screen but not much sucess, so I leave it for now.
@thomthom said:
You can use the ToolsObserver to detect when the Move, Rotate and Scale tools has performed an action.
Yes I saw similar suggestions on forum to track ToolsObserver instead of EntitiesObserver, and just now when I've read again API help pages I see that ToolsObserver.onToolStateChanged can be useful for this.
Thanks,
Marija -
TIG,
Interesting idea to put all in temporary group and lock it.
It seems good idea, but my client've just said that model 'freezing' is not a good option for them.However, I've never used start_operation and Undo related features, so this is good opportunity to look them too.
Thanks,
Marija -
@maricanis said:
However, I've never used start_operation and Undo related features, so this is good opportunity to look them too.
Indeed - they are essential for a good UX so the user an go back and forth.
Another note on the ToolsObserver - the tool state of the tools vary and are not consistent so you need to dig a little to figure out their behaviour. I described some of the behaviour of Move, Rotate and Scale in the comments of AutoSmooth. You can view the source at GitHub: https://github.com/thomthom/AutoSmooth
Advertisement