What UserData method needs to be activated?

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

Hi @f.kato,

Rather than assume, perhaps you can upload some code, that we can run here, that is not working for you?

– Dale

Hello Dale,

This is my plugin file which I want to save the situation to .3dm file.

This example is the reference to my program.

I have been struggling the file saving process of UserData. I am a beginner of C# but I have to finish this to get the next stage.
If you check the file and give me some advise, it would be really great.
Any hint of could be to keep up my motivation.

Thank you

Kato

Hi @f.kato,

I don’t see any user data code in your GitHub project. Am I missing something?

Anyway, here is some information on user data:

And a sample:

Let me know if any of this helps.

– Dale

Hello dale

I am sorry for my poor English. I have just misinterpreted many things.
Please forgive me. I will lean more about C# and Rhinocommon stuff.

I appreciate your help as always.

Kato

Hi @f.kato,

No reason to apologize. We are just trying to understand what problem you are having and how we can help. Please never hesitate to ask questions.

Thanks,

– Dale