Example #1
0
def initMEL():
    if 'PYMEL_SKIP_MEL_INIT' in os.environ or pymel_options.get('skip_mel_init', False):
        _logger.info("Skipping MEL initialization")
        return

    _logger.debug("initMEL")
    mayaVersion = versions.installName()
    prefsDir = getUserPrefsDir()
    if prefsDir is None:
        _logger.error("could not initialize user preferences: MAYA_APP_DIR not set")
    elif not os.path.isdir(prefsDir):
        _logger.error("could not initialize user preferences: %s does not exist" % prefsDir)

    # TODO : use cmds.internalVar to get paths
    # got this startup sequence from autodesk support
    startup = [
        #'defaultRunTimeCommands.mel',  # sourced automatically
        # os.path.join( prefsDir, 'userRunTimeCommands.mel'), # sourced automatically
        'createPreferencesOptVars.mel',
        'createGlobalOptVars.mel',
        os.path.join(prefsDir, 'userPrefs.mel') if prefsDir else None,
        'initialStartup.mel',
        #$HOME/Documents/maya/projects/default/workspace.mel
        'initialPlugins.mel',
        #'initialGUI.mel', #GUI
        #'initialLayout.mel', #GUI
        # os.path.join( prefsDir, 'windowPrefs.mel'), #GUI
        # os.path.join( prefsDir, 'menuSetPrefs.mel'), #GUI
        #'hotkeySetup.mel', #GUI
        'namedCommandSetup.mel',
        os.path.join(prefsDir, 'userNamedCommands.mel') if prefsDir else None,
        #'initAfter.mel', #GUI
        os.path.join(prefsDir, 'pluginPrefs.mel') if prefsDir else None
    ]
    if pymel_options.get('skip_initial_plugins', False):
        # initialPlugins.mel is not sourced when running maya -batch, but has been included
        # in the pymel startup sequence since time immemorial. see pymel.conf for more info
        _logger.info("Skipping loading Initial Plugins")
        startup.remove('initialPlugins.mel')

    try:
        for f in startup:
            _logger.debug("running: %s" % f)
            if f is not None:
                if os.path.isabs(f) and not os.path.exists(f):
                    _logger.warning("Maya startup file %s does not exist" % f)
                else:
                    # need to encode backslashes (used for windows paths)
                    if isinstance(f, unicode):
                        encoding = 'unicode_escape'
                    else:
                        encoding = 'string_escape'
                    #import pymel.core.language as lang
                    #lang.mel.source( f.encode(encoding)  )

                    import maya.mel
                    maya.mel.eval('source "%s"' % f.encode(encoding))

    except Exception, e:
        _logger.error("could not perform Maya initialization sequence: failed on %s: %s" % (f, e))
Example #2
0
def initMEL():
    if 'PYMEL_SKIP_MEL_INIT' in os.environ or pymel_options.get('skip_mel_init', False):
        _logger.info("Skipping MEL initialization")
        return

    _logger.debug("initMEL")
    mayaVersion = versions.installName()
    prefsDir = getUserPrefsDir()
    if prefsDir is None:
        _logger.error("could not initialize user preferences: MAYA_APP_DIR not set")
    elif not os.path.isdir(prefsDir):
        _logger.error("could not initialize user preferences: %s does not exist" % prefsDir)

    # TODO : use cmds.internalVar to get paths
    # got this startup sequence from autodesk support
    startup = [
        #'defaultRunTimeCommands.mel',  # sourced automatically
        # os.path.join( prefsDir, 'userRunTimeCommands.mel'), # sourced automatically
        'createPreferencesOptVars.mel',
        'createGlobalOptVars.mel',
        os.path.join(prefsDir, 'userPrefs.mel') if prefsDir else None,
        'initialStartup.mel',
        #$HOME/Documents/maya/projects/default/workspace.mel
        'initialPlugins.mel',
        #'initialGUI.mel', #GUI
        #'initialLayout.mel', #GUI
        # os.path.join( prefsDir, 'windowPrefs.mel'), #GUI
        # os.path.join( prefsDir, 'menuSetPrefs.mel'), #GUI
        #'hotkeySetup.mel', #GUI
        'namedCommandSetup.mel',
        os.path.join(prefsDir, 'userNamedCommands.mel') if prefsDir else None,
        #'initAfter.mel', #GUI
        os.path.join(prefsDir, 'pluginPrefs.mel') if prefsDir else None
    ]
    if pymel_options.get('skip_initial_plugins', False):
        # initialPlugins.mel is not sourced when running maya -batch, but has been included
        # in the pymel startup sequence since time immemorial. see pymel.conf for more info
        _logger.info("Skipping loading Initial Plugins")
        startup.remove('initialPlugins.mel')

    try:
        for f in startup:
            _logger.debug("running: %s" % f)
            if f is not None:
                if os.path.isabs(f) and not os.path.exists(f):
                    _logger.warning("Maya startup file %s does not exist" % f)
                else:
                    # need to encode backslashes (used for windows paths)
                    if isinstance(f, unicode):
                        encoding = 'unicode_escape'
                    else:
                        encoding = 'string_escape'
                    #import pymel.core.language as lang
                    #lang.mel.source( f.encode(encoding)  )

                    import maya.mel
                    maya.mel.eval('source "%s"' % f.encode(encoding))

    except Exception, e:
        _logger.error("could not perform Maya initialization sequence: failed on %s: %s" % (f, e))
