Page 1 of 1

Call sim_customizationscriptcall_cleanup before saving

Posted: 22 Aug 2016, 16:20
by meister_steve
This may be an argueable behaviour but for me it would perfectly make sense to have the sim_customizationscriptcall_cleanup called before saving a scene or a model.
By this, changes from the scripts could be remove again (if wanted/implemented in the cleanup section) before saving and so saving just keeps changes to the script itself or changes done outside of the script (i.e. manually).
Maybe to make it a bit clearer: my use-case of a customization script is to have it attached to a dummy object and automatically reload a robot model from somewhere else in the filesystem to the dummy position within the scene as I want to keep the model file separate from the scene file. If someone wants to keep the changes from a customization script, he/she just doesn't implement the removal of these objects in the cleanup section.
What are your thoughts on this???

Regards

Steffen

Re: Call sim_customizationscriptcall_cleanup before saving

Posted: 23 Aug 2016, 10:47
by coppelia
Hello Steffen,

this makes perfectly sense and is a good idea to implement this as a option that can be enabled/disabled on a customization script level, e.g. with:

Code: Select all

simSetScriptAttribute(sim_handle_self,sim_customizationscriptattribute_cleanupbeforesave,true)
Of course this should consider only customization scripts concerned by the save operation, i.e. all in case of scene save, and only the customization scripts of the model, in case of model save.

Not sure if this can make it into the next release, but we'll try.

Cheers

Re: Call sim_customizationscriptcall_cleanup before saving

Posted: 24 Aug 2016, 14:02
by meister_steve
Thanks for the fast reply and the agreement. The suggested solution would be perfectly fine for me.

Regards

Steffen

Re: Call sim_customizationscriptcall_cleanup before saving

Posted: 25 Aug 2016, 14:11
by coppelia
Looking more in details at this, I noticed that there might be a small problem: the undo/redo functionality works by saving the scene to memory at each change, comparing with previous memory save, and effectively saving only the differences of the two.

So this means we would also have to call the clean-up section of customization scripts each time the scene content has changed... which is potentially a lot and will slow down things, depending on what you do in the clean-up or initialization sections. So I'll implement the solution previously mentioned, in addition you will have the property sim_customizationscriptattribute_cleanupbeforeundosave that can be set separately.

The better solution would be to combine 2 methods:
  • Use a dummy as placeholder for the object to load. Attached to it, a customization script.
  • in the init phase of the customization script, check if the dummy has children. If yes, remove them
  • still in the init phase, load the desired model and make the dummy its parent (i.e. attach the model to the parent), set the correct model position/orientation.
  • still in the init phase call simSetScriptAttribute(sim_handle_self,sim_customizationscriptattribute_cleanupbeforesave,true)
  • in the clean-up phase, remove the children of the dummy
With above method, saving the scene will remove the model and add a fresh version immediately after. This way, you can also potentially drastically reduce the size of the scene. When reaching an undo point, the scene will be saved to memory with the old model. When you hit undo, a new scene from memory will be initialized, the old model removed and a fresh version added again.

Cheers

Re: Call sim_customizationscriptcall_cleanup before saving

Posted: 12 Apr 2017, 10:32
by meister_steve
It seems to work now for scenes (so scene objects are deleted before saving) but not for saving model bases with "Saving model as...". Here the submodels (i.e. Sensors) are not removed before saving.

Re: Call sim_customizationscriptcall_cleanup before saving

Posted: 13 Apr 2017, 12:54
by coppelia
Ooops, you are right,
thanks for pointing that out.

Cheers