def moveObjectToOrigin(objectName=""): if not objectName: MGlobal.displayError("Please provide ObjectName") return False localPivot = cmds.xform(objectName , q=True, rotatePivot=True) worldPivot = cmds.xform(objectName , q=True, rotatePivot=True, worldSpace=True) posx = 0.0 posy = 0.0 posz = 0.0 if worldPivot[0] == localPivot[0]: posx = worldPivot[0] else: posx = worldPivot[0] - localPivot[0] if worldPivot[1] == localPivot[1]: posy = worldPivot[1] else: posy = worldPivot[1] - localPivot[1] if worldPivot[2] == localPivot[2]: posz = worldPivot[2] else: posz = worldPivot[2] - localPivot[2] cmds.move(-posx, -posy, -posz, objectName, absolute=True)
def exportObjectAsAssFile(location="", objectName=""): if objectName == "": MGlobal.displayWarning("No object exported!!!") return False else: cmds.select(objectName, r=True) cmds.file(location + "/" + objectName, type="mayaBinary", force=True, exportSelected=True) return True
def exportObjectAsMbFile(location="", objectName=""): if objectName == "": MGlobal.displayWarning("No object exported!!!") return False else: print(objectName) cmds.select(objectName, replace=True) cmds.file(location + "/" + objectName, exportSelected=True, type="mayaBinary", constructionHistory=False, force=True) return True
def setLevelHook(level, *args, **kwargs): levelName = levelToName(level) level = nameToLevel(level) ret = func(level, *args, **kwargs) pymelLogger.info("Log Level Changed to '%s'" % levelName) try: # save the preference as a string name, for human readability # we need to use MGlobal because cmds.optionVar might not exist yet MGlobal.setOptionVarValue( LOGLEVEL_OPTVAR, levelName ) except Exception, e: pymelLogger.warning("Log Level could not be saved to the user-prefs ('%s')" % e)
def initializePlugin( mobject ): mplugin = OpenMayaMPx.MFnPlugin( mobject, 'macaronikazoo', '1' ) try: mplugin.registerNode( MirrorNode.NODE_TYPE_NAME, MirrorNode.NODE_ID, MirrorNode.Creator, MirrorNode.Init ) mplugin.registerNode( ControlPairNode.NODE_TYPE_NAME, ControlPairNode.NODE_ID, ControlPairNode.Creator, ControlPairNode.Init ) mplugin.registerCommand( CreateMirrorNode.CMD_NAME, CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator ) mplugin.registerCommand( CreateMirrorNode.CMD_NAME.lower(), CreateMirrorNode.Creator, CreateMirrorNode.SyntaxCreator ) except: MGlobal.displayError( "Failed to load zooMirror plugin:" ) raise
def uninitializePlugin( mobject ): mplugin = OpenMayaMPx.MFnPlugin( mobject ) try: mplugin.deregisterNode( MirrorNode.NODE_ID ) mplugin.deregisterNode( ControlPairNode.NODE_ID ) mplugin.deregisterCommand( CreateMirrorNode.CMD_NAME ) mplugin.deregisterCommand( CreateMirrorNode.CMD_NAME.lower() ) except: MGlobal.displayError( "Failed to unload zooMirror plugin:" ) raise
def movePivotToBottomCenter(objectName=""): if not objectName: MGlobal.displayError("Please provide ObjectName") return False boxMin = cmds.getAttr(objectName + ".boundingBoxMin")[0] boxMax = cmds.getAttr(objectName + ".boundingBoxMax")[0] posx = (boxMax[0] + boxMin[0]) / 2 posy = boxMin[1] posz = (boxMax[2] + boxMin[2]) / 2 bottomCenter = [posx, posy, posz] cmds.xform(objectName, piv=bottomCenter, ws=True) return True
def _setupLevelPreferenceHook(): """Sets up a callback so that the last used log-level is saved to the user preferences file""" LOGLEVEL_OPTVAR = 'pymel.logLevel' # retrieve the preference as a string name, for human readability. # we need to use MGlobal because cmds.optionVar might not exist yet # TODO : resolve load order for standalone. i don't think that userPrefs is loaded yet at this point in standalone. levelName = os.environ.get( PYMEL_LOGLEVEL_ENV_VAR, MGlobal.optionVarStringValue( LOGLEVEL_OPTVAR ) ) if levelName: level = min( logging.WARNING, nameToLevel(levelName) ) # no more than WARNING level pymelLogger.setLevel(level) pymelLogger.info("setting logLevel to user preference: %s (%d)" % (levelName, level) ) func = pymelLogger.setLevel def setLevelHook(level, *args, **kwargs): levelName = levelToName(level) level = nameToLevel(level) ret = func(level, *args, **kwargs) pymelLogger.info("Log Level Changed to '%s'" % levelName) try: # save the preference as a string name, for human readability # we need to use MGlobal because cmds.optionVar might not exist yet MGlobal.setOptionVarValue( LOGLEVEL_OPTVAR, levelName ) except Exception, e: pymelLogger.warning("Log Level could not be saved to the user-prefs ('%s')" % e) return ret
def reset( maxRange ): global _uiProgress _uiProgress = (MGlobal.mayaState() == MGlobal.kInteractive) if _uiProgress: MProgressWindow.reserve() MProgressWindow.setProgressRange( 0, maxRange ) MProgressWindow.setProgress( 0 ) MProgressWindow.startProgress() MProgressWindow.setInterruptable( True )
def ikHandle(*args, **kwargs): """ Modifications: - always converts to PyNodes in create mode, even though results are non-unique short names """ import nodetypes from maya.OpenMaya import MGlobal res = cmds.ikHandle(*args, **kwargs) # unfortunately, ikHandle returns non-unique names... however, it # doesn't support a parent option - so we can just throw a '|' in front # of the first return result (the ikHandle itself) to get a unique name # We then need to track through it's connections to find the endEffector... if kwargs.get('query', kwargs.get('q', False)): if kwargs.get('endEffector', kwargs.get('ee', False)): res = _factories.toPyNode(res) elif kwargs.get('jointList', kwargs.get('jl', False)): res = _factories.toPyNodeList(res) elif (not kwargs.get('edit', kwargs.get('e', False)) and isinstance(res, list) and len(res) == 2 and all(isinstance(x, basestring) for x in res)): handleName, effectorName = res # ikHandle doesn't support a parent kwarg, so result should always be # grouped under the world... handleNode = _factories.toPyNode('|' + handleName) # unfortunately, effector location is a little harder to predict. but # can find it by following connections... effectorNode = handleNode.attr('endEffector').inputs()[0] if effectorNode.nodeName() == effectorName: res = [handleNode, effectorNode] else: MGlobal.displayWarning( "Warning: returned ikHandle %r was connected to effector %r, " "which did not match returned effector name %r" % (handleName, effectorNode.shortName(), effectorName)) return res
def parseVersionStr(versionStr, extension=False): """ Parse a verbose version string (like the one displayed in the Maya title bar) and return the base version. :Parameters: extension : `bool` if True, leave the -x64 tag >>> from pymel.all import * >>> versions.parseVersionStr('2008 Service Pack1 x64') '2008' >>> versions.parseVersionStr('2008 Service Pack1 x64', extension=True) '2008-x64' >>> versions.parseVersionStr('2008x64', extension=True) '2008-x64' >>> versions.parseVersionStr('8.5', extension=True) '8.5' >>> versions.parseVersionStr('2008 Extension 2') '2008' >>> versions.parseVersionStr('/Applications/Autodesk/maya2009/Maya.app/Contents', extension=True) '2009' >>> versions.parseVersionStr('C:\Program Files (x86)\Autodesk\Maya2008', extension=True) '2008' """ if 'Preview' in versionStr: # Beta versions of Maya may use the format 'Preview Release nn x64', which # doesn't contain the actual Maya version. If we have one of those, we'll # make up the version from the API version. Not foolproof, but should work # in most cases. version = str(_MGlobal.apiVersion())[0:4] if extension and bitness() == 64: version += '-x64' else: # problem with service packs addition, must be able to match things such as : # '2008 Service Pack 1 x64', '2008x64', '2008', '8.5' # NOTE: we're using the same regular expression (parseVersionStr) to parse both the crazy human readable # maya versions as returned by about, and the maya location directory. to handle both of these i'm afraid # the regular expression might be getting unwieldy ma = re.search("((?:maya)?(?P<base>[\d.]{3,})(?:(?:[ ].*[ ])|(?:-))?(?P<ext>x[\d.]+)?)", versionStr) version = ma.group('base') if extension and (ma.group('ext') is not None): version += "-" + ma.group('ext') return version
def _printToScriptEditor(self): MGlobal.displayInfo(str(self.values))
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 info(msg): return MGlobal.displayInfo(msg)
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))
def getDagPathFromName(in_name): selector = MSelectionList() MGlobal.getSelectionListByName(in_name, selector) path = MDagPath() selector.getDagPath(0, path) return path
def isZAxisUp(): """Returns True if Z is world up :return: bool """ return MGlobal.isZAxisUp()
def print_maya(str_to_print): """ Print to Maya Script Editor as python comment """ MGlobal.displayInfo(str_to_print)
SPACE_LOCAL = rigUtils.SPACE_LOCAL SPACE_OBJECT = rigUtils.SPACE_OBJECT Axis = rigUtils.Axis CONTROL_DIRECTORY = None if CONTROL_DIRECTORY is None: #try to determine the directory that contains the control macros for f in Path( __file__ ).up().files( recursive=True ): if f.hasExtension( 'shape' ): if f.name().startswith( 'control' ): CONTROL_DIRECTORY = f.up() break if CONTROL_DIRECTORY is None: MGlobal.displayError( "WARNING: Cannot determine the directory that contains the .control files - please open '%s' and set the CONTROL_DIRECTORY variable appropriately" % __file__ ) AX_X, AX_Y, AX_Z, AX_X_NEG, AX_Y_NEG, AX_Z_NEG = map( Axis, range( 6 ) ) DEFAULT_AXIS = AX_X AXIS_ROTATIONS = { AX_X: (0, 0, -90), AX_Y: (0, 0, 0), AX_Z: (90, 0, 0), AX_X_NEG: (0, 0, 90), AX_Y_NEG: (180, 0, 0), AX_Z_NEG: (-90, 0, 0) } class ShapeDesc(object): ''' store shape preferences about a control
def error(msg, showLineNumber=False): #return mel.error(msg, showLineNumber) return MGlobal.displayError(msg)
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 isYAxisUp(): """returns True if y is world up :return: bool """ return MGlobal.isYAxisUp()
import time start =time.time() from maya.utils import executeDeferred from maya.cmds import pluginInfo,loadPlugin,warning,evalDeferred,unloadPlugin import fantabox as fb from fantabox.FantaBoxMenu import * import maya.mel as mel from subprocess import Popen, PIPE def documentsLocation(): handle = Popen('reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v personal', shell=True, stdout=PIPE) hostid = handle.communicate()[0] handle.kill return hostid.split( 'REG_SZ')[1].strip() from maya.OpenMaya import MGlobal as _MGlobal mayaver = str(_MGlobal.apiVersion())[0:4] def pluginload(): if pluginInfo("mtoa",q=1,loaded=1,name=1)==0: try: loadPlugin("mtoa") except: warning("no arnold!!") try: print "a" #evalDeferred('''cmds.unloadPlugin("pgYetiMaya",f=1)''' ) #evalDeferred('''cmds.loadPlugin("pgYetiMaya")''' ) except: warning("no pgYetiMaya!!") def mtoasetting(): hostname = documentsLocation()
def checkAndLoadPlugin(pluginName=""): if not cmds.pluginInfo(pluginName, query=True, loaded=True): cmds.loadPlugin(pluginName) MGlobal.displayInfo("plugin " + pluginName + " loaded success")
# -*- 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 getNodeFromName(in_name): selector = MSelectionList() MGlobal.getSelectionListByName(in_name, selector) node = MObject() selector.getDependNode(0, node) return node
def mayaUpVector(): """Gets the current world up vector :rtype: pw.libs.utils.vectors.Vector """ return MGlobal.upAxis()
def cmdPrint(info): from maya.OpenMaya import MGlobal MGlobal.displayInfo('%s' % (info))
def mayaNodeGetMat44(a): l = MSelectionList() MGlobal.getSelectionListByName(a, l) p = MDagPath() l.getDagPath(0, p) return mmatrixToMat44(p.inclusiveMatrix())
version += "-" + ma.group('ext') return version def bitness(): """ The bitness of python running inside Maya as an int. """ # NOTE: platform.architecture()[0] returns '64bit' on OSX 10.6 (Snow Leopard) # even when Maya is running in 32-bit mode. The struct technique # is more reliable. return struct.calcsize("P") * 8 _is64 = bitness() == 64 _current = _MGlobal.apiVersion() _fullName = _MGlobal.mayaVersion() _shortName = parseVersionStr(_fullName, extension=False) _installName = _shortName + ('-x64' if _is64 else '') v85 = 200700 v85_SP1 = 200701 v2008 = 200800 v2008_SP1 = 200806 v2008_EXT2 = 200806 v2009 = 200900 v2009_EXT1 = 200904 v2009_SP1A = 200906 v2010 = 201000 v2011 = 201100 v2011_HOTFIX1 = 201101
def __init__(self, obj): args = [self, obj, zRigHandleDrawOverride.draw] if MGlobal.apiVersion() >= 201700: # This argument is only present in 2017, and improves performance substantially. args.append(False) omr.MPxDrawOverride.__init__(*args)
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)
from metan.datatype.quaternion import Quaternion from metan.datatype.vector import Vector class TESTMObjectHandle(object): u"""これは仮のMObjectHandleです """ def __init__(self, *args, **kws): pass def isValid(self): return True # todo: バージョンで分けるような処理はここじゃなくてファイルを別にする current_version = _api1_MGlobal.apiVersion() _MFn_MFnSkinCluster = om.MFnDependencyNode _MFn_MFnAnimCurve = om.MFnDependencyNode _MFn_MObjectHandle = TESTMObjectHandle if current_version >= 201600: _MFn_MFnSkinCluster = oma.MFnSkinCluster _MFn_MFnAnimCurve = oma.MFnAnimCurve _MFn_MObjectHandle = om.MObjectHandle def to_string(args): _args = [] for arg in args: if hasattr(arg, "metan_class"): _args.append(str(arg))
if extension and (ma.group('ext') is not None): version += "-" + ma.group('ext') return version def bitness(): """ The bitness of python running inside Maya as an int. """ # NOTE: platform.architecture()[0] returns '64bit' on OSX 10.6 (Snow Leopard) # even when Maya is running in 32-bit mode. The struct technique # is more reliable. return struct.calcsize("P") * 8 _is64 = bitness() == 64 _current = _MGlobal.apiVersion() _fullName = _MGlobal.mayaVersion() _shortName = parseVersionStr(_fullName, extension=False) _installName = _shortName + ('-x64' if (_is64 and _current < 201600) else '') v85 = 200700 v85_SP1 = 200701 v2008 = 200800 v2008_SP1 = 200806 v2008_EXT2 = 200806 v2009 = 200900 v2009_EXT1 = 200904 v2009_SP1A = 200906 v2010 = 201000 v2011 = 201100
def mode(self): return MGlobal.selectionMode()
# QT5 moved a bunch of stuff around, moving some things from QtGui into QtWidgets. # This means that in order to make their API slightly "prettier", QT created a ton # of useless busywork for thousands of developers, and makes compatibility with Qt4 # and Qt5 painful. I couldn't care less about which module these are in, so work # around this by flattening everything into one module. from maya.OpenMaya import MGlobal if MGlobal.apiVersion() >= 201700: from PySide2.QtCore import * from PySide2.QtGui import * from PySide2.QtWidgets import * from shiboken2 import wrapInstance import pyside2uic as pysideuic else: from PySide.QtCore import * from PySide.QtGui import * from shiboken import wrapInstance import pysideuic as pysideuic