I have a user dictionary keyval pair attached to a doc object’s attributes. The keyval pair persists through a File->Save operation, and for as long as the Rhino doc is open, but is gone after re-opening the doc. This issue occurs in Rhino 6, but not 5. The doc object is an instance definition, in case that matters.
I can see that doc objects in Rhino 6 now have their own user dictionary (meaning one needn’t go through the attributes)… but I’d like to use the same code base if possible.
Can you provide some sample source code, that you use to assign the user dictionary keyval pair, to the instance definition? I’d like to be able to repeat what you are seeing.
Sure. I’m attaching the attributes to the objects in the definition. In the following, assume geometry is a List of GeometryBase:
To set:
// set attributes
var attributes = new List<ObjectAttributes>();
var att = new ObjectAttributes();
string layer_name = "Default";
int layer_index = doc.Layers.Find(layer_name, true);
att.LayerIndex = layer_index;
att.UserDictionary.Set("MySpecialKey", ""); // value is empty, does this matter?
foreach (GeometryBase geom in geometry)
{
attributes.Add(att);
}
// add block to origin
idef_name = "someName";
int idef_indx = doc.InstanceDefinitions.Add(idef_name, "someDescription", new Point3d(0, 0, 0), geometry, attributes);
InstanceDefinition idef = doc.InstanceDefinitions.Find(idef_name, true);
Guid id = doc.Objects.AddInstanceObject(idef.Index, Transform.Identity, att);
To get:
foreach (InstanceDefinition idef in Doc.InstanceDefinitions)
{
if (idef == null) continue;
var obj = idef.Object(0);
if (obj == null || obj.Geometry == null) continue;
if (obj.Attributes.UserDictionary.ContainsKey("MySpecialKey"))
{
// must be my special instance type, do stuff...
}
}
On my end Rhino 6 can’t find the key after saving/re-opening. Works in v5.