Unfortunately, there are still a bunch of places in maya that only
take MEL (and not python) - expressions being a big culprit.
My general approach when I have to do stick in some mel code into a
python script is to have the mel call a python function, instead of
putting in a mel literal string.
ie, instead of:
Method 1 - Raw String:
=================
melCommand = r'''
$someVal = $someOtherVal
'''
I might do:
Method 2 - Call python function:
=======================
melCommand = r'''python("import myCommand;myCommand.go()")'''
However, expressions are actually their own language, similar but
somewhat different from mel... and I seem to recall that last time I
tried to mix python and expressions, there were some additional
complications... something to do with imports, I think? So, trying to
do Method 2 may end up being more trouble than it's worth, especially
if it's a very simple expression.
If you want to use a mel string, but need to dynamically change it,
you'll have to fall back on string formatting operations, I'm afraid.
Ie:
expressionCommand = r'''
spriteScaleXPP=rand(%f,%f);
spriteScaleYPP=spriteScaleXPP;
spriteSpin=rand(%f);
spriteTwistPP=rand(%f,%f);''' % (scaleMin, scaleMax, spinMax,
twistMin, twistMax)
(Look up Section "3.6.2 String Formatting" in the python help for details.)
Note that, for readability, using the r (for a raw string literal),
and triple quoting it can help a lot (see section "2.4.1 String
Literals" in the python help for details).
Finally, as regards your outlinerEditor problem - maya GUI callback
CAN generally run python code, but there's some weird issues to work
around. For details, see this topic:
http://groups.google.com/group/python_inside_maya/browse_thread/thread/4fe55cd54ebb822/7fffe668f7b814e1?lnk=gst&q=gui+callback#7fffe668f7b814e1
...and look for Ofer Koren's post, which actually quotes the pymel docs.
Good luck!
- Paul