def checkForAnimationSaved(self, clearDeferredQueue=False, *args): if clearDeferredQueue: self.deferredQueue = [] sceneId = aToolsMod.getSceneId() idFolder = "%s%s%s"%(self.baseFolderName, os.sep, sceneId) latestFolder = "%s%s%s"%(idFolder, os.sep, self.baseLatestFolderName) infoFile = "%s%s%s%s%s.info"%(G.USER_FOLDER, os.sep, latestFolder, os.sep, self.infoDataFileName) mayaFile = cmds.file(query=True, sceneName=True) if not os.path.isfile(infoFile) or not os.path.isfile(mayaFile): return mayaFileModTime = os.path.getmtime(mayaFile) infoFileModTime = os.path.getmtime(infoFile) if mayaFileModTime < infoFileModTime: infoData = aToolsMod.loadFileWithUser(latestFolder, self.infoDataFileName, ext="info") if not infoData: return height = 170 completed = infoData["completed"] mayaFileModTimeStr = time.ctime(mayaFileModTime) infoFileModTimeStr = time.ctime(infoFileModTime) message = "This Maya file:\n%s\n\n"%(mayaFileModTimeStr) message += "Latest Animation Crash Recovery file:\n%s"%(infoFileModTimeStr) if not completed: message += "\n\n*Some animation may not be loaded.\nAnimation Crash Recovery did not finish saving before Maya crashed." height += 40 self.warningForLoading(message, height)
def saveInfoData(self, mayaFileName, completed=False): sceneId = aToolsMod.getSceneId() currFrame = cmds.currentTime(query=True) currSel = cmds.ls(selection=True) infoData = {"mayaFileName":mayaFileName, "currFrame":currFrame, "currSel":currSel, "completed":completed} aToolsMod.saveFileWithUser("%s%s%s%s%s"%(self.baseFolderName, os.sep, sceneId, os.sep, self.baseLatestFolderName), self.infoDataFileName, infoData, ext="info")
def optionBoxWindow(self, *args): sceneId = aToolsMod.getSceneId() idFolder = "%s%s%s"%(self.baseFolderName, os.sep, sceneId) bkpFolder = "%s%s%s"%(idFolder, os.sep, self.baseBackupFolderName) infoData = aToolsMod.loadFileWithUser(bkpFolder, self.infoDataFileName, ext="info") infoDataFile = "%s%s%s%s%s.info"%(G.USER_FOLDER, os.sep, bkpFolder, os.sep, self.infoDataFileName) modDate = os.path.getmtime(infoDataFile) if os.path.isfile(infoDataFile) else None if not infoData or not modDate: cmds.warning("There is no crash file to restore.") return def loadWindow(): mayaFileName = infoData["mayaFileName"] message = "%s\n%s\n\nWarning: Loading crash files after editing your Maya file can lead to unpredictable results."%(mayaFileName, time.ctime(modDate)) formLayout = cmds.setParent(query=True) icon = cmds.image(image= uiMod.getImagePath("ACR_white_bright")) titleText = cmds.text(label="Do you want to load?", font="boldLabelFont", align="left") messageText = cmds.text(label=message, align="left") buttonLoad = cmds.button(label='Load', command='cmds.layoutDialog(dismiss="load")') buttonLoadSel = cmds.button(label='Load On Selection', command='cmds.layoutDialog(dismiss="load_selection")', w=110) cmds.formLayout (formLayout, edit=True, width=300, height=170, attachPosition = [ (icon, 'left', 10, 0), (icon, 'top', 10, 0), (titleText, 'top', 10, 0), (messageText, 'left', 10, 0), (messageText, 'top', 0, 30), (buttonLoad, 'left', 10, 0), (buttonLoad, 'bottom', 10, 100), (buttonLoadSel, 'bottom', 10, 100) ], attachForm = [ (buttonLoad, 'left', 10), (buttonLoadSel, 'right', 10) ], attachControl = [ (titleText, 'left', 10, icon), (buttonLoad, 'right', 5, buttonLoadSel) ]) def window(dismiss): if dismiss == "dismiss": return onlySelectedNodes = True if dismiss == "load_selection" else False self.loadData(onlySelectedNodes, self.baseBackupFolderName) window(cmds.layoutDialog(title="aTools Animation Crash Recovery", ui=loadWindow))
def clearLatestFolder(self): self.deferredQueue = [] G.deferredManager.removeFromQueue("ACR") sceneId = aToolsMod.getSceneId() idFolder = "%s%s%s"%(self.baseFolderName, os.sep, sceneId) latestFolder = "%s%s%s"%(idFolder, os.sep, self.baseLatestFolderName) aToolsMod.deleteFolderWithUser(latestFolder)
def saveBackup(self): sceneId = aToolsMod.getSceneId() idFolder = "%s%s%s"%(self.baseFolderName, os.sep, sceneId) latestFolder = "%s%s%s"%(idFolder, os.sep, self.baseLatestFolderName) bkpFolder = "%s%s%s"%(idFolder, os.sep, self.baseBackupFolderName) aToolsMod.deleteFolderWithUser(bkpFolder) aToolsMod.renameFolderWithUser(latestFolder, bkpFolder) aToolsMod.deleteFolderWithUser(latestFolder)
def loadInfoData(self): sceneId = aToolsMod.getSceneId() infoData = aToolsMod.loadFileWithUser("%s%s%s%s%s"%(self.baseFolderName, os.sep, sceneId, os.sep, self.baseLatestFolderName), self.infoDataFileName, ext="info") if not infoData: return currFrame = infoData["currFrame"] currSel = infoData["currSel"] if currFrame: cmds.currentTime(currFrame) if len(currSel) > 0: cmds.select(currSel, replace=True)
def saveNonKeyedAttrs(self, mayaFileName, nonKeyedAttrsStr): self.setLed("blinking") sceneId = aToolsMod.getSceneId() nonKeyedAttr = nonKeyedAttrsStr.replace("_aTools_", ":") attrData = self.getNonKeyedAttrData(nonKeyedAttr) if nonKeyedAttrsStr in self.deferredQueue: self.deferredQueue.remove(nonKeyedAttrsStr) if attrData is None: return if not self.nonKeyedAttrInfo.has_key(sceneId): self.nonKeyedAttrInfo[sceneId] = {} if self.nonKeyedAttrInfo[sceneId].has_key(nonKeyedAttrsStr): if self.nonKeyedAttrInfo[sceneId][nonKeyedAttrsStr] == attrData: return self.nonKeyedAttrInfo[sceneId][nonKeyedAttrsStr] = attrData #save curve to disk aToolsMod.saveFileWithUser("%s%s%s%s%s"%(self.baseFolderName, os.sep, sceneId, os.sep, self.baseLatestFolderName), nonKeyedAttrsStr, attrData, ext=self.attrExt) self.saveInfoData(mayaFileName)
def saveCurve(self, mayaFileName, curveStr): self.setLed("blinking") sceneId = aToolsMod.getSceneId() curve = curveStr.replace("_aTools_", ":") animData = animMod.getAnimData([curve]) if curveStr in self.deferredQueue: self.deferredQueue.remove(curveStr) if animData is None: return if not self.animCurvesInfo.has_key(sceneId): self.animCurvesInfo[sceneId] = {} if self.animCurvesInfo[sceneId].has_key(curveStr): if self.animCurvesInfo[sceneId][curveStr] == animData: return self.animCurvesInfo[sceneId][curveStr] = animData #save curve to disk aToolsMod.saveFileWithUser("%s%s%s%s%s"%(self.baseFolderName, os.sep, sceneId, os.sep, self.baseLatestFolderName), curveStr, animData, ext=self.curveExt) self.saveInfoData(mayaFileName)
def getSavedData(self, crashFolder=None, onlySelectedNodes=False, *args): idFolder = aToolsMod.getSceneId() crashFolder = self.baseLatestFolderName if not crashFolder else crashFolder folder = "%s%s%s%s%s"%(self.baseFolderName, os.sep, idFolder, os.sep, crashFolder) filePath = cmds.file(query=True, sceneName=True) fileModTime = None if os.path.isfile(filePath): fileModTime = os.path.getmtime(filePath) curveFiles = aToolsMod.readFilesWithUser(folder, ext=self.curveExt) attrFiles = aToolsMod.readFilesWithUser(folder, ext=self.attrExt) status = "aTools Animation Crash Recovery - Step 1/3 - Loading crash files..." utilMod.startProgressBar(status) totalSteps = len(curveFiles + attrFiles) firstStep = 0 thisStep = 0 estimatedTime = None startChrono = None progressInfo = [startChrono, firstStep, thisStep, totalSteps, estimatedTime, status] data = self.getDataFromFiles("anim", folder, curveFiles, fileModTime, self.curveExt, progressInfo, onlySelectedNodes) if not data: return animData = data[0] progressInfo = data[1] data = self.getDataFromFiles("attr", folder, attrFiles, fileModTime, self.attrExt, progressInfo, onlySelectedNodes) attrData = data[0] if not data: return utilMod.setProgressBar(endProgress=True) return {"fileModTime":fileModTime, "animData":animData, "attrData":attrData}