Hello,
I am trying to serialize some RhinoObject
with the ToJSON
method.
If I use it on RhinoObject.Geometry
and RhinoObject.Attributes
it returns correct string.
If the method is used on the RhinoObject
itselft it returns null?
Is that correct behavior or I am missing something?
Code sample is simple:
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
try
{
RhinoObject brep = doc.Objects.First();
if (brep == null)
{
RhinoApp.WriteLine("No Brep found.");
return Result.Failure;
}
else
{
Rhino.FileIO.SerializationOptions options = new Rhino.FileIO.SerializationOptions();
options.WriteUserData = true;
// This always return null
var serializedRhinoObject = brep.ToJSON(options);
// This does work...
Dictionary<string, string> jsonDictGeom = JsonConvert.DeserializeObject<Dictionary<string, string>>(brep.ToJSON(options));
Dictionary<string, string> jsonDictAttribute = JsonConvert.DeserializeObject<Dictionary<string, string>>(brep.Attributes.ToJSON(options));
// Nefunguje pro RhinoObject => Discourse napsat....
Brep newbrep = CommonObject.FromJSON(jsonDictGeom) as Brep;
ObjectAttributes attributes = CommonObject.FromJSON(jsonDictAttribute) as ObjectAttributes;
doc.Objects.Add(newbrep, attributes);
return Result.Success;
}
}
catch (Exception ex)
{
RhinoApp.WriteLine("Exception: " + ex.Message);
return Result.Failure;
}
}
Thanks for any reply.
Ondřej