String literals with maya.eval in python

91 views
Skip to first unread message

Jeremy YeoKhoo

unread,
Jun 12, 2014, 3:06:27 AM6/12/14
to python_in...@googlegroups.com
Hey guys, I am having string literal issues with my following piece of code. 

mel.eval('runTimeCommand -annotation "Herrow" -category "User" -commandLanguage "python" -command ("from tools.anim import picker\nreload(picker)") customCmd;')    

I am having escaping with the parentheses, I think. Could someone throw me a line please :)

Thanks
-Jeremy


ha...@haggi.de

unread,
Jun 12, 2014, 3:53:33 AM6/12/14
to python_in...@googlegroups.com

-You could try:

"from tools.anim import picker;reload(picker)"

haggi

--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/3207324d-fcee-408c-95e3-d94f39443b7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

 

 

Jeremy YeoKhoo

unread,
Jun 12, 2014, 5:15:13 AM6/12/14
to python_in...@googlegroups.com
er no that didnt work

Justin Israel

unread,
Jun 12, 2014, 6:52:44 AM6/12/14
to python_in...@googlegroups.com
This seems to work fine:
mel.eval('runTimeCommand -annotation "Herrow" -category "User" -commandLanguage "python" -command "from tools.anim import picker; reload(picker)" customCmd2;')
And so does the python commands equivalent
cmds.runTimeCommand("customCmd", annotation="Herrow", category="User", commandLanguage="python", command="from tools.anim import picker; reload(picker)")
You don't need the outer parenthesis around the command string. And using the semi-colon instead of the newline works. The python equiv is a bit easier to manage though.

Also sometimes if you find yourself dealing with complicated nested quotations (not really the case here, but releated), it can help to use triple quotes:
complexString = '''some code that contains both "double quotes" and 'single quotes' all in one'''
And using the repr string formatting for combining snippets with quotes and other snippets with quotes:

complexString = '''some code that contains both "double quotes" and 'single quotes' and also %r'''
print complexString % complexString
-- justin



--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.

Jeremy YeoKhoo

unread,
Jun 12, 2014, 7:34:30 PM6/12/14
to python_in...@googlegroups.com
I left out a snippet of code in my command, so Haggi was right, my bad... 

In my code I was trying to parse in a string in my command arg for runTimeCommand such as:

picker
.control("mySel")

so in respect to mel I was trying to use the escape characters for the double quotes

-c "picker.control(\"mySel\")"

Needless to say that didn't work either, but I took Justin's advice rewrote the command as 

mel.eval('''runTimeCommand -ann "Herrow" -cat "User" -cl "python" -c "from tools.anim import picker;reload(picker);picker('mySel')" customCmd;''')    

Realising that mel probably doesnt see the single quotes and python does.

So for now, that works

Cool thanks guys
-Jeremy


On Thursday, 12 June 2014 17:06:27 UTC+10, Jeremy YeoKhoo wrote:
Reply all
Reply to author
Forward
0 new messages