Creating TextObjects with quotes and whitespaces

Hi,

I am using python script and having problem creating a text object (using Rhino.Command(-TextObject….) as to my knowledge there is not python command which can create a text object) where the text contains quotes and spaces.

To give some context:
I have a rectangular bar which I would like to carve text out of. I do this by creating a text object and perform a boolean difference between the two objects. In many cases this works fine however with text which contains whitespaces and double quotes e.g. 39o29’ 45.8”N 2o28’21.5”E the command breaks after the first double quote

I have tried doing this directly in Rhino command bar:
-TextObject "39o29’ 45.8”N 2o28’21.5”E”

I tried escaping the quotes:
-TextObject “39o29’ 45.8””N 2o28"’21.5”E”

but to no avail. How could I do this?

Thanks in advance
Alex

Why not like this -TextObject "39o29' 45.8N'' 2o28'21.5''E"

Only use straight quotes, use double straight quote at start and end, and duplicate single quotes instead of using a double quote internally.

Hi Alex,

You can use Menno’s method of enclosing your python strings with one type type of quotes, and then use the other type “inside” the string.

The other way is to use backslash character () to escape characters which follow after it (in your case that’s double quote)

someString = "39o29' 45.8\"N 2o28'21.5\"E"

This seems to work, if I understand correctly what you need …

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

rs.Command( '''-TextObject "39o29’ 45.8”N 2o28’21.5”E" 0,0,0''' )

HTH
Cheers

# -*- coding: utf-8 -*-
import rhinoscriptsyntax as rs

rs.Command( '-TextObject "39o29’ 45.8”N 2o28’21.5”E" 0,0,0' )

Well … no need for triple quotes.
Since there are no single quotes inside the string, single quotes around the command text are enough

1 Like

Good one Emilio, with utf-8 we can also directly use the degree sign:
’-TextObject “39°29’ 45.8”N 2°28’21.5”E” 0,0,0’

Hi Jess.
Actually I simply tried the script in EditPythonScript, and it complained that the coding was missing.
I remembered that Vittorio talked about inserting the coding statement to make a certain script run …

I think I had read something about the theory behind the utf coding … but I’ve already forgotten that …
Heh … growing old …
I think I’ll have to read about that again.
Thanks