About Me

Thursday, August 18, 2011

Maya Command Completion issues in Python

Something Dave discovered a while ago and has just come back to bite us again is that the dot code completion in the scriptEditor in Maya is actually RUNNING the code inside Python property blocks when you call a dot complete (Ctrl+Space). It's not just returning the function/property list by using something like the inspect module, but actually running the property itself. The same is true when
you hit return to accept and fill that function/property in the script editor.

Test it, add this in a Python Script window:

import pymel.core as pCore

class AutoCompleteTest(object):

    def __init__(self):
        pass

    @property
    def Test(self):
        print "Im being CALLED Multiple times!!!!!\n" 
        pCore.newFile(force=True)


Now do the following:

com=AutoCompleteTest()

turn on ’Command Completion’ and do a dot complete to inspect the com object you just made!

The property is now being RUN. So what you ask? Well lets say you are doing something stupid like the fileNew example above, just by trying to get code completion you've actually nuked your scene. Also because it's doing this for all the inspect calls it means that it's running all code, in all property blocks which makes it very, very slow!

Mark