Face changes color

Hi everyone!
I have a problem with face coloring. Here is code for example

mod = Sketchup.active_model # Open model
ent = mod.entities # All entities in model
sel = mod.selection # Current selection
ent.clear!
#wall
f0 = []
f0[0] = [26.074643, -28.518705, 0.000000]
f0[1] = [26.074643, -51.189309, 0.000000]
f0[2] = [26.074643, -51.189309, 9.842520]
f0[3] = [26.074643, -28.518705, 9.842520]
face0 = ent.add_face(f0)
cfn0 = Sketchup::Color.new "Yellow"
cfn0.alpha = 10
face0.material = cfn0
face0.back_material = cfn0
#hole 1
f0in1 = []
f0in1[0] = [26.074643, -31.118771, 7.004593]
f0in1[1] = [26.074643, -34.120739, 7.004593]
f0in1[2] = [26.074643, -34.120739, 1.000656]
f0in1[3] = [26.074643, -31.118771, 1.000656]
face0in1 = ent.add_face(f0in1)
ent.erase_entities(face0in1)
#hole 2
f0in2 = []
f0in2[0] = [26.074643, -35.219820, 7.004593]
f0in2[1] = [26.074643, -38.221789, 7.004593]
f0in2[2] = [26.074643, -38.221789, 1.000656]
f0in2[3] = [26.074643, -35.219820, 1.000656]
face0in2 = ent.add_face(f0in2)
ent.erase_entities(face0in2)
#hole 3
f0in3 = []
f0in3[0] = [26.074643, -39.320870, 7.004593]
f0in3[1] = [26.074643, -42.322839, 7.004593]
f0in3[2] = [26.074643, -42.322839, 1.000656]
f0in3[3] = [26.074643, -39.320870, 1.000656]
face0in3 = ent.add_face(f0in3)
ent.erase_entities(face0in3)
#red frame
f1 = []
f1[0] = [26.074643, -34.058239, 6.942093]
f1[1] = [26.074643, -31.181271, 6.942093]
f1[2] = [26.074643, -31.181271, 1.063156]
f1[3] = [26.074643, -30.889276, 1.063156]
f1[4] = [26.074643, -30.889276, 7.234088]
f1[5] = [26.074643, -34.350234, 7.234088]
f1[6] = [26.074643, -34.350234, 1.063156]
f1[7] = [26.074643, -34.058239, 1.063156]
face1 = ent.add_face(f1)
cfn1 = Sketchup::Color.new "Red"
cfn1.alpha = 10
face1.material = cfn1
face1.back_material = cfn1
#inner green frame
f2 = []
f2[0] = [26.074643, -31.118771, 7.004593]
f2[1] = [26.074643, -31.118771, 1.000656]
f2[2] = [26.074643, -34.120739, 1.000656]
f2[3] = [26.074643, -34.120739, 7.004593]
face2 = ent.add_face(f2)
cfn2 = Sketchup::Color.new "Green"
cfn2.alpha = 10
face2.material = cfn2
face2.back_material = cfn2
#window hole
f2in = []
f2in[0] = [26.074643, -31.181271, 6.942093]
f2in[1] = [26.074643, -34.058239, 6.942093]
f2in[2] = [26.074643, -34.058239, 1.063156]
f2in[3] = [26.074643, -31.181271, 1.063156]

face2in = ent.add_face(f2in)
ent.erase_entities(face2in)

As you can see from the code first face is colored in yellow. But after all operations it starts to be colored in green, as last face with a hole. (picture is added)

What is the problem? Has everyone had already this problem?

Thanks, for your answers!

Firstly, you are setting up materials in an odd way, they are not displaying properly [transparency]

face0 = ent.add_face(f0)
cfn0 = Sketchup::Color.new "Yellow"
cfn0.alpha = 10
face0.material = cfn0
face0.back_material = cfn0

would be better and work as

face0 = ent.add_face(f0)
face0.material = "Yellow"
mat0 = face0.material
face0.back_material = mat0
mat0.alpha = 0.1

Then the alpha works etc…

However, this doesn’t fix your issue…
I suspect that the rectangles you are adding within the red frame are overlapping, thereby the face you add is splitting and the deletions produce odd results.
The image shows it with the erase disabled.
The yellow faces survive
.Check your code and make the rectangles correctly with no overlapping…

Thank you for your answer!
But I’m getting this coordinates from file, so I can’t solve this overlapping issue.

I’ve had very similar issue where I was constrained to points given to me from a file. I’d consider making the windows cutting components that way you don’t have to worry about overlapping the wall with the window trim.

EDIT: However creating cutting components would add some additional hurdles as well. Food for thought

Thanks gnebster and TIG for your answers!
I solve this problem by adding groups for each separate geometry object (walls, windows etc)

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