Sometimes when I try to eval a string, I end up with a syntax error like this one:
// Error: python(“pixel_blocks.set_colors()”); python(“pixel_blocks.pixel_character(“InsectB”,”//Computer/Path/Generic/Computer/Path/Generic/Compu€ //
// Error: Line 1.82: Syntax error //
Anyone run into this? I seem to be getting it a lot lately. It’s python in Maya 2008 with PyMel… in order to use evalDeferred I had to run python commands through a mel command which is called through python. It’s real ugly, but I haven’t found a more elegant solution.
Oh and the python call looks like this:
maya.mel.eval(‘evalDeferred(“python(\“pixel_blocks.set_colors()\”); python(\“pixel_blocks.pixel_character(\”%s\”,\"%s\",%s,%s)\")");’%(charname,imgdir,numfiles,(cur_frame+1)))
What are the values of the variables you’re passing in? The error seems to be happening after those values are formatted to the string, during the eval.
BTW, you can chuck your python calls within a python comment block ‘’’ like so:
template = 'nameOfProc' # Dont have to do this via variable, but powerful
name = 'dbsmith'
myDirectory = 'C:/Temp'
maya.mel.eval(
'''
global proc string[] %(procName)s()
{
python("import MyAwesomeModule;");
return python("MyAwesomeModule.Method(%(name)s, %(myDir)s)");
}
''' % { 'procName':template, 'name':template, 'myDir':myDirectory }
)
This guy is probably doing more than you need to, e.g. creating a global mel method that calls a python import, but you get the idea…
You can use a one shot scriptJob that fires on the idle event if you want to keep it py(Mel)thon all the way down.
Thanks, guys. It turns out there was actually a character limit somewhere in there because I tried a few different things and it always cut off at 128 characters.
Annoying solution to an annoying problem was to stick the variables at the top of the python file putting them in the module space and setting them separately so they don’t need to be passed in during the eval.
Hi,
The python version of evalDeferred is maya.utils.executeDeferred().
From the docs:
(Similar to maya.utils.executeInMainThreadWithResult() except that it does not wait for the return value.) It delays the execution of the given script or function until Maya is idle. This function runs code using the idle event loop. This means that the main thread must become idle before this Python code is executed.
There are two different ways to call this function. The first is to supply a single string argument which contains the Python code to execute. In that case the code is interpreted. The second way to call this routine is to pass it a callable object. When that is the case, then the remaining regular arguments and keyword arguments are passed to the callable object.
def TempFunction(*args):
pixel_block s.set_colors()
pixel_blocks.pixel_character(charname,imgdir,numfiles,(c ur_frame+1))
maya.utils.executeDeferred(TempFunction)
Keir
Oh cool thanks. I guess I should check the docs more often.