Change colour of a point object using Rhinocommon C#


#1

I want to change the color of a point object when i create it. I have tried adding it as an attribute but no success. I tried the following

Point3d point = SelectedSurface.PointAt(u, v);
var attributes = new Rhino.DocObjects.ObjectAttributes();
attributes.ObjectColor = System.Drawing.Color.Blue;
attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
doc.Objects.AddPoint(point,attributes);

please suggest a solution


(Menno Deij - van Rijswijk) #2

You’re doing it right. I just made this command to test and I get a blue point.

Did you call doc.Views.Redraw() at the end of your code to show the added point?

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
    ObjRef sRef;
    var r = RhinoGet.GetOneObject("Select surface", false, ObjectType.Surface, out sRef);
    if (r != Result.Success)
        return r;
    doc.Objects.UnselectAll(true);

    var SelectedSurface = sRef.Surface();

    GetPoint gp = new GetPoint();
    gp.Constrain(SelectedSurface, false);
    gp.SetCommandPrompt("Select a point on the surface");
    GetResult res = gp.Get();
    if (res != GetResult.Point)
        return Result.Failure;

    Point3d point = gp.Point();

    var attributes = new Rhino.DocObjects.ObjectAttributes();
    attributes.ObjectColor = System.Drawing.Color.Blue;
    attributes.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
    doc.Objects.AddPoint(point, attributes);

    doc.Views.Redraw();
    return Result.Success;
}