def checkShadersAssignation(shape): """Ensure that required shaders are connected to alembicHolder""" required = [] connected = [] # find the shaders / displacement that are required shadersAssignation = cmds.getAttr("%s.shadersAssignation" % shape) if shadersAssignation: shadersAssignation = json.loads(shadersAssignation) for shader in shadersAssignation.keys(): if not shader in required: required.append(shader) shape_connections = cmds.listAttr("%s.shaders" % shape, multi=True) # go find the connected shaders if shape_connections: for con in shape_connections: connected_shader = cmds.listConnections("%s.%s" % (shape, con))[0] connected.append(connected_shader) port = len(connected) for req in required: if req not in connected: if cmds.objExists(req): cmds.connectAttr(req + ".message", shape + ".shaders[%i]" % port) port += 1 message = 'Connected %s to %s' % (req, shape) MGlobal.displayInfo(message) else: message = "Missing shader : %s" % req MGlobal.displayWarning(message)
def checkLayersOverride(shape): """Ensure that required shaders are connected to alembicHolder""" required = [] connected = [] # find the shaders / displacement that are required layersOverride = cmds.getAttr("%s.layersOverride" % shape) if layersOverride: layersOverride = json.loads(layersOverride) for layer in layersOverride: if layersOverride[layer].has_key('shaders'): for k in layersOverride[layer]['shaders'].keys(): if not k in required: required.append(k) shape_connections = cmds.listAttr("%s.shaders" % shape, multi=True) # go find the connected shaders if shape_connections: for con in shape_connections: connected_shader = cmds.listConnections("%s.%s" % (shape, con))[0] connected.append(connected_shader) port = len(connected) for req in required: if req not in connected: if cmds.objExists(req): cmds.connectAttr(req + ".message", shape + ".shaders[%i]" % port) port += 1 message = 'Connected %s to %s' % (req, shape) MGlobal.displayInfo(message) else: message = "Missing shader : %s" % req MGlobal.displayWarning(message)
def update_xforms(abcfile, parent_under): """Update previously imported transforms""" cmd = 'AbcImport "%s" -d -rpr "%s" -ct "%s" -eft "Shape"' % ( abcfile, parent_under, parent_under) try: mel.eval(cmd) MGlobal.displayInfo(cmd) except Exception as e: message = "Error running update transforms : %s" % e MGlobal.displayError(message)
def import_xforms(abcfile, transform_names, parent_under, update): """ Imports and optionally, updates transforms from an alembic file. Params: abcfile : (str) the filepath of the alembic file transform_names : (list) a list of transform names to import / update parent_under : (str) the dag path to alembicHolder update : (bool) update previously imported transforms """ archive = cask.Archive(abcfile) update_data = [] for tr in transform_names: data = {} data['transform'] = tr data['dag_path'] = get_future_dag_path(tr, parent_under, archive) data['exists'] = cmds.objExists(data['dag_path']) if not data['exists']: update_data.append(data) elif data['exists'] and update: update_data.append(data) if get_previously_imported_transforms(abcfile, parent_under) == []: # this doesnt use the -ct and -crt flags, which will cause the import to fail if root nodes are not present if update and update_data != []: cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -eft "Shape"' % ( abcfile, parent_under, ' '.join( [i['transform'] for i in update_data])) try: mel.eval(cmd) MGlobal.displayInfo(cmd) except Exception as e: message = "Error running import transforms : %s" % e MGlobal.displayError(message) return # conntect type AbcImport if update and update_data != []: cmd = 'AbcImport "%s" -d -rpr "%s" -ft "%s" -ct "%s" -crt -eft "Shape"' % ( abcfile, parent_under, ' '.join( [i['transform'] for i in update_data]), parent_under) try: mel.eval(cmd) MGlobal.displayInfo(cmd) except Exception as e: message = "Error running import transforms : %s" % e MGlobal.displayError(message)
def transferMat(): sel = pm.ls(sl=1) if sel == [] or len(sel) != 2: MGlobal.displayInfo('请选择2个物体(源+目标)不要多选或者少选!') return if pm.objectType(sel[0]) == 'mesh': sourceShape = sel[0] else: sourceShape = sel[0].getShapes()[0] if pm.objectType(sel[1]) == 'mesh': targetShape = sel[1] else: targetShape = sel[1].getShapes()[0] mel.eval('deformerAfterObjectSetMod %s %s' % (sourceShape.name(), targetShape.name())) MGlobal.displayInfo('完成!请检查结果!!!')
def checkAndLoadPlugin(pluginName=""): """ load plugin if not loaded. :param pluginName: :return: """ if not cmds.pluginInfo(pluginName, query=True, loaded=True): load_result = cmds.loadPlugin(pluginName) if load_result: MGlobal.displayInfo("plugin " + pluginName + " loaded success") return True else: MGlobal.displayError("Can find and load plugin:%s" % pluginName) return False else: MGlobal.displayInfo("Plugin already loaded:%s" % pluginName) return True
def setSel(self, index): print('正在存储选择...') sl = cmds.ls(sl=1) if sl != []: self.selStor[index] = cmds.ls(sl=1) else: MGlobal.displayInfo('请选择物体') return #起名字 result = cmds.promptDialog(title='Rename Object', message='Enter Name:', button=['OK', 'Cancel'], defaultButton='OK', cancelButton='Cancel', dismissString='Cancel') if result == 'OK': name = cmds.promptDialog(query=True, text=True) if name == '': name = self.selStor[index][0] else: name = self.selStor[index][0] cmds.textField('selectName%d' % index, e=1, tx=name)
def checkAndLoadPlugin(pluginName=""): if not cmds.pluginInfo(pluginName, query=True, loaded=True): cmds.loadPlugin(pluginName) MGlobal.displayInfo("plugin " + pluginName + " loaded success")
def print_maya(str_to_print): """ Print to Maya Script Editor as python comment """ MGlobal.displayInfo(str_to_print)
def info(msg): return MGlobal.displayInfo(msg)
def _printToScriptEditor(self): MGlobal.displayInfo(str(self.values))
def checkTime(shape): """Connect alembicHolder to time""" if not cmds.isConnected("time1.outTime", "%s.time" % shape): message = 'Connecting : time1.outTime to %s.time' % shape cmds.connectAttr("time1.outTime", "%s.time" % shape) MGlobal.displayInfo(message)
def unLock(): a = pm.ls() for i in a: i.unlock() MGlobal.displayInfo(u'解锁完毕!')
def clearSel(self, index): cmds.textField('selectName%d' % index, e=1, tx='') self.selStor[index] = [] MGlobal.displayInfo('清除选择%d' % (index + 1))
# -*- coding: utf-8 -*- # 将所选物体贴在坐标网格上 # designed by Jiaguobao # QQ:779188083 && Tel:15615026078 # Date:2018年10月14日 # version 1.0 # # 1.选择物体 # 2.执行脚本 # 3.将所选物体全部最低点归于坐标y轴零点 from maya.OpenMaya import MGlobal #所有物体贴地 def doit(): tr = cmds.ls(sl=1,dag=1,tr=1) for i in tr: bb = cmds.xform(i,q=1,bb=1) cmds.xform(i,r=1,t=[0,-bb[1],0]) MGlobal.displayInfo(u'执行完成') if __name__ == '__main__': doit()
def convert(self, *args): # 0: 'Only not existing' # 1: 'Overwrite older' # 2: 'Overwrite all' # 0: from scene # 1: from folder flagString = '' lErrors = [] # SIMPLE for myCheckBox in self.simpleCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s ' % mc.checkBox( '%sCheckBox' % myCheckBox, q=True, ann=True) # INT for myCheckBox in self.intCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %i ' % ( mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.intField('%sIntField' % myCheckBox, q=True, v=True)) # DOUBLE INT for myCheckBox in self.doubleIntCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %i %i ' % ( mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.intField('%sIntFieldX' % myCheckBox, q=True, v=True), mc.intField('%sIntFieldY' % myCheckBox, q=True, v=True)) # FLOAT for myCheckBox in self.floatCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %f ' % ( mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.floatField('%sFloatField' % myCheckBox, q=True, v=True)) # ENUM # for myCheckBox in self.enumCheckBoxes: # if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): # flagString += '%s %s ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.attrEnumOptionMenu('%sOptionMenu' % myCheckBox, q=True)) # OPTION MENU for myCheckBox in self.enumCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %s ' % ( mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.optionMenu('%sOptionMenu' % myCheckBox, q=True, v=True)) makeTxPath = mc.textFieldButtonGrp(self.pathTextField, q=True, fileName=True) convertType = mc.radioButtonGrp( self.convertBehaviorRadioButton, q=True, sl=True) - 1 sourceType = mc.radioButtonGrp(self.textureFrom, q=True, sl=True) - 1 showTerminal = mc.checkBox('verboseCheckBox', q=True, v=True) if not os.path.isfile('%s/maketx.exe' % makeTxPath): MGlobal.displayInfo('[ERROR] Unable to find makeTx.exe. Exit!') return if not len(mc.ls(type='file')) and not sourceType: MGlobal.displayInfo( '[WARNING] No textures in current scene. Nothing to convert.') return myFileList = [] if sourceType: myTextureFolder = mc.textFieldButtonGrp(self.texturePathTextField, q=True, fileName=True) imageFormats = [ '.bmp', '.cin', '.dds', '.dpx', '.f3d', '.fits', '.hdr', '.hdri', '.ico', '.iff', '.jpg', '.jpeg', '.jif', '.jfif', '.jfi', '.jp2', '.j2k', '.exr', '.png', '.pbm', '.pgm', '.ppm', '.ptex', '.rla', '.sgi', '.rgb', '.rgba', '.pic', '.tga', '.tif', '.tiff' ] for (fileFolder, folders, files) in os.walk(myTextureFolder): for file in files: if os.path.splitext(file)[-1] in imageFormats: myFileList.append(os.path.join(fileFolder, file)) else: for fileNode in mc.ls(type='file'): myFileList.append(mc.getAttr('%s.fileTextureName' % fileNode)) #Setting up the progress bar. x = len(myFileList) counter = 0 mc.progressBar(self.progressControl, e=True, maxValue=x) mc.columnLayout(self.progressLayout, e=True, manage=True) mc.refresh(f=True) for i, texFileIn in enumerate(myFileList): myPath, myFile = os.path.split(texFileIn) myFile, myExt = os.path.splitext(myFile) texFileOut = '%s/%s.tx' % (myPath, myFile) progressInc = mc.progressBar(self.progressControl, edit=True, pr=counter) mc.text(self.currentNumberText, e=True, l='Processing file %i / %i' % (i + 1, x)) mc.text(self.currentFileText, e=True, l='%s%s' % (myFile, myExt)) mc.refresh(f=True) if not os.path.isfile(texFileOut) or convertType == 2: MGlobal.displayInfo('[INFO] %s --> %s' % (texFileIn, texFileOut)) call('%s/maketx.exe %s "%s"' % (makeTxPath, flagString, texFileIn), shell=1 - showTerminal) # Check if the texture has been converted and add the errors to a list if not os.path.isfile(texFileOut): lErrors.append(texFileOut) elif convertType == 1: sourceFileDate = datetime.datetime.fromtimestamp( os.path.getmtime(texFileIn)) try: with open(texFileOut, 'r') as f: destFileDate = datetime.datetime.fromtimestamp( os.path.getmtime(texFileOut)) except: destFileDate = datetime.datetime.min if sourceFileDate > destFileDate: MGlobal.displayInfo('[INFO] %s updated' % (texFileOut)) call('%s/maketx.exe %s "%s"' % (makeTxPath, flagString, texFileIn), shell=1 - showTerminal) # Check if the texture has been converted and add the errors to a list if not os.path.isfile(texFileOut): lErrors.append(texFileOut) else: MGlobal.displayInfo('[INFO] %s is up to date' % (texFileOut)) else: MGlobal.displayInfo('[INFO] %s already present, skipped' % texFileOut) counter = counter + 1 mc.columnLayout(self.progressLayout, e=True, manage=False) if lErrors: MGlobal.displayInfo( '[ERROR] unable to write the following files: %s' % lErrors)
def cmdPrint(info): from maya.OpenMaya import MGlobal MGlobal.displayInfo('%s' % (info))
def convert(self, *args): # 0: 'Only not existing' # 1: 'Overwrite older' # 2: 'Overwrite all' # 0: from scene # 1: from folder flagString = '' lErrors = [] # SIMPLE for myCheckBox in self.simpleCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s ' % mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True) # INT for myCheckBox in self.intCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %i ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.intField('%sIntField' % myCheckBox, q=True, v=True)) # DOUBLE INT for myCheckBox in self.doubleIntCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %i %i ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.intField('%sIntFieldX' % myCheckBox, q=True, v=True), mc.intField('%sIntFieldY' % myCheckBox, q=True, v=True)) # FLOAT for myCheckBox in self.floatCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %f ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.floatField('%sFloatField' % myCheckBox, q=True, v=True)) # ENUM # for myCheckBox in self.enumCheckBoxes: # if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): # flagString += '%s %s ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.attrEnumOptionMenu('%sOptionMenu' % myCheckBox, q=True)) # OPTION MENU for myCheckBox in self.enumCheckBoxes: if mc.checkBox('%sCheckBox' % myCheckBox, q=True, v=True): flagString += '%s %s ' % (mc.checkBox('%sCheckBox' % myCheckBox, q=True, ann=True), mc.optionMenu('%sOptionMenu' % myCheckBox, q=True, v=True)) makeTxPath = mc.textFieldButtonGrp(self.pathTextField, q=True, fileName=True) convertType = mc.radioButtonGrp(self.convertBehaviorRadioButton, q=True, sl=True) - 1 sourceType = mc.radioButtonGrp(self.textureFrom, q=True, sl=True) - 1 showTerminal = mc.checkBox('verboseCheckBox', q=True, v=True) if not os.path.isfile('%s/maketx.exe' % makeTxPath): MGlobal.displayInfo('[ERROR] Unable to find makeTx.exe. Exit!') return if not len(mc.ls(type='file')) and not sourceType: MGlobal.displayInfo('[WARNING] No textures in current scene. Nothing to convert.') return myFileList = [] if sourceType: myTextureFolder = mc.textFieldButtonGrp(self.texturePathTextField, q=True, fileName=True) imageFormats = [ '.bmp', '.cin', '.dds', '.dpx', '.f3d', '.fits', '.hdr', '.hdri', '.ico', '.iff', '.jpg', '.jpeg', '.jif', '.jfif', '.jfi', '.jp2', '.j2k', '.exr', '.png', '.pbm', '.pgm', '.ppm', '.ptex', '.rla', '.sgi', '.rgb', '.rgba', '.pic', '.tga', '.tif', '.tiff' ] for (fileFolder, folders, files) in os.walk(myTextureFolder): for file in files: if os.path.splitext(file)[-1] in imageFormats: myFileList.append(os.path.join(fileFolder, file)) else: for fileNode in mc.ls(type='file'): myFileList.append(mc.getAttr('%s.fileTextureName' % fileNode)) #Setting up the progress bar. x = len(myFileList) counter = 0 mc.progressBar(self.progressControl, e=True, maxValue=x) mc.columnLayout(self.progressLayout, e=True, manage=True) mc.refresh(f=True) for i, texFileIn in enumerate(myFileList): myPath, myFile = os.path.split(texFileIn) myFile, myExt = os.path.splitext(myFile) texFileOut = '%s/%s.tx' % (myPath, myFile) progressInc = mc.progressBar(self.progressControl, edit=True, pr=counter) mc.text(self.currentNumberText, e=True, l='Processing file %i / %i' % (i+1, x)) mc.text(self.currentFileText, e=True, l='%s%s' % (myFile, myExt)) mc.refresh(f=True) if not os.path.isfile(texFileOut) or convertType == 2: MGlobal.displayInfo('[INFO] %s --> %s' % (texFileIn, texFileOut)) call('%s/maketx.exe %s "%s"' % (makeTxPath, flagString, texFileIn), shell=1 - showTerminal) # Check if the texture has been converted and add the errors to a list if not os.path.isfile(texFileOut): lErrors.append(texFileOut) elif convertType == 1: sourceFileDate = datetime.datetime.fromtimestamp(os.path.getmtime(texFileIn)) try: with open(texFileOut, 'r') as f: destFileDate = datetime.datetime.fromtimestamp(os.path.getmtime(texFileOut)) except: destFileDate = datetime.datetime.min if sourceFileDate > destFileDate: MGlobal.displayInfo('[INFO] %s updated' % (texFileOut)) call('%s/maketx.exe %s "%s"' % (makeTxPath, flagString, texFileIn), shell=1 - showTerminal) # Check if the texture has been converted and add the errors to a list if not os.path.isfile(texFileOut): lErrors.append(texFileOut) else: MGlobal.displayInfo('[INFO] %s is up to date' % (texFileOut)) else: MGlobal.displayInfo('[INFO] %s already present, skipped' % texFileOut) counter = counter + 1 mc.columnLayout(self.progressLayout, e=True, manage=False) if lErrors: MGlobal.displayInfo('[ERROR] unable to write the following files: %s' % lErrors)