• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python OpenMaya.MGlobal类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中maya.OpenMaya.MGlobal的典型用法代码示例。如果您正苦于以下问题:Python MGlobal类的具体用法?Python MGlobal怎么用?Python MGlobal使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了MGlobal类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: moveObjectToOrigin

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)
开发者ID:yes7rose,项目名称:maya_utils,代码行数:27,代码来源:maya_utils.py


示例2: exportObjectAsAssFile

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
开发者ID:yes7rose,项目名称:maya_utils,代码行数:9,代码来源:maya_utils.py


示例3: exportObjectAsMbFile

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
开发者ID:yes7rose,项目名称:maya_utils,代码行数:10,代码来源:maya_utils.py


示例4: uninitializePlugin

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
开发者ID:GuidoPollini,项目名称:MuTools,代码行数:12,代码来源:zooMirror.py


示例5: initializePlugin

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
开发者ID:GuidoPollini,项目名称:MuTools,代码行数:12,代码来源:zooMirror.py


示例6: setLevelHook

    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)
开发者ID:0xb1dd1e,项目名称:PipelineConstructionSet,代码行数:12,代码来源:plogging.py


示例7: movePivotToBottomCenter

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
开发者ID:yes7rose,项目名称:maya_utils,代码行数:15,代码来源:maya_utils.py


示例8: _setupLevelPreferenceHook

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
开发者ID:0xb1dd1e,项目名称:PipelineConstructionSet,代码行数:30,代码来源:plogging.py


示例9: reset

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 )
开发者ID:redpawfx,项目名称:uninstancer,代码行数:9,代码来源:Progress.py


示例10: ikHandle

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
开发者ID:LumaPictures,项目名称:pymel,代码行数:39,代码来源:animation.py


示例11: parseVersionStr

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
开发者ID:LumaPictures,项目名称:pymel,代码行数:48,代码来源:versions.py


示例12: and

        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
开发者ID:LumaPictures,项目名称:pymel,代码行数:30,代码来源:versions.py


示例13: getDagPathFromName

def getDagPathFromName(in_name):
    selector = MSelectionList()
    MGlobal.getSelectionListByName(in_name, selector)
    path = MDagPath()
    selector.getDagPath(0, path)
    return path
开发者ID:yes7rose,项目名称:maya_utils,代码行数:6,代码来源:maya_utils.py


示例14: getNodeFromName

def getNodeFromName(in_name):
    selector = MSelectionList()
    MGlobal.getSelectionListByName(in_name, selector)
    node = MObject()
    selector.getDependNode(0, node)
    return node
开发者ID:yes7rose,项目名称:maya_utils,代码行数:6,代码来源:maya_utils.py


示例15: checkAndLoadPlugin

def checkAndLoadPlugin(pluginName=""):
    if not cmds.pluginInfo(pluginName, query=True, loaded=True):
        cmds.loadPlugin(pluginName)
        MGlobal.displayInfo("plugin " + pluginName + " loaded success")
开发者ID:yes7rose,项目名称:maya_utils,代码行数:4,代码来源:maya_utils.py


示例16: error

def error(msg, showLineNumber=False):
	#return mel.error(msg, showLineNumber)
	return MGlobal.displayError(msg)
开发者ID:jedmao,项目名称:maya-scripts,代码行数:3,代码来源:general.py


示例17: __init__

	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)
开发者ID:zewt,项目名称:zRigHandle,代码行数:6,代码来源:zRigHandle.py


示例18: info

def info(msg):
	return MGlobal.displayInfo(msg)
开发者ID:jedmao,项目名称:maya-scripts,代码行数:2,代码来源:general.py


示例19: Path

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
开发者ID:BGCX261,项目名称:zootoolbox-svn-to-git,代码行数:31,代码来源:control.py


示例20: convert

    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:
#.........这里部分代码省略.........
开发者ID:mkolar,项目名称:Tapp,代码行数:101,代码来源:nMakeTx.py



注:本文中的maya.OpenMaya.MGlobal类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cmds.about函数代码示例发布时间:2022-05-27
下一篇:
Python maya.OpenMayaMPx类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap