How to random color a Component?


I wanna apply random colors to all Components in the Scene (all faces of the Component should have the same random color).
I searched in the forum and in the API but I didn’t found anything I understand.

Isn’t there something like "… entity.material = ‘color’ " ?

If ‘entity’ is a reference to your ComponentInstance then entity.material='color' will work, but only if the material of that name ‘color’ existing in the model or ‘color’ is one of the named colors.
Try it out manually…
Select the ComponentInstance and use this snippet


A new material named ‘Red’ will be added to the model if it doesn’t already exist…
You can of course get the reference to the ComponentInstance in several ways…
The list of ‘built-in’ colors is here:

This code will generate an array of all available colors by name…

array = Sketchup::Color.names

There are 140 listed color-names, so using something like


would use a random one of those color-names…


Thanks alot TIG, this is something my little brain understands :slight_smile: