Object attributes user dictionary keyval pair not saving in Rhino 6?


#1

Hi all,

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.

Lmk if anyone can reproduce this issue. Thanks!

Jon


(Steve Baer) #2

Can you share a 3dm with a single object in it that reproduces this?


#3

Thanks, Steve. This Rhino-5 doc has an object with a keyval pair in its attributes:

On my end the attributes are lost when copy-pasting into a Rhino-6 doc:

I can assign the attributes in Rhino 6, but they don’t survive a save/re-open, so of course I can’t prove this with a file :slight_smile:


(Dale Fugier) #4

Hi @Jon,

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.

Thanks,

– Dale


#5

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.

Thanks!


(Dale Fugier) #6

Hi @Jon

Yes, the empty value matters, as empty values are not archived.

– Dale


#7

Ha, thanks Dale, should’ve tried the obvious. :slight_smile: