How to bake color curves with c# component


It’s a question that I followed up on my post last time. I wanted to bake curves from grasshopper to Rhino. This time I want to add and select the color of that curve on grasshopper. I wrote the following code but could not implement it.

protected override void RegisterInputParams(GH_Component.GH_InputParamManager pManager)
pManager.AddBooleanParameter(“Boolean”, “B”, “True or False”, GH_ParamAccess.item);
pManager.AddCurveParameter(“Curve”, “C”, “Bake curves”, GH_ParamAccess.list);
pManager.AddColourParameter(“Colour”, “C”, “Objects colour”, GH_ParamAccess.list);

    protected override void RegisterOutputParams(GH_Component.GH_OutputParamManager pManager)

    protected override void SolveInstance(IGH_DataAccess DA)
        List<Curve> crv = new List<Curve>();
        if (!DA.GetDataList(1, crv)) return;

        List<Color> colors = new List<Color>();
        if (!DA.GetDataList(2, colors)) return;

        var objAttr = new ObjectAttributes();
        objAttr.ColorSource = ObjectColorSource.ColorFromObject;
        objAttr.ObjectColor = Color.Red;

        var t = true;
        if (!DA.GetData(0, ref t)) return;

        Rhino.DocObjects.Tables.ObjectTable ot = Rhino.RhinoDoc.ActiveDoc.Objects;
        if (t)
            foreach(Curve c in crv)
                ot.Add(c, objAttr);

What code do I need to rewrite to allow the colors to be selected on grasshopper?

For Baking a Curve with attributes:

In one very long line :wink:
You can see how attributes are initializes in in-line constructor.

Guid g1 = Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(


new Rhino.DocObjects.ObjectAttributes { ObjectDecoration = Rhino.DocObjects.ObjectDecoration.EndArrowhead, PlotColor =  System.Drawing.Color.FromArgb(255, 0, 0), PlotWeightSource = Rhino.DocObjects.ObjectPlotWeightSource.PlotWeightFromObject, PlotColorSource = Rhino.DocObjects.ObjectPlotColorSource.PlotColorFromObject,  ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject, ObjectColor = System.Drawing.Color.FromArgb(255, 0, 0),PlotWeight = 0.5, DisplayOrder = 1 }


If you want to get rhino object color, you first get GUID then cast to geometry type if possible, then retrieve object color informaiton.

1 Like

It worked! Thank you Petras!

By the way, is it possible to use a “color swatch component” to specify a color?

Add in your inputs: