InstanceObjects and UserDictionary

I am writing a plugin with a command that adds an instance object to the document and writes a simple parameter string into the UserDictionary on the InstanceObject. When I run my command again there is an option to “edit” an existing object in the document and to do that I try to read my parameter string back from the selected InstanceObject in order to restore the state of my command. This works well up to a point. Below is the general sequence of events:

  1. Run command first time with nothing selected and hit
    a. Parameters are written to the UserDictionary of the created InstanceObject
  2. Run command second time with previously created object pre-selected
    a. Parameters are read from the UserDictionary of the pre-selected object
    b. The pre-selected object is altered: ReplaceInstanceObject to change the instance definition
    c. Parameters are written/overwritten to the UserDictionary of the created InstanceObject
  3. Run command third time with previously created/altered object pre-selected
    a. Parameters can not be read as the UserDictionary on my InstanceObject is now empty

I’m only dealing with a single object in my document and I can verify that the GUID on the InstanceObject never changes. I can also verify that each time after I write my parameter string to the UserDictionary it appears to me to write successfully. I’m not sure at what point the UserDictionary is getting cleared.

I’ve written a similar test just with normal geometry rather than instance objects and the results are similar but slightly different. In that instance when I reach point 3a the UserDictionary on my RhinoObject does still have my parameter string but it is not the updated copy from step 2 but rather the original from step 1.

Very confused what is happening here. Any ideas?

It’s always best to provide sample code that demonstrates what you are doing and what doesn’t work - preferably code that we can run here without too much effort.

– Dale

Sorry for the long delay. This turned out to be a bug in my code. I had obtained a RhinoObject and was then calling Transform on that with the “deleteOriginal” flag set to true. I then mistakenly thought that I could use the same RhinoObject (rather than reacquiring a fresh reference) to read/write my data to the UserDictionary. So in other words I was writing my data to the old copy of the object.