Set color for individual Door in SketchUp using Ruby

Hi All,

Please see the below image

I want to give color for each door, what i mentioned. Herewith, i have attached my code for your reference,

Please help me with this,

Thanks,
Siva S

You need references to the faces that you want to paint. When you create these faces, you need to keep the returned reference in a variable.

Then you assign a material object with the desired color object (see also for back material). If you have not such a material yet, you need to create one first, but SketchUp is also able to create it on the fly if you assign the name or hexcode of the color.

You should also maybe refactor your code so that it contains 0.020 and 0 only once, each as a variable that you use everywhere where it is currently repeated.

Hi @Aerilius thanks for your reply. Can you give me a reference codes for my reference?

Reference code, like door3.material = "blue"?

Yes, I am a beginner for sketchup. Can you give me some example codes like this?

Well, that is it already. A better alternative is:

blue_material = model.materials.add("blue")
blue_material .color = Sketchup::Color.new(0, 0, 255)
# ...
door3.material = blue_material

Here you do not have to repeat the string (repetitive strings are error-prone!) and can re-use the same material reference for more faces, and configure the marterial (texture, opacity).