Hi all,
I followed the sample program and simply replaced its properties “int Weight” and “double Density” to Point3d that are min and max corners of BoundingBox.
My RunCommand is that just building simple BoundingBox and pass it to User data class.
Unlike the sample code is successfully writes and reads UserData, my ShouldWrite method is not called when Rhino saving .3dm file and of course not Write method is called too.
Here is my code.
[Guid("8D4CA4C6-66EC-4ACD-B4D8-540CF293D8DF")]
public class BoxPointData : Rhino.DocObjects.Custom.UserData
{
public Point3d minPoint { get; set; }
public Point3d maxPoint { get; set; }
public BoundingBox b_box;
public BoxPointData() { }
public BoxPointData(BoundingBox bbox)
{
b_box = bbox;
minPoint = b_box.Min;
maxPoint = b_box.Max;
}
public override string Description
{
get { return "BoxPointsData"; }
}
public override string ToString()
{
return String.Format("MinimumPoint={0}, MaximumPoint={1}", minPoint, maxPoint);
}
protected override void OnDuplicate(Rhino.DocObjects.Custom.UserData source)
{
BoxPointData src = source as BoxPointData;
if (src != null)
{
minPoint = src.minPoint;
maxPoint = src.maxPoint;
}
}
public override bool ShouldWrite
{
get
{
if (minPoint.IsValid && maxPoint.IsValid)
return true;
return false;
}
}
protected override bool Read(BinaryArchiveReader archive)
{
Rhino.Collections.ArchivableDictionary dict = archive.ReadDictionary();
if (dict.ContainsKey("MinimumPoint") && dict.ContainsKey("MaximumPoint"))
{
minPoint = (Point3d)dict["MinimumPoint"];
maxPoint = (Point3d)dict["MaximumPoint"];
}
return true;
}
protected override bool Write(BinaryArchiveWriter archive)
{
var dict = new Rhino.Collections.ArchivableDictionary(1, "BoxPointsData");
dict.Set("MinimumPoin", minPoint);
dict.Set("MaximumPoint", maxPoint);
archive.WriteDictionary(dict);
return true;
}
}
[Guid("ca9a110e-3969-49ec-9d59-a7c2ee0b85bd")]
public class DocumentUserDataCommand : Rhino.Commands.Command
{
public override string EnglishName { get { return "DocumentUserData"; } }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode)
{
Box basebox;
RhinoGet.GetBox(out basebox);
var bbox = basebox.BoundingBox;
var data = new BoxPointData(bbox);
return Rhino.Commands.Result.Success;
}
}
I assume why my methods are not called is because of there is not ObjRef in RunCommand.
So, is ObjRef must needed for UserData or there is any other way to store Geometry data as UserData?
Moreover, I would like to know what exactly can be invoke ShouldWrite and Write methods. It would be good for visualize that saving UserData mechanism in my brain.
Thank you
Kato