Bake curves with specific RGB colors - possible without plug-in?

Via a Python script component? Or do I absolutely need something like Elefront?

One approach is to use rhinoscriptsyntax.ObjectColor after adding/baking geometry. Here’s a simple example with adding a point and then setting its color:


210429_ObjectColor_00.gh (2.9 KB)

Yeah, thanks, I had to go look up my documentation on all that, I’m in the process of getting up to speed on it now…

1 Like

Trying to do this in RhinoCommon, but I’m getting a “Multiple targets could match” when I try to modify the attributes… It works OK outside of the GH environment in the regular Python editor.

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino, System

if Bake:
    rhobj=rs.coercerhinoobject(Crv)
    sc.doc=Rhino.RhinoDoc.ActiveDoc
    attr=Rhino.DocObjects.ObjectAttributes()
    attr.ColorSource=Rhino.DocObjects.ObjectColorSource.ColorFromObject
    attr.ObjectColor=System.Drawing.Color.FromArgb(0,255,0)
    sc.doc.Objects.ModifyAttributes(rhobj,attr,True)
    sc.doc.Views.Redraw()
    sc.doc.Objects.Add(rhobj,attr)
    sc.doc = ghdoc

BakeTest.gh (5.2 KB)

Open source Python:

Oh, curves? :thinking:

1 Like

rhobj is None when I run your test. But also, doesn’t ModifyAttributes take the guid of a Rhino document object (i.e. and not a RhinoCommon type, which you would get from coercing your Crv input):

This is working:

image

import rhinoscriptsyntax as rs
import scriptcontext as sc
import Rhino

sc.doc = ghdoc

rhobj = rs.coercerhinoobject(Crv)

geometry = rhobj.Geometry

sc.doc = Rhino.RhinoDoc.ActiveDoc

rhino_obj = sc.doc.Objects.Add(geometry)
rs.ObjectColor(rhino_obj, rs.coercecolor([0,255,0]))

sc.doc = ghdoc

However, when I press the
Bake button, I always get two curves…

Still trying to figure out how to add the color attribs directly instead of going through rs.ObjectColor()

Here’s a pure RhinoCommon solution using the method documented here:

210429_BakeWithColor_RhinoCommon_GHpython.gh (4.3 KB)

3 Likes

Was making the same in c# …

private void RunScript(GeometryBase G, ref object A)
  {
    Rhino.DocObjects.ObjectAttributes att = new Rhino.DocObjects.ObjectAttributes();
    att.ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject;
    att.ObjectColor = System.Drawing.Color.Aquamarine;
    this.RhinoDocument.Objects.Add(G, att);
  }
1 Like

Yep, just got to that myself, thanks!! I am still getting TWO objects when I press the bake button though…

Does the button fire once when pressed and again when released?

It does expire the component twice yes (on push down and release), but the script within the Bake scope should only run once (i.e while Bake is True). Which the definition I just posted above does on my system:

2 Likes

Oh, yeah, that was dumb, while testing I took out the if Bake… :upside_down_face:
:+1:

1 Like

Thanks to all who helped, got it working nicely now!! Cheers!

Interesting knock-on effect of this, I thought I would be smart and combine the baking of 3 sets of curve objects in 3 different colors in one component…

Looked fine at first until I started setting a file up to cut - then I suddenly noticed I was getting unexpected dupes on some items. Then it dawned on me - when different sets of curves have different quantities (list length) the bake procedure will run as many times as the longest list - resulting in multiple dupes of the last item in the shorter lists.

Not such a smart idea after all… (dope slap). I’m sure there might be a fancy workaround with some tree helpers here, but for now I’m back to one python bake component per list of curves/color.

BadBakeExample2.gh (11.3 KB)