Modify objects before save

I need to send data to the ArchivableDictionary of an object before the document closes. As per advice on this forum I’m avoiding modifying any objects during events. So I have my plugin run any modifications during the idle event. Of course by the time Idle is called, I’ll have missed the boat. So I would like to know;

By some miracle is the BeginSave Event a safe event to modify in? (I assume not)
And if not, how might I go about doing this?

– Callum

Hi, can you please elaborate with an example that explains why you need this, so we perhaps can help you figure out a more robust way to save your plugin data? @stevebaer can perhaps help as well.

Hey @rajaa ,

I have created an example project that mirrors the dilemma I face; (129.6 KB)

If you create a new document, generate a rectangle and type ‘CreateNewObject’ then an object will be serialized into the UserDictionary of the object as well as added to the ActiveDocument.

In theory on load of the document, the objects in every RhinoObject will be deserialized and added to the ActiveDocument.

The idea is that on Save those objects get serialized into their Host RhinoObjects and saved along with them. But of course the document saves before they get serialized into their host objects.

– Callum

If you write your data during this event, do you get the results you want?

– Dale

I have tried this and it seems to work fine. I tried 1000 objects and no crash. Is this safe to do? :slight_smile:

Yes, this should be safe.

– Dale

1 Like