Code examples for getting & setting key/value pairs in C#

Hello,

I’ve seen this page:

But would appreciate if there were some C# command examples for getting & setting Key/Value pairs on breps. Or is there another resource that I could be directed to?

I think the right place to start is learning more about user dictionaries?
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_Custom_UserDictionary.htm

Also, is it possible to assign key/value pairs to layers such that all objects can inherit the layer key/pair values?

Thanks,

Dan

Hi @daniel.depoe,

Any class that inherits from CommonObject has a dictionary.

For example:

var min = new Point3d(0.0, 0.0, 0.0);
var max = new Point3d(1.0, 1.0, 1.0);
var bbox = new BoundingBox(min, max);
var brep = Brep.CreateFromBox(bbox);
brep.UserDictionary.Set("Key", "Value");

// TODO...

brep.UserDictionary.TryGetString("Key", out var value);

– Dale

Thanks Dale, I also found this little tidbit of yours.