A script to assign a random colour for selected items? [Keyshot export]


Hey guys, trying out the polyhedra plugin which would could create polyhedra with different colours. This comes very handy when quickly assigning materials in Keyshot.
So maybe you know some workaround for this:

  1. select several objects (surfaces, polysurfaces etc) and then assign a random colour which wouldn’t reoccur if select and assign other objects to kind of pre organize the scene before exporting to Keyshot. Would save a bunch of time. Hope you know something.

Thanks a lot and have relaxed Sunday evening to you all! Hannes

(Pascal Golay) #2

Hi Hannes -
Do you want a random color material, or display color (wireframe)?



@pascal my hero! I finally figured out what would be great approach:

  1. A script for a random material (because someone can evaluate the overall look within Rhino first)
  2. a script for selecting all parts with the same material ID so I could handle them better (e.g. select all objects with one material and then deselect some parts and reassign, or assign to a layer)

What do you think? What be awesome since I’m getting my hands deeply into contemporary Arabic designs and the included pattern designs. This would be a game changer within Rhino.

Within Keyshot you can even handle material assemblies with selecting same material

(Pascal Golay) #4

Hi Hannes - you can, to get at this part of the request, use SelMaterialName in Rhino.



Hi Hannes,

below is some very old rvb script which still seems to work in V5 (Windows only), since i do not have the time to rewrite it in python tonight. Note that by default it assigns colors to object (wireframe) color and material color. So be careful, eg. running it on 100 objects may create 100 different materials unless you disable the option “MaterialColor” in the command prompt.

There are various options, color gradients, brighten, darken, random color, random greyscale, reset color source …

ColorTools_RH3.rvb (12.3 KB)

it got this ugly icon in my workspace:

this is a result from the “RandomColor” option:

btw, @Helvetosaur also posted this a while ago.



Hmmm… This is really helpful. Keyshot clown passes often use very similar colours. Applying random colours to a multitude of objects before export is really helpful as another layer for masking.




Thanks will give it a try in the evening. Looking forward!!! Thanks a lot @clement
@pascal I’ve found this out but thought there is a special Alias I could bind to a script so I would fire SMA (SelectMaterial) while having a part selected and hence all parts with same material would get highlighted without trying all materials in default material name popup. would be super intuitive so. but maybe nobody who needs this except me :slight_smile:


@clement I gave it a try but it would only color all selected objects in a random color each.
What I originally wanted for keyshot is a quick and easy material or color organisation within Rhino for quick overview and further for export to Keyshot.

So it would be rather very straigtforward if there was

  1. a single solution/script for just selecting objects and fire a command to colour them all in a random material colour. toggling material and display colour as options would be nice but not necessary

  2. a solution/script to select one object and fire script and get all items selected with same MatColour

What do you think?

As you see all selected surfaces got a random colour each :frowning:

(Pascal Golay) #9

HI Hannes - You’re right, this command could be a lot more useful - more like SelColor behavior. I’ll look into it.




pascal maybe you could set the more important command/script higher in priority: to select different items and fire the ‘set random material colour’ command. highly appreciated! :slight_smile:


@hannesgrebin, below are some scripts to assign one random color value to selected objects. One script for object wireframe color and one for material color. Note that the material color script also assigns a material name, to get rid of this look at the annotatons in the script.

RandomObjectColor.py (557 Bytes)
RandomMaterialColor.py (912 Bytes)

To select objects with the same material color(s) as the selected object(s), you might try this:

SelectMaterialColor.py (874 Bytes)



@clement your are my hero of the month!!! Will try out tomorrow morning. Thank you so much these scripts. They are a game changer! Will post some videos soon. Lots of love & God bless you! Hannes