Multi-Line 3D text

I can’t seem to find any threads on this topic but it may have been answered before.

I’m trying to figure out if there is way to generate multi-line 3D text with the API.

Can I insert a newline character or some other special character that will cause the API to create multiple lines of text?

\n

image

def test_text(text)
  entities = Sketchup.active_model.entities
  entities.add_3d_text(text, TextAlignLeft, "Arial")
end
test_text( "my\ntest")
3 Likes

BTW
It is important to use " double quotes to define the string, otherwise :

image

3 Likes

Thank-you, this is very exciting, I didn’t realize I could do multi-lines with the 3D text.

3 Likes

This can be fixed inside the method …

def test_text(text)
  entities = Sketchup.active_model.active_entities
  text.gsub!('\n',"\n")
  entities.add_3d_text(text, TextAlignLeft, "Arial")
end
3 Likes

On a related note does anyone know what the actual integer values are for the constants:

TextAlignLeft

TextAlignRight

TextAlignCenter

I can’t seem to find this anywhere in the documentation.

Sketchup defines these constants at the top level NameSpace

You can simply type the name into the Ruby Console to retrieve the value.
TextAlignLeft = 0
TextAlignCenter = 1
TextAlignRight = 2

Or , in any Module you can look up the value of a single constant with the const_get() method using name of the constant as a Symbol.

Object.const_get(:TextAlignCenter)

or dump the gamut

Object.constants.sort.each { | const |
  puts "#{const} = #{ Object.const_get(const) }"
}
nil

Object being the default root of all Ruby objects.

2 Likes

Tomtom has produced a plugin that allows the insertion of editable multiline 3D text.

1 Like