Example #3
0
def initMEL():
    if 'PYMEL_SKIP_MEL_INIT' in os.environ or pymel_options.get('skip_mel_init', False):
        _logger.info("Skipping MEL initialization")
        return

    _logger.debug("initMEL")
    mayaVersion = versions.installName()
    prefsDir = getUserPrefsDir()
    if prefsDir is None:
        _logger.error("could not initialize user preferences: MAYA_APP_DIR not set")
    elif not os.path.isdir(prefsDir):
        _logger.error("could not initialize user preferences: %s does not exist" % prefsDir)

    # TODO : use cmds.internalVar to get paths
    # got this startup sequence from autodesk support
    startup = [
        #'defaultRunTimeCommands.mel',  # sourced automatically
        # os.path.join( prefsDir, 'userRunTimeCommands.mel'), # sourced automatically
        'createPreferencesOptVars.mel',
        'createGlobalOptVars.mel',
        os.path.join(prefsDir, 'userPrefs.mel') if prefsDir else None,
        'initialStartup.mel',
        #$HOME/Documents/maya/projects/default/workspace.mel
        'initialPlugins.mel',
        #'initialGUI.mel', #GUI
        #'initialLayout.mel', #GUI
        # os.path.join( prefsDir, 'windowPrefs.mel'), #GUI
        # os.path.join( prefsDir, 'menuSetPrefs.mel'), #GUI
        #'hotkeySetup.mel', #GUI
        'namedCommandSetup.mel',
        os.path.join(prefsDir, 'userNamedCommands.mel') if prefsDir else None,
        #'initAfter.mel', #GUI
        os.path.join(prefsDir, 'pluginPrefs.mel') if prefsDir else None
    ]
    if pymel_options.get('skip_initial_plugins', False):
        # initialPlugins.mel is not sourced when running maya -batch, but has been included
        # in the pymel startup sequence since time immemorial. see pymel.conf for more info
        _logger.info("Skipping loading Initial Plugins")
        startup.remove('initialPlugins.mel')

    import maya.mel

    callbacks = om.MCallbackIdArray()
    toDelete = []

    # initialStartup.mel will run a `file -f -new`.  This is dangerous, for
    # obvoius resons, so we disable all file news while we run these...
    def rejectNewCallback(boolPtr_retCode, clientData):
        om.MScriptUtil.setBool(boolPtr_retCode, False)

    callbacks.append(om.MSceneMessage.addCheckCallback(
        om.MSceneMessage.kBeforeNewCheck, rejectNewCallback))

    try:
        # additionally, userPrefs.mel will apparently create a bunch of ikSolver
        # nodes (apparently just to set some global ik prefs?)
        # make sure we clean those up...
        def logIkSolverCreation(nodeObj, clientData):
            toDelete.append(om.MObjectHandle(nodeObj))

        callbacks.append(om.MDGMessage.addNodeAddedCallback(
            logIkSolverCreation, "ikSolver"))

        for f in startup:
            _logger.debug("running: %s" % f)
            if f is not None:
                if os.path.isabs(f) and not os.path.exists(f):
                    _logger.warning("Maya startup file %s does not exist" % f)
                else:
                    if PY2:
                        # need to encode backslashes (used for windows paths)
                        if isinstance(f, unicode):
                            encoding = 'unicode_escape'
                        else:
                            encoding = 'string_escape'
                        f = f.encode(encoding)
                    else:
                        # encoding to unicode_escape should add escape
                        # sequences, but also make sure everything is in basic
                        # ascii - so if we decode utf-8 (or ascii), it should
                        # give us a string which is escaped
                        f = f.encode('unicode_escape').decode('utf-8')
                    maya.mel.eval('source "%s"' % f)

    except Exception as e:
        _logger.error("could not perform Maya initialization sequence: failed "
                      "on %s: %s" % (f, e))
    finally:
        om.MMessage.removeCallbacks(callbacks)

        # clean up the created ik solvers
        dgMod = om.MDGModifier()
        for objHandle in toDelete:
            if objHandle.isValid():
                dgMod.deleteNode(objHandle.object())
        dgMod.doIt()

    try:
        # make sure it exists
        res = maya.mel.eval('whatIs "userSetup.mel"')
        if res != 'Unknown':
            maya.mel.eval('source "userSetup.mel"')
    except RuntimeError:
        pass

    _logger.debug("done running mel files")