pagarcia
(Pablo Garcia-Amorena)
October 21, 2016, 2:01pm
1
Hi all,
In C# rhinocommon, I’m creating a polyline curve with some custom user data and adding it to Rhino. Let’s say I have a PolylineCurve myCurve
and I want to attach my custom user data myUserData
, then in my RunCommand
I have
myCurve.UserData.Add (myUserData);
doc.Objects.AddCurve(myCurve);
but this doesn’t work, as myUserData
seems to be present but not properly initialized.
I have this workaround
doc.Objects.AddCurve(myCurve);
Rhino.DocObjects.RhinoObject objref = doc.Objects.MostRecentObject();
objref.Geometry.UserData.Add(myUserData);
This one works, but I’d rather prefer the first one, as the latter may not be suitable when multiple objects are being added. Any idea to fix the first one?
Many thanks!
Pablo
dale
(Dale Fugier)
October 21, 2016, 6:00pm
2
Without a full code sample to run, its difficult to tell what is going on. But here is a sample that you might find beneficial.
https://github.com/dalefugier/SampleCsUserData
– Dale
pagarcia
(Pablo Garcia-Amorena)
October 21, 2016, 6:59pm
3
Many thanks Dale! I think I had to go through the Attributes
property of my object.
By the way, do you have a similar sample, but using UserDictionary
? Is it more or less the same as UserData
? That would be great!
Pablo
dale
(Dale Fugier)
October 21, 2016, 7:56pm
4
Pablo Garcia-Amorena:
By the way
I don’t think I do. But its pretty darn easy. To set a value, you basically do this:
var dict = obj.Attributes.UserDictionary;
dict.Set("MyKey", value);
To retrieve the value, you do this:
var dict = obj.Attributes.UserDictionary;
var value = dict.Get("MyKey");
– Dale
pagarcia
(Pablo Garcia-Amorena)
October 21, 2016, 8:26pm
5
I see, it’s similar to a C++ map. Very useful!
Pablo