Пример #1
0
def setupDagProcMenu():
    '''
	sets up the modifications to the dagProcMenu script
	'''
    try:
        dagMenuScriptpath = findFirstInEnv('dagMenuProc.mel',
                                           'MAYA_SCRIPT_PATH')
    except:
        MGlobal.displayWarning(
            "Cannot find the dagMenuProc.mel script - aborting auto-override!")
        return

    tmpScriptpath = Path(
        cmd.internalVar(usd=True)) / 'zoo_dagMenuProc_override.mel'

    def writeZooLines(fStream, parentVarStr, objectVarStr):
        fStream.write('\n/// ZOO TOOLBOX MODS ########################\n')
        fStream.write('\tsetParent -m $parent;\n')
        fStream.write('\tmenuItem -d 1;\n')
        fStream.write('\tpython( "from zooPyMaya import triggeredUI" );\n')
        fStream.write(
            """\tint $killState = python( "triggeredUI.buildMenuItems( '"+ %s +"', '"+ %s +"' )" );\n"""
            % (parentVarStr, objectVarStr))
        fStream.write('\tif( $killState ) return;\n')
        fStream.write('/// END ZOO TOOLBOX MODS ####################\n\n')

    globalProcDefRex = re.compile(
        "^global +proc +dagMenuProc *\( *string *(\$[a-zA-Z0-9_]+), *string *(\$[a-zA-Z0-9_]+) *\)"
    )
    with open(dagMenuScriptpath) as f:
        dagMenuScriptLineIter = iter(f)
        with open(tmpScriptpath, 'w') as f2:
            hasDagMenuProcBeenSetup = False
            for line in dagMenuScriptLineIter:
                f2.write(line)

                globalProcDefSearch = globalProcDefRex.search(line)
                if globalProcDefSearch:
                    parentVarStr, objectVarStr = globalProcDefSearch.groups()
                    selHierarchyRex = re.compile(
                        'uiRes *\( *"m_dagMenuProc.kSelectHierarchy" *\)')

                    if '{' in line:
                        writeZooLines(f2, parentVarStr, objectVarStr)
                        hasDagMenuProcBeenSetup = True

                    if not hasDagMenuProcBeenSetup:
                        for line in dagMenuScriptLineIter:
                            f2.write(line)
                            if '{' in line:
                                writeZooLines(f2, parentVarStr, objectVarStr)
                                hasDagMenuProcBeenSetup = True
                                break

        if not hasDagMenuProcBeenSetup:
            printErrorStr("Couldn't auto setup dagMenuProc!  AWOOGA!")
            return

        evalMel('source "%s";' % tmpScriptpath)
        evalMel('source "%s";' % tmpScriptpath)
Пример #2
0
def setupDagProcMenu():
    """
	sets up the modifications to the dagProcMenu script
	"""
    try:
        dagMenuScriptpath = findFirstInEnv("dagMenuProc.mel", "MAYA_SCRIPT_PATH")
    except:
        MGlobal.displayWarning("Cannot find the dagMenuProc.mel script - aborting auto-override!")
        return

    tmpScriptpath = Path(cmd.internalVar(usd=True)) / "zoo_dagMenuProc_override.mel"

    def writeZooLines(fStream, parentVarStr, objectVarStr):
        fStream.write("\n/// ZOO TOOLBOX MODS ########################\n")
        fStream.write("\tsetParent -m $parent;\n")
        fStream.write("\tmenuItem -d 1;\n")
        fStream.write('\tpython( "from zooPyMaya import triggeredUI" );\n')
        fStream.write(
            """\tint $killState = python( "triggeredUI.buildMenuItems( '"+ %s +"', '"+ %s +"' )" );\n"""
            % (parentVarStr, objectVarStr)
        )
        fStream.write("\tif( $killState ) return;\n")
        fStream.write("/// END ZOO TOOLBOX MODS ####################\n\n")

    globalProcDefRex = re.compile(
        "^global +proc +dagMenuProc *\( *string *(\$[a-zA-Z0-9_]+), *string *(\$[a-zA-Z0-9_]+) *\)"
    )
    with open(dagMenuScriptpath) as f:
        dagMenuScriptLineIter = iter(f)
        with open(tmpScriptpath, "w") as f2:
            hasDagMenuProcBeenSetup = False
            for line in dagMenuScriptLineIter:
                f2.write(line)

                globalProcDefSearch = globalProcDefRex.search(line)
                if globalProcDefSearch:
                    parentVarStr, objectVarStr = globalProcDefSearch.groups()
                    selHierarchyRex = re.compile('uiRes *\( *"m_dagMenuProc.kSelectHierarchy" *\)')

                    if "{" in line:
                        writeZooLines(f2, parentVarStr, objectVarStr)
                        hasDagMenuProcBeenSetup = True

                    if not hasDagMenuProcBeenSetup:
                        for line in dagMenuScriptLineIter:
                            f2.write(line)
                            if "{" in line:
                                writeZooLines(f2, parentVarStr, objectVarStr)
                                hasDagMenuProcBeenSetup = True
                                break

        if not hasDagMenuProcBeenSetup:
            printErrorStr("Couldn't auto setup dagMenuProc!  AWOOGA!")
            return

        evalMel('source "%s";' % tmpScriptpath)
        evalMel('source "%s";' % tmpScriptpath)
Пример #3
0
	def getUserSetupFile( self ):
		pyUserSetup, melUserSetup = None, None
		try:
			pyUserSetup = findInPyPath( 'userSetup.py' )
		except: pass

		try:
			melUserSetup = findFirstInEnv( 'userSetup.mel', 'MAYA_SCRIPT_PATH' )
		except: pass

		return pyUserSetup, melUserSetup
Пример #4
0
    def getUserSetupFile(self):
        pyUserSetup, melUserSetup = None, None
        try:
            pyUserSetup = findInPyPath('userSetup.py')
        except:
            pass

        try:
            melUserSetup = findFirstInEnv('userSetup.mel', 'MAYA_SCRIPT_PATH')
        except:
            pass

        return pyUserSetup, melUserSetup