def getFileBox(task_id, task_stage): if not getAccountInfo(ACCOUNT_LOGGED_IN): return [] if task_id == Filebox.task_id: return Filebox.content Filebox.task_id = task_id pipeline = tw.pipeline(config.getConfig("database")) filebox = tw.filebox(config.getConfig("database")) tables = {"asset": "asset_name", "shot": "shot"} for table in tables: pipeline_item = pipeline.get_with_filter(["name"], [["module", "=", "%s_task" % table]]) pipeline_id = "" for p in pipeline_item or list(): if p["name"] == task_stage: pipeline_id = p["id"] if not pipeline_id: continue Filebox.content = [] for filebox_item in filebox.get_with_pipeline_id(pipeline_id, "%s_task" % table) or list(): info_module = tw.info_module(config.getConfig("database"), "%s_task" % table) info_module.init_with_filter([["%s_task.id" % table, "=", task_id]]) filebox_obj = info_module.get_filebox_with_filebox_id(filebox_item["id"]) if filebox_obj: Filebox.content.append(filebox_obj) return Filebox.content
def getCheckInfo(): result = [] if not getAccountInfo(ACCOUNT_LOGGED_IN): return result tables = {"asset": "asset_name", "shot": "shot"} for table in tables: check_filter = tw.con._send("c_work_flow", "get_check_filter", {"db":config.getConfig("database"), "module":"%s_task"%table}) if not check_filter: continue module = tw.task_module(config.getConfig("database"), "%s_task" % table) module.init_with_filter(check_filter) for item in module.get(["%s.%s" % (table, tables[table]), "%s_task.pipeline" % table, "%s_task.status" % table, "%s_task.end_date" % table, "%s_task.artist" % table, "%s_task.last_submit_time" % table]) or list(): if not item["%s.%s" % (table, tables[table])]: continue result.append({"id": item["id"], "name": item["%s.%s" % (table, tables[table])], "stage": item["%s_task.pipeline" % table], "status": item["%s_task.status" % table], "date": item["%s_task.end_date" % table], "artist": item["%s_task.artist" % table], "latest": item["%s_task.last_submit_time" % table]}) return result
def submit(task_id, path, text, image=None): History.force_update = True for table in ["asset_task", "shot_task"]: t_module = tw.task_module(config.getConfig("database"), table) t_module.init_with_id(task_id) t_module.submit([path], text)
def refreshUI(self, *_): self.reset() if not config.getProject(): return self.project = config.getConfig("database") self.onTaskListChanged()
def doIt(): cameraName = config.getConfig('camera') listCam = cmds.listCameras(perspective=True) if not cameraName in listCam: cmds.camera(name=cameraName, displayResolution=True) cmds.rename(cameraName) cmds.setAttr("defaultResolution.width", config.getConfig('camResX')) cmds.setAttr("defaultResolution.height", config.getConfig('camResY')) cmds.select(cameraName, r=True) try: cmds.addAttr(cameraName, ln='Focal_Length', attributeType='double', defaultValue=35, minValue=0, maxValue=200) cmds.setAttr(cameraName+".Focal_Length", edit=True, keyable=True) cmds.connectAttr(cameraName+".Focal_Length", cameraName+"Shape.focalLength", force=True) except: pass
def submit(self, *_): if not database.getAccountInfo(database.ACCOUNT_LOGGED_IN): self.reset() return import pyblish_starter.api as api index = self.CGTWTVTask.currentIndex() task_id = index.data(model.TASK_ID) family = index.data(model.TASK_STAGE) name = index.data(model.TASK_NAME) if family not in config.getConfig("familyMap"): self.CGTWLBLResult.setText(u"<font color=black>所选任务不能在Maya中执行</font>") self.CGTWLBLResult.setStyleSheet("background-color: rgba(255, 255, 90, 255);") return self.CGTWLBLResult.setText(u"<font color=black>正在提交检查...</font>") self.CGTWLBLResult.setStyleSheet("background-color: rgba(90, 255, 255, 255);") try: cmds.delete("%s_SEL"%name) except: pass api.registered_host().create(name, config.getConfig("familyMap")[family]) cmds.addAttr("%s_SEL"%name, longName="project", dataType="string", hidden=False) cmds.addAttr("%s_SEL"%name, longName="pipeline", dataType="string", hidden=False) cmds.addAttr("%s_SEL"%name, longName="database", dataType="string", hidden=False) cmds.addAttr("%s_SEL"%name, longName="taskID", dataType="string", hidden=False) cmds.setAttr("%s_SEL.project"%name, config.getProject(), type="string") cmds.setAttr("%s_SEL.pipeline"%name, family, type="string") cmds.setAttr("%s_SEL.database"%name, config.getConfig("database"), type="string") cmds.setAttr("%s_SEL.taskID"%name, task_id, type="string") context = pyblish.util.publish() self.CGTWLBLResult.setText(u"<font color=black>任务提交成功</font>") self.CGTWLBLResult.setStyleSheet("background-color: rgba(90, 255, 90, 255);") for result in context.data["results"]: if not result["success"]: self.CGTWLBLResult.setText(u"<font color=black>错误:%s</font>"%result["error"].message) self.CGTWLBLResult.setStyleSheet("background-color: rgba(255, 90, 90, 255);") break cmds.delete("%s_SEL"%name)
def getCharacters(self): cmds.namespace(set=":") refs = cmds.file(q=True, reference=True) fileList = self.getDirectoryList(config.getConfig('animLibPath')) newNS = [] for ref in refs: if not cmds.referenceQuery(ref, isLoaded=True): continue name = ref.split("/")[-1] for f in fileList: if not name.find(f) == -1: newNS.append(cmds.referenceQuery(ref, namespace=True)) break return newNS
def configuration(self): sel = self.shelf.data if not sel: return None cmds.namespace(set=":") time = int(cmds.currentTime(q=True)) copy = self.motionLibHSCopies.value() filePath = "%s%s\\%s.anim" % (config.getConfig('animLibPath'), self.getOrigChar( self.namespace.split(":")[-1]), sel) mode = "insert" if self.motionLibRBMerge.isChecked(): mode = "merge" cfg = {"copy": copy, "file": filePath, "time": time, "mode": mode} return cfg
def getTaskInfo(**kwargs): if not getAccountInfo(ACCOUNT_LOGGED_IN): return [] result = [] tables = {"asset": "asset_name", "shot": "shot"} tables2 = {"asset": "asset.type_name", "shot": "eps.eps_name"} tables3 = {"asset": "asset.cn_name", "shot": "eps.eps_name"} if "table" in kwargs and kwargs["table"]: tables = {kwargs["table"]: tables[kwargs["table"]]} for table in tables: filters = [] for key in kwargs: if key == "table": continue if filters: filters.append("and") filters.append(["%s_task.%s" % (table, key), "=", kwargs[key]]) if not filters: filters.append(["%s.%s" % (table, tables[table]), "has", "%"]) module = tw.task_module(config.getConfig("database"), "%s_task" % table) module.init_with_filter(filters) for item in module.get(["%s.%s" % (table, tables[table]), "%s_task.pipeline" % table, "%s_task.status" % table, "%s_task.end_date" % table, "%s_task.artist" % table, "%s_task.image" % table, "%s_task.last_submit_time" % table, tables2[table], tables3[table]]) or list(): if not item["%s.%s" % (table, tables[table])]: continue result.append({"id": item["id"], "name": item["%s.%s" % (table, tables[table])], "stage": item["%s_task.pipeline" % table], "status": item["%s_task.status" % table], "date": item["%s_task.end_date" % table], "artist": item["%s_task.artist" % table], "image": item["%s_task.image" % table], "latest": item["%s_task.last_submit_time" % table], "filter": item[tables2[table]], "detail": item[tables3[table]]}) return result
def refreshData(self, *_): self.__select = [] cmds.namespace(set=":") self.shelf.cleanUp() self.motionLibBtnImport.setEnabled(False) self.motionLibCBProject.setCurrentText(config.getProject()) if not self.motionLibCBCharactor.count(): return self.namespace = self.motionLibCBCharactor.currentText().split( "<")[-1].split(">")[0] self.path = config.getConfig('animLibPath') + self.getOrigChar( self.namespace.split(":")[-1]) fileList = self.getFileList(self.path) exp = codecs.decode(self.motionLibLEFilter.text(), 'utf-8') itemList = [] for f in fileList: if self.__match__(f, exp): found = False for ext in ['gif', 'png', 'jpg']: iconPath = self.path + f + ext if os.path.isfile(iconPath): found = True break if not found: iconPath = config.getPath(config.kIcon, "motion.gif") itemList.append({ ui.QShelfView.kName: f, ui.QShelfView.kData: f, ui.QShelfView.kIcon: iconPath, ui.QShelfView.kType: f }) self.shelf.setup(*itemList) sels = os.popen("type \"%s\"\\__config__" % self.path).read() for sel in sels.split('&'): if not sel: continue self.__select.append("%s:%s" % (self.namespace, sel)) if not self.__select: self.__select.append("%s:Main" % self.namespace) cmds.select(self.__select, r=True) self.__config = None
def getFileHistoryInfo(task_id): if not getAccountInfo(ACCOUNT_LOGGED_IN): return [] if History.force_update: History.force_update = False elif task_id == History.task_id: return History.content History.task_id = task_id for module in ["asset_task", "shot_task"]: t_history = tw.history(config.getConfig("database"), module) History.content = t_history.get_with_filter(["text", "last_update_by", "last_update_time", "step", "status", "file"], [["#task_id", "=", task_id]]) if not History.content: continue History.content = sorted(History.content, key=lambda x:x["last_update_time"], reverse=True) return History.content
def __check__(cls): sf = config.getConfig("startFrame") ast = int(cmds.playbackOptions(q=1, ast=1)) aet = int(cmds.playbackOptions(q=1, aet=1)) mint = int(cmds.playbackOptions(q=1, min=1)) maxt = int(cmds.playbackOptions(q=1, max=1)) if sf != ast: cmds.displayColor("headsUpDisplayLabels", 17) cmds.displayColor("headsUpDisplayValues", 16) return u"初始帧不是第%s帧" % sf if len(cmds.ls(type='audio')) > 1: cmds.displayColor("headsUpDisplayLabels", 17) cmds.displayColor("headsUpDisplayValues", 16) return u"存在多重音轨" if ast != mint or aet != maxt: cmds.displayColor("headsUpDisplayLabels", 17) cmds.displayColor("headsUpDisplayValues", 16) return u"时间轴未最大化" cmds.displayColor("headsUpDisplayLabels", 14) cmds.displayColor("headsUpDisplayValues", 16) return ""
def playblast(cls): fullPath = cmds.file(q=1, exn=1) fileName = cmds.file(q=1, sn=1, shn=1) if fileName == '': cmds.headsUpMessage(u'文件未保存', time=1) return videoNameList = fileName.split(".") videoName = "" for i in range(len(videoNameList) - 1): videoName = videoName + videoNameList[i] if i < len(videoNameList) - 1: videoName = videoName + '.' videoOutName = videoName + 'mov' videoName = videoName + 'avi' pathList = fullPath.split(fileName) path = "" for i in range(len(pathList) - 1): path = path + pathList[i] videoPath = path + videoName videoOutPath = path + videoOutName soundTmp = mel.eval('$tmpVar=$gPlayBackSlider') soundObj = cmds.timeControl(soundTmp, q=1, sound=1) startFrame = cmds.playbackOptions(q=1, minTime=1) endFrame = cmds.playbackOptions(q=1, maxTime=1) panel = cmds.playblast(activeEditor=True).split("|")[-1] currentCam = cmds.modelPanel(panel, q=True, camera=True) cam = cmds.listRelatives(currentCam) if not cam: cam = currentCam else: cam = cam[0] padding = 0 if (not cmds.optionVar(exists="PutaoTools_HUD_Padding") ) or cmds.optionVar(q="PutaoTools_HUD_Padding"): cmds.optionVar(iv=("PutaoTools_HUD_Padding", 120)) padding = cmds.optionVar(q="PutaoTools_HUD_Padding") cmds.setAttr(cam + ".displayFilmGate", 0) cmds.setAttr(cam + ".displayResolution", 1) cmds.setAttr(cam + ".displayGateMask", 1) cmds.setAttr(cam + ".displayGateMaskOpacity", 1.0) cmds.setAttr(cam + ".displayGateMaskColor", 0.0, 0.0, 0.0, type='double3') cmds.setAttr(cam + ".displaySafeAction", 1) cmds.setAttr(cam + ".overscan", 1) cmds.setAttr(cam + ".filmFit", 1) cmds.select(clear=True) cmds.setAttr("%s.width" % cmds.ls(renderResolutions=True)[0], config.getConfig('camResX')) cmds.setAttr("%s.height" % cmds.ls(renderResolutions=True)[0], config.getConfig('camResY')) ha = cmds.getAttr(cam + ".verticalFilmAperture") ar = float(config.getConfig('camResX')) / float( config.getConfig('camResY')) cmds.setAttr(cam + ".horizontalFilmAperture", lock=False) cmds.setAttr(cam + ".horizontalFilmAperture", ha * ar) cmds.setAttr( "%s.deviceAspectRatio" % cmds.ls(renderResolutions=True)[0], ar) cls.__makeHUD__() try: if soundObj: playblastFile = cmds.playblast( sound=soundObj, combineSound=True, st=startFrame, et=endFrame, widthHeight=[ config.getConfig('camResX'), config.getConfig('camResY') + padding ], percent=config.getConfig('playblastScale'), filename=videoPath, forceOverwrite=True, format='avi', compression='none', quality=100, clearCache=True, viewer=False, showOrnaments=True, offScreen=False) else: playblastFile = cmds.playblast( st=startFrame, et=endFrame, widthHeight=[ config.getConfig('camResX'), config.getConfig('camResY') + padding ], percent=config.getConfig('playblastScale'), filename=videoPath, forceOverwrite=True, format='avi', compression='none', quality=100, clearCache=True, viewer=False, showOrnaments=True, offScreen=False) except: cls.__clearHUD__() cmds.setAttr(cam + ".filmFit", config.getConfig('camFilmFit')) return cls.__clearHUD__() cmds.setAttr(cam + ".filmFit", config.getConfig('camFilmFit')) if playblastFile: mp = config.getPath(config.kBinary, "ffmpeg") uFile = os.path.abspath(playblastFile.encode('gbk')) uOut = os.path.abspath(videoOutPath.encode('gbk')) resultCmd = r'%s -i "%s" -vcodec "mpeg4" -y -qscale 0 "%s"' % ( mp, uFile, uOut) os.system(resultCmd) os.startfile(uOut) os.remove(playblastFile) cmds.currentTime(startFrame)
def getShotInfo(name): info_module = tw.info_module(config.getConfig("database"), "shot") result = info_module.get_with_filter(["eps.eps_name"], [["shot.shot", "=", name]]) if result: return result[0]["eps.eps_name"]
def getAssetInfo(name): info_module = tw.info_module(config.getConfig("database"), "asset") result = info_module.get_with_filter(["asset.cn_name", "asset.type_name"], [["asset.asset_name", "=", name]]) if result: return result[0]
def getPipeLineInfo(table): tw_pipeline = tw.pipeline(config.getConfig("database")) return tw_pipeline.get_with_module(table, ["name"])