View Full Version : Extreme syntax question
08-16-2012, 12:16 AM
I'm attempting to modify LevelTools by adding a right click option "Edit in new instance of Maya" command but I'm running into syntax errors galore.
This is what I have so far which works (but Maya doesn't open the file because I'm missing the filename and extension):
string $reference = ("system(\"start \\\"\" + getenv(\"MAYA_LOCATION\") + \"/bin/maya.exe\\\" \\\"\+$propFolder+\\\"\");");
I need to add this code (which generates filename.extension):
"\" + $name + "\" + $name
Anyone know where to start? :banghead:
When dealing with complex runtime-generated strings that you need to escape to infinity, it's probably most useful to break it up into little chunks and deal with those junks individually, then concatenate them in one final step at the end.
The most logic way of going about this would be to select chunks that form sub-strings inside your final string:
$sysCmd = "system($startCmd)"
$startCmd = "start $mayaPath $propFolder $fileName"
$mayaPath = getenv(MAYA_LOCATION)
$fileName = $name0 + $name1
Adding backslashes inside those smaller strings is alot simpler and easier to keep track of.
Once you have your strings, you can start using each sub-string inside its "parent", then do the same with the parent and the "grandparent".
Also, don't forget that Maya offers the encodeString command which will automatically create a string file with escaped backslashes etc. for you.
08-16-2012, 12:31 PM
Such an obvious, but elegant solution. THanks Nyro!
$mayaPath = `getenv "MAYA_LOCATION"`;
$filetoopen = ($propFolder + "/"+ $name + "." +$name);
$startCmd = ("start "+$mayaPath+"/bin/maya.exe "+$filetoopen+"");
menuItem -l "Edit in new instance of Maya" -c $reference;
Edit: Although Maya seems to open the new session without the viewport (panel bug) :D lol
08-16-2012, 12:31 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.