UserDictionary of Point geometry not preserved when adding to RhinoDoc

@stevebaer and @dale Can I draw your attention to the following: when I create a Point geometry and add data to its UserDictionary, the information in the dictionary gets lost after the Point is added to the document (see command code below)

This is probably because of these lines in ObjectTable.cs:Add(GeometryBase, ObjectAttributes)

case ObjectType.Point:
  return this.AddPoint(((Rhino.Geometry.Point) geometry).Location, attributes);

where only the location is used to re-direct to AddPoint. The UserDictionary info is therefore not copied to the newly added object.

There may be more cases where this is a problem?

To reproduce, run this code:

Point p = new Point(Point3d.Origin);
p.UserDictionary.Set("MY_KEY", "MY_VALUE");

Guid id = doc.Objects.Add(p);
RhinoObject obj = doc.Objects.Find(id);

bool keyFound = obj.Geometry.UserDictionary.ContainsKey("MY_KEY");
if (keyFound)
    RhinoApp.WriteLine("Key found. all is good");
else
{
    // I get this
    RhinoApp.WriteLine("Key not found. oh dear");
}

return Result.Success;

I’ve added this to the list of things to get fixed.

http://mcneel.myjetbrains.com/youtrack/issue/RH-29056

Thanks Menno,

Giulio

Giulio Piacentino
for Robert McNeel & Associates
giulio@mcneel.com

@menno, this should be fixed in the next V6 WIP release.

1 Like

@stevebaer
@piac

It seem to be the Surface also can not preserved the UserDictionary to RhinoDoc.

Notice

Brep can preserved the UserDictionary.

Hi @cughudson,

Can you provide a small code snippet that will allow us to repeat the problem you are seeing?

Thanks,

– Dale

I was using Grashopper’s C# Component find this “BUG”


When I Bake the Component 1(show in the picture below) to RhinoDocument, the UseDictionary can preserved, but Component 2 does not.

The C# Code of C# Script Componet is as follow:

Srf.UserDictionary.Set("Test", "TestData");

Hi @cughudson,

Keep in mind that any surface you bake is added to the document as a Brep. So if you are adding user data inside of your script, make sure to create a Brep from the surface and then add the user data to the Brep before returning.

– Dale

@dale
It is mean that, When I Convert an Brep from Surface, the user data attach to the surface will be wipe out?

Hi @cughudson,

No not at all. However, the surface is added to the Brep structure. So getting to the user data takes a bit more work.

Can you post a sample .gh solution for me to evaluate?

Thanks,

– Dale

Hi @dale,

I have post the test gh file at the below.
Thanks.
UserDictTest.gh (6.1 KB)

Hi @cughudson,

Yes if you want your user data attached to a “top” level geometry object, attach it to a Brep, not a Surface.

If you have a Surface, you can create a Brep like this:

var brep = surface.ToBrep();

– Dale

@dale
OK, Dale
And If you using the code var brep = surface.ToBrep() to convert the surface to Brep, is maybe return null (from the RhinoCommon SDK document). So I question is:

Is any surface can using ToBrep() Convert to Brep?If not,Which type of the surface can not
convert to the Brep Correctly?

Thanks a lot

Hi @cughudson,

Yes, any object that inherits from Rhino.Geometry.Surface can be converted to a Brep.

– Dale

@dale
Thanks , Happy NewYear