Should JSON preserve UserDictionary on brep faces?

@dale , would you expect the logic below to preserve the brep face data? Thanks!

	protected override Result RunCommand(RhinoDoc doc, RunMode mode)
	{
		// Create a box brep
		var boxBrep = Brep.CreateFromBox(new BoundingBox(new Point3d(-0.5, -0.5, -0.5), new Point3d(0.5, 0.5, 0.5)));
		boxBrep.Faces[0].UserDictionary["TestKey"] = "TestValue";

		foreach (var pair in boxBrep.Faces[0].UserDictionary)
			RhinoApp.WriteLine($"Key = {pair.Key}, Value = {pair.Value}");

		var options = new Rhino.FileIO.SerializationOptions()
		{
			WriteUserData = true
		};
		var jsonString = boxBrep.ToJSON(options);
		
		var brepFromJson = Rhino.Runtime.CommonObject.FromJSON(jsonString) as Brep;
		foreach (var pair in brepFromJson.Faces[0].UserDictionary)
			RhinoApp.WriteLine($"Key = {pair.Key}, Value = {pair.Value}");

		return Result.Success;
	}

Hi @LarryL,

Since ArchivableDictionary is not part of openNURBS, I would think not.

@stevebaer should know more about this.

– Dale

This should work, but I see in the case of brep faces the dictionary is not getting saved. If you store the dictionary on the top level Brep then the data does properly serialize.

1 Like

Thanks @dale, @stevebaer , I also found if I store the data on the dictionary of the underlysurface of the face it also gets saved.

Is this something that could be rectified in a future SR (assuming you view it as something that needs rectification :slight_smile: )

It’s hard to say at this point since I haven’t done any real digging. File I/O code is always something we need to be very careful about which is why I’m hesitant to just state “yes, we’ll fix it”