示例#1
0
def mayaInit(forversion=None) :
    """ Try to init Maya standalone module, use when running pymel from an external Python inerpreter,
    it is possible to pass the desired Maya version number to define which Maya to initialize


    Part of the complexity of initializing maya in standalone mode is that maya does not populate os.environ when
    parsing Maya.env.  If we initialize normally, the env's are available via maya (via the shell), but not in python
    via os.environ.

    Note: the following example assumes that MAYA_SCRIPT_PATH is not set in your shell environment prior to launching
    python or mayapy.

    >>> import maya.standalone            #doctest: +SKIP
    >>> maya.standalone.initialize()      #doctest: +SKIP
    >>> import maya.mel as mm             #doctest: +SKIP
    >>> print mm.eval("getenv MAYA_SCRIPT_PATH")    #doctest: +SKIP
    /Network/Servers/sv-user.luma-pictures.com/luma .....
    >>> import os                         #doctest: +SKIP
    >>> 'MAYA_SCRIPT_PATH' in os.environ  #doctest: +SKIP
    False

    The solution lies in `refreshEnviron`, which copies the environment from the shell to os.environ after maya.standalone
    initializes.

    :rtype: bool
    :return: returns True if maya.cmds required initializing ( in other words, we are in a standalone python interpreter )

    """
    setupFormatting()

    global isInitializing

    # test that Maya actually is loaded and that commands have been initialized,for the requested version

    aboutExists = False
    try :
        from maya.cmds import about
        aboutExists = True
    except ImportError:
        pass
    
    if aboutExists and mayaStartupHasStarted():        
        # if this succeeded, we're initialized
        isInitializing = False
        return False

    _logger.debug( "startup.initialize running" )
    # for use with pymel compatible maya package
    os.environ['MAYA_SKIP_USERSETUP_PY'] = 'on'

    if not aboutExists and not sys.modules.has_key('maya.standalone'):
        try :
            import maya.standalone #@UnresolvedImport
            maya.standalone.initialize(name="python")

            if versions.current() < versions.v2009:
                refreshEnviron()
                
        except ImportError, e:
            raise e, str(e) + ": pymel was unable to intialize maya.standalone"
示例#2
0
def mayaInit(forversion=None):
    """ Try to init Maya standalone module, use when running pymel from an external Python inerpreter,
    it is possible to pass the desired Maya version number to define which Maya to initialize


    Part of the complexity of initializing maya in standalone mode is that maya does not populate os.environ when
    parsing Maya.env.  If we initialize normally, the env's are available via maya (via the shell), but not in python
    via os.environ.

    Note: the following example assumes that MAYA_SCRIPT_PATH is not set in your shell environment prior to launching
    python or mayapy.

    >>> import maya.standalone            #doctest: +SKIP
    >>> maya.standalone.initialize()      #doctest: +SKIP
    >>> import maya.mel as mm             #doctest: +SKIP
    >>> print mm.eval("getenv MAYA_SCRIPT_PATH")    #doctest: +SKIP
    /Network/Servers/sv-user.luma-pictures.com/luma .....
    >>> import os                         #doctest: +SKIP
    >>> 'MAYA_SCRIPT_PATH' in os.environ  #doctest: +SKIP
    False

    The solution lies in `refreshEnviron`, which copies the environment from the shell to os.environ after maya.standalone
    initializes.

    :rtype: bool
    :return: returns True if maya.cmds required initializing ( in other words, we are in a standalone python interpreter )

    """
    setupFormatting()

    global isInitializing

    # test that Maya actually is loaded and that commands have been initialized,for the requested version

    aboutExists = False
    try:
        from maya.cmds import about
        aboutExists = True
    except ImportError:
        pass

    if aboutExists and mayaStartupHasStarted():
        # if this succeeded, we're initialized
        isInitializing = False
        return False

    _logger.debug("startup.mayaInit running")
    # for use with pymel compatible maya package
    os.environ['MAYA_SKIP_USERSETUP_PY'] = 'on'

    if not aboutExists and not sys.modules.has_key('maya.standalone'):
        try:
            import maya.standalone  #@UnresolvedImport
            maya.standalone.initialize(name="python")

            if versions.current() < versions.v2009:
                refreshEnviron()

        except ImportError, e:
            raise e, str(e) + ": pymel was unable to intialize maya.standalone"
示例#3
0
                cmd = '/usr/bin/env'
            else:
                cmd = 'set'
                
            cmdOutput = shellOutput(cmd)
            #print "ENV", cmdOutput
            # use splitlines rather than split('\n') for better handling of different
            # newline characters on various os's
            for line in cmdOutput.splitlines():
                # need the check for '=' in line b/c on windows (and perhaps on other systems? orenouard?), an extra empty line may be appended
                if '=' in line:
                    var, val = line.split('=', 1)  # split at most once, so that lines such as 'smiley==)' will work
                    if not var.startswith('_') and var not in exclude: 
                            os.environ[var] = val 
    
    refreshEnviron()

    import PMP.mayaUtils
    import PMP.maya.fileUtils
    from PMP.maya import hw

    for path in (r"C:\Program Files\Autodesk\MayaBonusTools%d\python"  % PMP.mayaUtils.getMayaVersion(),
                 r"C:\MayaBonusTools%d\python" % PMP.mayaUtils.getMayaVersion(),
                 os.path.join(os.environ["OMTOOLBOX"], "pyScripts"),
                 os.path.join(os.environ["PAUL_SCRIPTS"], "pyScripts"),
                 os.path.join(os.environ["PAUL_C_DRIVE"],
                     *r"Dev\eclipse\plugins\org.python.pydev.debug_1.4.5.2727\pysrc".split('\\'))
                 ):
        try:
            addToPath(path)
        except Exception: