"\" is getting deleted automatically


#1

I am trying to execute a script which contains this portion of code.

proxyName = instan + ‘_proxy’
mesh = locationFolder + “/” + nodeName
cmd2 = ‘vrayCreateProxyExisting( “{0}”, “{1}”,"{2}");’.format( proxyName, mesh ,"" )
mel.eval(cmd2)

If I print the mesh, it is showing properly the input path along with the file name.
But when I am executing the command, the path is getting changed automatically
from
“D:\jay/pSphereShape1.vrmesh”
to
“D:jay/pSphereShape1.vrmesh”

And so the script is getting stopped with a error message “Error: (“D:jay/pSphereShape1.vrmesh”) does not exist”

Why the “” is getting deleted automatically?


#2

In a string \ performs a function that depends on the character that follows it. For example
is the new-line character. Google “escape character”. If you want to keep a \ in a string you need to add an extra one in front of it, but each time the string is evaluated in some way it will lose one again.

In your example you may be better off just ensuring that the string only contains forward slashes instead.

mesh = locationFolder.replace(’\’, ‘/’) + “/” + nodeName

Notice how I even had to use 2 's here as well.

David


#3

Thanks djx.