How to color an object in sketchup script

in sketchup pro i create an block with ruby script … but how do i gif that block with ruby script an color…?

“block” is not a SketchUp term, so I’m not sure exactly what Entity class you are working with, but anyway to assign a color to an Entity you create a new Sketchup:Material and assign it using the Entity’s #material= method. So, for instance, if f refers to a Face,

m=Sketchup.active_model.materials.add "my_mat"
m.color = "red" # or any other way of describing a color such as an rgb array

Edit: in my specific example note that Faces have two materials in general, a front and a back material. The Face#material= method sets the front surface material. Also, obviously, you need to have a shaded style else the color won’t show.

Edit#2: As @TIG showed, there are various pre-defined pure-color Materials that you can use by simply referring to their name vs actually adding a new Material as I did. But you would need to add a Material to get a texture rather than a pure color.

If your ‘block’ is a ‘face’ then you use:

face.material='red' # i.e. it makes it 'red'

Or if you have a loaded material named ‘MyMaterial’ use:


if there are a number of faces saved as an array, then iterate through them thus:

faces.each{|face| face.material='blue' }

If your ‘block’ is a group or a component-instance [containing the faces]. then you can apply a material to the ‘container’ - rather than its faces - thus:

block.material='green' #etc

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.