Add custom Point Object to doc

Hello,
I have a question regarding the CustomPointObject Class.

Until now of the Custom Object Classes i have used mostly CustomCurveObject and been adding them to the rhinodoc with the AddRhinoObject(curveObject, curve) overload which seams to internally convert my customCurveObject to a curveObject.

Right now i’m scripting up a 2d Graph System with Nodes and for the Nodes customPointObjects seem more fitting. Adding customPointObjects to the Rhinodoc doesn’t work with AddRhinoObject(PointObject, Point), and adding just with AddRhinoObject(CustomPointObject) places all added PointObjects at the world origin.

What would be the recommended way of adding a customPointObject considering i don’'t really need a HistoryRecord for my functionality?

Many thanks,
Lando

What are you trying to achieve with your custom point object? And, can that not be achieved by attaching metadata to a normal point object, by using e.g. the UserStrings, UserDictionary, or UserData?

I use the custom Objects mainly for two things:

  1. for visualization e.g. overriding onDraw to give visual feedback to users depending on states and relations between different objects. Maybe this is a wrong approach and I should use classes that derive from display conduits.
  2. I store another object in the custom Objects which has all the logic and methods I use so maybe this could be done as a custom user data object. I only read into custom user data today but it looks promising. And since you are mentioning it here I will try that approach next.

Out of curiosity, is there a particular reason customPointObject can’t be added to the doc like CustomCurveObject?

Yes for additional visualisation your best bet is a custom object, although a conduit might also work. My feeling is that that would require more bookkeeping, compared to overriding the drawing routines.

I don’t know why a custom point object does not work.

Are you giving the base class constructor a Rhino.Geometry.Point object (NOT a Point3d!) in the constructor?

class MyPointObject : CustomPointObject
{
  MyPointObject(Point3d pt) : base(new Point(pt))
  {
  }

}

I just tested the implementation below and it works as expected.

  public class MyPoint : CustomPointObject
  {
    public MyPoint()
    {
      
    }

    public MyPoint(Point3d at) : base(new Point(at))
    {
      
    }

    public override string ShortDescription(bool plural)
    {
      return plural ? "circle-points" : "circle point";
    }

    protected override void OnDraw(DrawEventArgs e)
    {
      e.Display.DrawCircle(new Circle(this.PointGeometry.Location, 10.0), Color.Crimson );
      base.OnDraw(e);
    }
  }

// command:

      Point3d pt;
      if (Result.Success != RhinoGet.GetPoint("Give point", false, out pt))
        return Result.Failure;

      MyPoint obj = new MyPoint(pt);
      doc.Objects.AddRhinoObject(obj);


      return Result.Success;
1 Like

Well d’oh i used my own constructor for customPoint without base. I rewrote it to fit your example and it works now :slight_smile:

Thanks a lot!

1 Like