Python 2.7.11 (default, Dec 21 2015, 22:48:54) [MSC v.1700 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os >>> os.environ = {} >>> >>> from maya import standalone >>> standalone.initialize() Error: local variable 'commandListPath' referenced before assignment # Traceback (most recent call last): # File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-packages\maya\app\startup\batch.py", line 5, in <module> # import maya.app.startup.basic # File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-packages\maya\app\startup\basic.py", line 76, in <module> # maya.app.commands.processCommandList() # File "C:\Program Files\Autodesk\Maya2017\Python\lib\site-packages\maya\app\commands.py", line 43, in processCommandList # sys.stderr.write("Unable to process commandList %s" % commandListPath) # UnboundLocalError: local variable 'commandListPath' referenced before assignment
Python 2.7.11 (default, Dec 21 2015, 22:48:54) [MSC v.1700 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from maya import standalone >>> standalone.initialize() Error: No module named startup.batch # ImportError: No module named startup.batch >>>
""" This module is always imported during Maya's startup. It is imported from both the maya.app.startup.batch and maya.app.startup.gui scripts """ import atexit import os.path import sys import traceback import maya import maya.app import maya.app.commands from maya import cmds, utils
defsetupScriptPaths(): """ Add Maya-specific directories to sys.path """ # Extra libraries # try: # Tkinter libraries are included in the zip, add that subfolder p = [p for p in sys.path if p.endswith('.zip')][0] sys.path.append( os.path.join(p,'lib-tk') ) except: pass # Per-version prefs scripts dir (eg .../maya8.5/prefs/scripts) # prefsDir = cmds.internalVar( userPrefDir=True ) sys.path.append( os.path.join( prefsDir, 'scripts' ) ) # Per-version scripts dir (eg .../maya8.5/scripts) # scriptDir = cmds.internalVar( userScriptDir=True ) sys.path.append( os.path.dirname(scriptDir) ) # User application dir (eg .../maya/scripts) # appDir = cmds.internalVar( userAppDir=True ) sys.path.append( os.path.join( appDir, 'scripts' ) ) defexecuteUserSetup(): """ Look for userSetup.py in the search path and execute it in the "__main__" namespace """ ifnot os.environ.has_key('MAYA_SKIP_USERSETUP_PY'): try: for path in sys.path[:]: scriptPath = os.path.join( path, 'userSetup.py' ) if os.path.isfile( scriptPath ): import __main__ execfile( scriptPath, __main__.__dict__ ) except Exception, err: # err contains the stack of everything leading to execfile, # while sys.exc_info returns the stack of everything after execfile try: # extract the stack trace for the current exception etype, value, tb = sys.exc_info() tbStack = traceback.extract_tb(tb) finally: del tb # see warning in sys.exc_type docs for why this is deleted here sys.stderr.write("Failed to execute userSetup.py\n") sys.stderr.write("Traceback (most recent call last):\n") # format the traceback, excluding our current level result = traceback.format_list( tbStack[1:] ) + traceback.format_exception_only(etype, value) sys.stderr.write(''.join(result))
# Set up sys.path to include Maya-specific user script directories. setupScriptPaths()
# Set up string table instance for application maya.stringTable = utils.StringTable()
# Set up auto-load stubs for Maya commands implemented in libraries which are not yet loaded maya.app.commands.processCommandList()
# Set up the maya logger before userSetup.py runs, so that any custom scripts that # use the logger will have it available utils.shellLogHandler()
# Register code to be run on exit atexit.register( maya.app.finalize )
# Locations of commandList file by OS type as returned by maya.cmds.about( os=True ) commandListLocations = { 'nt' : 'bin', 'win64' : 'bin', 'mac' : 'Resources', 'linux' : 'lib', 'linux64' : 'lib' }
def__makeStubFunc( command, library ): defstubFunc( *args, **keywords ): """ Dynamic library stub function """ maya.cmds.dynamicLoad( library ) # call the real function which has replaced us return maya.cmds.__dict__[command]( *args, **keywords ) return stubFunc
defprocessCommandList(): """ Process the "commandList" file that contains the mappings between command names and the libraries in which they are found. This function will install stub functions in maya.cmds for all commands that are not yet loaded. The stub functions will load the required library and then execute the command. """
try: # Assume that maya.cmds.about and maya.cmds.internalVar are already registered # commandListPath = os.path.realpath( os.environ[ 'MAYA_LOCATION' ] ) platform = maya.cmds.about( os=True ) commandListPath = os.path.join( commandListPath, commandListLocations[platform], 'commandList' )
file = open( commandListPath, 'r' ) for line in file: commandName, library = line.split() ifnot commandName in maya.cmds.__dict__: maya.cmds.__dict__[commandName] = __makeStubFunc( commandName, library ) except: sys.stderr.write("Unable to process commandList %s" % commandListPath) raise