Hello,
I have this simple code to import some file to rhino, the path is correct
but “Program Files” have a space, this cause problems on comand
import, there is any way to sove this?
path = “C:\Program Files\data\teste\file.3dm”
commandline = “_-Import " + path + " _Enter”
ok = rs.Command(commandline)
thank you
dale
(Dale Fugier)
June 7, 2019, 4:56pm
2
Hi @MatrixRatrix ,
Try:
path = "C:\\Program Files\\data\\teste\\file.3dm"
path = "\"" + path + "\"" # Escape the double quotes
print path
– Dale
2 Likes
Hello Dale,
The problem is not //, the problem this the space between “Program” and “Files”, this space
cause path interruption.
“C:\Program.3dm not found, unable open”
Thanks
nathanletwory
(Nathan 'jesterKing' Letwory)
June 8, 2019, 10:58pm
4
Note the espaced double quotes in the sample from @dale . Those will ensure proper path.
OK, I was doing rong, is solve thank you.
hello!
i’ve got the same problem…
in this code:
path=rs.DocumentPath()
if in path, there is a space, it will interrupt the script, how can i do?
nathanletwory
(Nathan 'jesterKing' Letwory)
November 3, 2020, 2:41pm
7
Enclose the path in double quotes in the string.
onlyforpeace:
path=rs.DocumentPath()
This command return document path.
For me is working, even with spaces on path name.
nathanletwory
(Nathan 'jesterKing' Letwory)
November 3, 2020, 3:21pm
9
Sure you’ll get a path with spaces back. The point is to enclose it properly when using it as part of a macro.
path = rs.DocumentPath()
enclosed_path = "\"%s\"" % (path)
1 Like
Ok!! it is working!!!
but what does mean
"\"%s\"" %
nathanletwory
(Nathan 'jesterKing' Letwory)
November 3, 2020, 4:21pm
11
That is a string that contains two escaped double-quotes \"
and a format variable %s
. These are as string literal inside double-quotes → "\"%s\""
. The percentage that after this bit comes means “replace with what we get in parentheses next”. So the value of variable path
replaces the %s
in the formatted string. %s
means the value given should be a string.
Clearer would actually be:
enclosed_path = "\"{}\"".format(path)
The first I gave is so-called old-style formatting (https://docs.python.org/2/tutorial/inputoutput.html#old-string-formatting ), but you probably should go for the fancier new-style. Scroll up a bit in the page I linked for old-style formatting.
1 Like
tahirhan
(Tahirhan)
December 12, 2024, 8:14am
12
This is also works for Rhinocommon.