Ruby: 2D text, how to fill?

Any suggestions, why does not the following change the fill color to black?

faces= ents2.each{|e|faces<<e if e.class==Sketchup::Face}
e.reverse! if e.normal.z<0 ### so faces up
e.erase! if filled==(db("No"))

The general idea of assigning a material and back_material to a face should work. So something else is wrong.

Unless faces was defined as an Array before the start of your snippet, the line

faces = ents2.each{|e| faces << e if e.class==Sketchup::Face}

will raise an error because faces is nil inside the .each iteration.

That said, it is more efficient to get faces using

faces = ents2.grep(Sketchup::Face)

the grep method returns an Array of all objects matching its argument.

Beyond that, there are various things that are not defined in the snippet you provided, so I can’t say whether or not they do what you want. ents2 comes from somewhere else. Are you certain it contains what you expect? I have no way to know what filled or (db(“No”) is.

You are cobbling together code snippets from something else…
For example…
Your array ents2 is NOT predefined in your example.
The line
e.erase! if filled==(db(“No”))
will not work because filled is not defined,
AND you are then using db(“No”) as a test, which is an old debabelizer [translation] method called from within some of my older plugins.

It’d not be too hard to recast it into your own working code - but you must understand what each steps does !

1 Like


The following did the trick:

model = Sketchup.active_model
ents = model.active_entities
group1 = ents.add_group
ents1 = group1.entities

ents1.add_3d_text("Hello world", 2, "Arial", false, false, 16.inch, 0.0, 0, true, 0)

faces = ents1.grep(Sketchup::Face)