当前位置: 首页>>代码示例>>Python>>正文


Python OpenMaya.MGlobal类代码示例

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


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


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