Extrusion based on object color

Hi everyone,
When I extrude a profile section with different edge colors, the colors of the surfaces formed become gray after extrusion. However, what I want is for the colored parts to be extruded in color. I want to do this in rhino with editpythonscirpt. I’m looking for help.


do you have a sample input file? Do you have any code you have tried to write? sounds like a good use for python :+1:

hi, I have a grasshopper file. I did this using grasshopper, but ı want to do this with python.

Its not too hard, you just need to do some bookkeeping.
Without writing the code for you, you need to:

  1. Get the curves to be extruded and their object colors, keep them in parallel lists or a dictionary
  2. In a loop:
  • Extrude each curve individually
  • Get the object color from the curve and apply it to the result of the extrusion

thank you, I’m working on this idea, but when I make the extruded object a closed polysurface, there is a high probability that the generated colored surfaces can become a single color

Ah, you want to apply per-face colors… That’s more complicated and will need some RhinoCommon. Basically you are going to need to keep track of which curve (and color) needs to be applied to which face of the resulting polysurface. You could then apply the per-face color in RhinoCommon. The main problem is I don’t know if the order of the individual extruded faces in a list will be the same as the order of faces in the joined polysurface face list. I can try to create an example.

yeah that exactly what ı want. I am working on it but ı am new with rhınocommon so ı getting hard :slight_smile:

OK, this turned out to be a little easier than I thought, at least for my example - as it looks like you can attribute a per-face color to the individual extrusions before joining and that color is preserved after joining… (yay!)

import scriptcontext as sc
import rhinoscriptsyntax as rs
import Rhino

def TestPerFaceColorExtrusion():
    crv_ids=rs.GetObjects("Select curves to extrude",4,preselect=True)
    colors=[rs.ObjectColor(crv_id) for crv_id in crv_ids]
    crvs=[rs.coercecurve(crv_id) for crv_id in crv_ids]
    #for this test I just used a fixed extrusion vector
    for i,crv in enumerate(crvs):
        #apply the curve color as a per face color to the extrusion
    #join the surfaces
    #add the joined brep(s) to the document
    extru_ids=[sc.doc.Objects.AddBrep(brep) for brep in joined]
1 Like

You are a master man :pray:
How can I improve my Rhino scripting skills? What resources should I use? I am considering a career in this field.

Good question…

First, I guess read as much as you can here:

(particularly the 101 primer…)

and maybe here:

Then, feel free to post questions here on the forum.

I don’t see any offers for any online or in-person courses for scripting unfortunately - it seems mostly to be concentrated on Grasshopper these days.

1 Like

Hi -

After having gone through the guides that Mitch pointed out, you could go through posts in this “Scripting” category and check how specific things were solved. Then, when new posts are created in this category, try to solve them first and monitor responses. The best way to learn is often by trying to solve real cases…