def accept(self): """Sets option/environnement vars to remember user choices.""" # Set session var if checkbox1 was checked if self.cbx_switch_session.isChecked(): pmu.putEnv(Vars.VIEWPORT_ENVVAR, "1") # Set option var if checkbox2 was checked if self.cbx_switch_always.isChecked(): pmc.optionVar(iv=(Vars.VIEWPORT_OPTION, 1)) # Accept event QtGui.QDialog.accept(self)
def openScene(sScenePath, **kwargs): bAddToRecent = kwargs.pop("addToRecent", False) if kwargs.pop("noFileCheck", True): pmu.putEnv("DAVOS_FILE_CHECK", "") bFail = kwargs.pop("fail", True) res = None try: res = pm.openFile(sScenePath, **kwargs) except RuntimeError, e: if bFail: raise else: pm.displayError(toStr(e.message))
def saveScene(**kwargs): sSceneType = "" sCurScnPath = pm.sceneName() if not sCurScnPath: sCurScnPath = "untitled" sSceneName = "untitled scene" sSceneTypeList = ['mayaAscii', 'mayaBinary'] else: sSceneName = sCurScnPath sExt = osp.splitext(sCurScnPath)[1].lower() sSceneTypeList = [] if sExt: if sExt == ".ma": sSceneTypeList = ['mayaAscii'] elif sExt == ".mb": sSceneTypeList = ['mayaBinary'] if not sSceneTypeList: raise ValueError("Invalid maya scene extension: '{}'".format(sExt)) #sSceneTypeList = mc.file(q=True, type=True) if len(sSceneTypeList) > 1: raise RuntimeError, 'Saving "{0}" : More than one type matches this file : {1}'\ .format(sCurScnPath, sSceneTypeList) else: sSceneType = sSceneTypeList[0] sWantedSceneType = kwargs.get('fileType', kwargs.get('ft', '')) if sWantedSceneType and (sWantedSceneType != sSceneType): if sWantedSceneType not in ('mayaAscii', 'mayaBinary'): raise ValueError('Invalid file type: "{0}"'.format(sWantedSceneType)) sSceneType = sWantedSceneType else: if not mc.file(q=True, modified=True): pm.displayWarning("Current scene has NO changes to save: '{}'.".format(sSceneName)) return sCurScnPath bPrompt = kwargs.get("prompt", True) if bPrompt: if kwargs.get("discard", True): buttonList = ("Save", "Don't Save", "Cancel") sDismiss = "Don't Save" sConfirmEnd = "?" else: buttonList = ("Save", "Cancel") sDismiss = "Cancel" sConfirmEnd = "!" sMsg = 'Save changes to :\n\n{0} {1}'.format(sSceneName, sConfirmEnd) sConfirm = pm.confirmDialog(title="DO YOU WANT TO...", message=sMsg, button=buttonList, defaultButton="Cancel", cancelButton="Cancel", dismissString=sDismiss, icon="question", ) else: sConfirm = "Save" if sConfirm == "Cancel": logMsg("Cancelled !" , warning=True) return "" elif sConfirm == "Don't Save": return sCurScnPath elif sConfirm == "Save": bNoFileCheck = kwargs.pop("noFileCheck", True) if (not sCurScnPath) or sCurScnPath == "untitled": sFileList = chooseMayaScene(ff=sSceneTypeList) if not sFileList: return "" if bNoFileCheck: pmu.putEnv("DAVOS_FILE_CHECK", "") return pm.saveAs(sFileList[0], force=True) else: if bNoFileCheck: pmu.putEnv("DAVOS_FILE_CHECK", "") if kwargs.get("checkError", True): try: assertCurrentSceneReadWithoutDataLoss() except AssertionError: return "" if sSceneType: return pm.saveFile(force=True, type=sSceneType) else: return pm.saveFile(force=True)
def saveScene(**kwargs): sSceneType = "" sCurScnPath = pm.sceneName() if not sCurScnPath: sCurScnPath = "untitled" sSceneName = "untitled scene" sSceneTypeList = ['mayaAscii', 'mayaBinary'] else: sSceneName = sCurScnPath sExt = osp.splitext(sCurScnPath)[1].lower() sSceneTypeList = [] if sExt: if sExt == ".ma": sSceneTypeList = ['mayaAscii'] elif sExt == ".mb": sSceneTypeList = ['mayaBinary'] if not sSceneTypeList: raise ValueError("Invalid maya scene extension: '{}'".format(sExt)) #sSceneTypeList = mc.file(q=True, type=True) if len(sSceneTypeList) > 1: raise RuntimeError, 'Saving "{0}" : More than one type matches this file : {1}'\ .format(sCurScnPath, sSceneTypeList) else: sSceneType = sSceneTypeList[0] sWantedSceneType = kwargs.get('fileType', kwargs.get('ft', '')) if sWantedSceneType and (sWantedSceneType != sSceneType): if sWantedSceneType not in ('mayaAscii', 'mayaBinary'): raise ValueError( 'Invalid file type: "{0}"'.format(sWantedSceneType)) sSceneType = sWantedSceneType else: if not mc.file(q=True, modified=True): pm.displayWarning( "Current scene has NO changes to save: '{}'.".format( sSceneName)) return sCurScnPath bPrompt = kwargs.get("prompt", True) if bPrompt: if kwargs.get("discard", True): buttonList = ("Save", "Don't Save", "Cancel") sDismiss = "Don't Save" sConfirmEnd = "?" else: buttonList = ("Save", "Cancel") sDismiss = "Cancel" sConfirmEnd = "!" sMsg = 'Save changes to :\n\n{0} {1}'.format(sSceneName, sConfirmEnd) sConfirm = pm.confirmDialog( title="DO YOU WANT TO...", message=sMsg, button=buttonList, defaultButton="Cancel", cancelButton="Cancel", dismissString=sDismiss, icon="question", ) else: sConfirm = "Save" if sConfirm == "Cancel": logMsg("Cancelled !", warning=True) return "" elif sConfirm == "Don't Save": return sCurScnPath elif sConfirm == "Save": bNoFileCheck = kwargs.pop("noFileCheck", True) if (not sCurScnPath) or sCurScnPath == "untitled": sFileList = chooseMayaScene(ff=sSceneTypeList) if not sFileList: return "" if bNoFileCheck: pmu.putEnv("DAVOS_FILE_CHECK", "") return pm.saveAs(sFileList[0], force=True) else: if bNoFileCheck: pmu.putEnv("DAVOS_FILE_CHECK", "") if kwargs.get("checkError", True): try: assertCurrentSceneReadWithoutDataLoss() except AssertionError: return "" if sSceneType: return pm.saveFile(force=True, type=sSceneType) else: return pm.saveFile(force=True)
def _set_working_drive(working_drive): #set the working drive if it's not already if not working_drive: for c in reversed(get_available_drives()): d = Path(c + ':') if not (d / 'lavaWorkingDrive').isfile(): continue working_drive = d.drive break if not working_drive: return False working_drive = Path(working_drive[0] + ':/') #set the maya path maya_path = Path(working_drive) / 'maya' if not maya_path.isdir(): return False #it's too late at this point, unfortunately, to pick up the latest version of pymel, #nor does the Maya.env PYTHONPATH seem to work like it should, so, #assuming your working drive is Z, your Maya path is z:/maya and you've #installed the latest version of pymel in your Maya path, you need to edit the #environment variables for your account to include #PYTHONPATH: z:/maya/scripts;z:/maya/pymel-1.x.x #i wish there was a better way and maybe there is, but i really devoted a lot #of time and energy into solving this problem with python scripts and this is #the only solution that worked. #look for and load the maya/plug-ins folder too. env_key = 'MAYA_PLUG_IN_PATH' pips = getEnvs(env_key) for i, p in enumerate(pips): pips[i] = _fix_path(Path(p)) for f in maya_path.listdir(): if f.name == 'plug-ins': f = _fix_path(f) if f in pips: del pips[pips.index(f)] pips.insert(0, f) break putEnv(env_key, ';'.join(pips)) #set the workspace workspace(maya_path / 'projects', openWorkspace=True) #set the script path script_path = maya_path / 'scripts' if script_path.isdir(): #prepare some empty dictionaries to store unique #folder paths as keys for script locations. mels, pys, pymods = {}, {}, {} #put the file's folder path in the appropriate mel, mods #or pys dictionary. pats = {'__init__.py*': pymods, '*.mel': mels, '*.py': pys} for f in script_path.walkfiles(): for k, v in pats.items(): if f.fnmatch(k): v[_fix_path(f.dirname())] = None #remove any pys keys that are also found in pymods. #this is the only reason we made pymods in the first place, so #delete pymods to make it clear that we're done with it. for k in (k for k in pymods.keys() if k in pys): del pys[k] del pymods #fix all the sys.paths to make them consistent with pys #key-searches and add any py leftovers to the sys.paths. pys[_fix_path(script_path)] = None sp = [] for p in sys.path: p = _fix_path(Path(p)) if p in pys: del pys[p] sp.append(p) sys.path = [k for k in reversed(sorted(pys.keys(), key=str.lower))] + sp #fix all the maya script paths to make them consistent with mels #key-searches and add any mel leftovers to the env var. mels[_fix_path(script_path)] = None env_key = 'MAYA_SCRIPT_PATH' sps = getEnvs(env_key) for i, p in enumerate(sps): sps[i] = _fix_path(Path(p)) if sps[i] in mels: del mels[sps[i]] for k in reversed(sorted(mels.keys(), key=str.lower)): sps.insert(0, k) putEnv(env_key, ';'.join(sps)) #sourcing the scriptEditorPanel, for some reason, will actually check #the pymelScrollFieldReporter.py in the Plug-in Manager. if this is not #done, it will throw an error whenever the script editor is opened. sep = 'scriptEditorPanel.mel' if (script_path / sep).isfile(): mel.source(sep) return True