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


Python OpenMaya.MFnDagNode方法代码示例

本文整理汇总了Python中maya.api.OpenMaya.MFnDagNode方法的典型用法代码示例。如果您正苦于以下问题:Python OpenMaya.MFnDagNode方法的具体用法?Python OpenMaya.MFnDagNode怎么用?Python OpenMaya.MFnDagNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在maya.api.OpenMaya的用法示例。


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

示例1: cloneMeshs

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def cloneMeshs(meshPaths):
    cloneMeshPaths = []
    cloneGroup = cmds.group(empty = True, world = True, name = 'ssdsResult')
    cloneGroupSL = om.MGlobal.getSelectionListByName(cloneGroup)
    cloneGroupFn = om.MFnTransform(cloneGroupSL.getDagPath(0))
    for path in meshPaths:
        mesh = om.MFnMesh(path)
        meshName = om.MFnDagNode(mesh.parent(0)).name()
        cloneMeshName = 'ssds:' + meshName
        sl = om.MSelectionList();
        sl.clear()
        sl.add(path)
        om.MGlobal.setActiveSelectionList(sl)
        cmds.duplicate(returnRootsOnly = True, name = cloneMeshName, renameChildren = True)
        cmds.parent(cloneMeshName, cloneGroup)
        cmds.setAttr(cloneMeshName + '.inheritsTransform', False)
        cloneMeshSL = om.MGlobal.getSelectionListByName(cloneMeshName)
        cloneMeshPath = cloneMeshSL.getDagPath(0)
        cloneMeshPath.extendToShape()
        cloneMeshPaths.append(cloneMeshPath)
    return cloneMeshPaths, cloneGroup 
开发者ID:TomohikoMukai,项目名称:ssds,代码行数:23,代码来源:main.py

示例2: test_superclass

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def test_superclass():
    """cmdx.Node(dagmobject) creates a DagNode"""

    # Using the right class works
    mobj = om.MFnDagNode().create("transform")
    node = cmdx.DagNode(mobj)
    assert isinstance(node, cmdx.DagNode)

    mobj = om.MFnDependencyNode().create("polySplit")
    node = cmdx.Node(mobj)
    assert isinstance(node, cmdx.Node)

    # Using the wrong class works too
    mobj = om.MFnDagNode().create("transform")
    node = cmdx.Node(mobj)
    assert isinstance(node, cmdx.DagNode)

    mobj = om.MFnDependencyNode().create("polySplit")
    node = cmdx.DagNode(mobj)
    assert isinstance(node, cmdx.Node) 
开发者ID:mottosso,项目名称:cmdx,代码行数:22,代码来源:tests.py

示例3: ownerInfo

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def ownerInfo(self):
        '''
        Returns the node that has this as a sub control and the key to access it.
        '''
        
        obj = core.capi.asMObject(self)
        
        msgplug = obj.findPlug('message', False)

        for con in msgplug.connectedTo(False, True):
            if con.name().endswith('controlLink'):
                #node, plug = con.name().split('.', 1)
                
                # Can't remember why I did this but is seems fine.
                plug = con.partialName( useFullAttributePath=True, useLongNames=True)
                node = OpenMaya.MFnDagNode( con.node() ).fullPathName()

                return PyNode(node), getAttr( (node + '.' + plug)[:-11] + 'controlName' ) 
开发者ID:patcorwin,项目名称:fossil,代码行数:20,代码来源:fossilNodes.py

示例4: bindToSkin

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def bindToSkin(meshPaths, skinIndex, skinWeight,
              skinJnts, numMaxInfluences):
    asl = om.MSelectionList()
    asl.clear()
    jntNames = [sj.name for sj in skinJnts]
    for sj in skinJnts:
        m = om.MMatrix(sj.bindPose.tolist())
        m = om.MTransformationMatrix(m)
        om.MFnTransform(sj.path).setTransformation(m)
        asl.add(sj.path)
    offset = 0
    for meshPath in meshPaths:
        mesh = om.MFnMesh(meshPath)
        sl = om.MSelectionList(asl)
        sl.add(meshPath)
        om.MGlobal.setActiveSelectionList(sl)
        meshName = om.MFnDagNode(mesh.parent(0)).name()
        skinName = cmds.skinCluster(maximumInfluences = numMaxInfluences,
                                    name = meshName + 'Cluster',
                                    toSelectedBones = True)[0]
        skinObj = om.MGlobal.getSelectionListByName(skinName).getDependNode(0)
        skin = oma.MFnSkinCluster(skinObj)
        vertexIndices = om.MIntArray(mesh.numVertices, 0)
        for i in xrange(mesh.numVertices):
            vertexIndices[i] = i
        singleIndexedComp = om.MFnSingleIndexedComponent()
        vertexComp = singleIndexedComp.create(om.MFn.kMeshVertComponent)
        singleIndexedComp.addElements(vertexIndices)
        infDags = skin.influenceObjects()
        numInfDags = len(infDags)
        infIndices = om.MIntArray(numInfDags, 0)
        for i in xrange(numInfDags):
            infIndices[i] = i
        weights = om.MDoubleArray(mesh.numVertices * numInfDags, 0)
        for v in xrange(mesh.numVertices):
            for j, w in zip(skinIndex[offset + v], skinWeight[offset + v]):
                if j >= 0:
                    weights[v * numInfDags + j] = w
        skin.setWeights(meshPath, vertexComp, infIndices, weights)
        offset += mesh.numVertices 
        skin.findPlug('deformUserNormals', True).setBool(False) 
开发者ID:TomohikoMukai,项目名称:ssds,代码行数:43,代码来源:main.py

示例5: test_createNode_performance

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def test_createNode_performance():
    """createNode cmdx vs cmds > 2x"""

    versions = (
        ("mel", lambda: mel.eval("createNode \"transform\"")),
        ("cmds", lambda: cmds.createNode("transform")),
        ("cmdx", lambda: cmdx.createNode(cmdx.tTransform)),
        # ("PyMEL", lambda: pm.createNode("transform")),
        ("API 1.0", lambda: om1.MFnDagNode().create("transform")),
        ("API 2.0", lambda: om2.MFnDagNode().create("transform")),
    )

    for contender, test in versions:
        Compare(contender, "createNode", test, setup=New)

    cmdx_vs_cmds = (
        timings["createNode"]["cmds"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    cmdx_vs_api = (
        timings["createNode"]["API 2.0"]["percall"] /
        timings["createNode"]["cmdx"]["percall"]
    )

    assert_greater(cmdx_vs_cmds, 0.5)  # at most 2x slower than cmds
    assert_greater(cmdx_vs_api, 0.20)  # at most 5x slower than API 2.0 
开发者ID:mottosso,项目名称:cmdx,代码行数:29,代码来源:test_performance.py

示例6: editCurve

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def editCurve(parent, points, degree=1, form=kOpen):
    assert isinstance(parent, DagNode), (
        "parent must be of type cmdx.DagNode"
    )

    degree = min(3, max(1, degree))

    cvs = om1.MPointArray()
    curveFn = om1.MFnNurbsCurve()

    for point in points:
        cvs.append(om1.MPoint(*point))

    mobj = curveFn.createWithEditPoints(cvs,
                                        degree,
                                        form,
                                        False,
                                        False,
                                        True,
                                        _encode1(parent.path()))

    mod = om1.MDagModifier()
    mod.renameNode(mobj, parent.name(namespace=True) + "Shape")
    mod.doIt()

    def undo():
        mod.deleteNode(mobj)
        mod.doIt()

    def redo():
        mod.undoIt()

    commit(undo, redo)

    shapeFn = om1.MFnDagNode(mobj)
    return encode(shapeFn.fullPathName()) 
开发者ID:mottosso,项目名称:cmdx,代码行数:38,代码来源:cmdx.py

示例7: createCallbacks

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def createCallbacks(self):
        # frame changed callback
        # needed for changing the relative keyframe display
        self.mTimeCallbackId = om.MEventMessage.addEventCallback('timeChanged', self.setRelativeFrames)
        # iterate over all cameras add the callback
        dgIter = om.MItDependencyNodes(om.MFn.kCamera)
        while not dgIter.isDone():
            shape = om.MFnDagNode(dgIter.thisNode())
            transform = shape.parent(0)
            if transform is not None:
                self.mCameraMovedCallbackIds.append(
                    om.MNodeMessage.addAttributeChangedCallback(transform, self.cameraMovedCB))
            dgIter.next()

    # removing them when the ui is closed 
开发者ID:Viele,项目名称:onionSkinRenderer,代码行数:17,代码来源:onionSkinRendererCore.py

示例8: keyObjectsFromContainer

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def keyObjectsFromContainer(containerHandle, componentName):
    """

    :param containerHandle: `MObjectHandle`
    :param componentName: `str` mandatory now, used to compose full name of some exepcted items/paths
    :return: `dict` k,v pairs for interesting objects and their handle, None if unavailable
    """

    mfn_cont = om2.MFnContainerNode(containerHandle.object())
    mobaMembers = mfn_cont.getMembers()

    keyObsDict = {
        'control':None,
        'guide':None,
        'deform':None,
        '{}_toolParameters'.format(componentName):None,
    }

    for eachMob in mobaMembers:
        if not eachMob.hasFn(om2.MFn.kDagNode):
            continue

        mfn_dag = om2.MFnDagNode(eachMob)

        objectName = mfn_dag.name()

        if objectName in keyObsDict:
            keyObsDict[objectName] = om2.MObjectHandle(eachMob)

    return keyObsDict 
开发者ID:CultOfRig,项目名称:didactic,代码行数:32,代码来源:s01_d023_retrievingContainedObjects.py

示例9: keyObjectsFromContainer

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def keyObjectsFromContainer(containerHandle, componentName):
    """
    :param containerHandle: `MObjectHandle`
    :param componentName: `str` mandatory now, used to compose full name of some exepcted items/paths
    :return: `dict` k,v pairs for interesting objects and their handle, None if unavailable
    """

    mfn_cont = om2.MFnContainerNode(containerHandle.object())
    mobaMembers = mfn_cont.getMembers()

    keyObsDict = {
        'componentName': componentName,
        'control':None,
        'guide':None,
        'deform':None,
        'toolParameters':None,
    }

    for eachMob in mobaMembers:
        if not eachMob.hasFn(om2.MFn.kDagNode):
            continue

        mfn_dag = om2.MFnDagNode(eachMob)

        objectName = mfn_dag.name()

        if objectName == 'control':
            keyObsDict['control'] = om2.MObjectHandle(eachMob)
        elif objectName == 'guide':
            keyObsDict['guide'] = om2.MObjectHandle(eachMob)
        elif objectName == 'control':
            keyObsDict['deform'] = om2.MObjectHandle(eachMob)
        elif objectName == '{}_toolParameters'.format(componentName):
            # todo: the above string composition running every loop is an abomination
            keyObsDict['toolParameters'] = om2.MObjectHandle(eachMob)

    return keyObsDict 
开发者ID:CultOfRig,项目名称:didactic,代码行数:39,代码来源:s01_d025_swappingPlugs.py

示例10: keyObjectsFromContainer

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def keyObjectsFromContainer(containerHandle, componentName):
    """

    :param containerHandle: `MObjectHandle`
    :param componentName: `str` mandatory now, used to compose full name of some exepcted items/paths
    :return: `dict` k,v pairs for interesting objects and their handle, None if unavailable
    """

    mfn_cont = om2.MFnContainerNode(containerHandle.object())
    mobaMembers = mfn_cont.getMembers()

    keyObsDict = {
        'componentName': componentName,
        'control':None,
        'guide':None,
        'deform':None,
        'toolParameters':None,
    }

    for eachMob in mobaMembers:
        if not eachMob.hasFn(om2.MFn.kDagNode):
            continue

        mfn_dag = om2.MFnDagNode(eachMob)

        objectName = mfn_dag.name()

        if objectName == 'control':
            keyObsDict['control'] = om2.MObjectHandle(eachMob)
        elif objectName == 'guide':
            keyObsDict['guide'] = om2.MObjectHandle(eachMob)
        elif objectName == 'control':
            keyObsDict['deform'] = om2.MObjectHandle(eachMob)
        elif objectName == '{}_toolParameters'.format(componentName):
            # todo: the above string composition running every loop is an abomination
            keyObsDict['toolParameters'] = om2.MObjectHandle(eachMob)

    return keyObsDict 
开发者ID:CultOfRig,项目名称:didactic,代码行数:40,代码来源:s01_d027_finishingPlugCases.py

示例11: keyObjectsFromContainer

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def keyObjectsFromContainer(componentName, containerHandle):
    """
    This takes a component name for some filtering and a container handle and isolates
      the key objects related to it that represent our component interesting items.
    :param componentName: `str` mandatory now, used to compose full name of some exepcted items/paths
    :param containerHandle: `MObjectHandle`
    :return: `dict` k,v pairs for interesting objects and their handle, None if unavailable
    """

    mfn_cont = om2.MFnContainerNode(containerHandle.object())
    mobaMembers = mfn_cont.getMembers()

    keyObsDict = {
        'componentName': componentName,
        'control':None,
        'guide':None,
        'deform':None,
        'toolParameters':None,
    }

    for eachMob in mobaMembers:
        if not eachMob.hasFn(om2.MFn.kDagNode):
            continue

        mfn_dag = om2.MFnDagNode(eachMob)

        objectName = mfn_dag.name()

        if objectName == 'control':
            keyObsDict['control'] = om2.MObjectHandle(eachMob)
        elif objectName == 'guide':
            keyObsDict['guide'] = om2.MObjectHandle(eachMob)
        elif objectName == 'deform':
            keyObsDict['deform'] = om2.MObjectHandle(eachMob)
        elif objectName == '{}_toolParameters'.format(componentName):
            # todo: the above string composition running every loop is an abomination
            keyObsDict['toolParameters'] = om2.MObjectHandle(eachMob)

    return keyObsDict 
开发者ID:CultOfRig,项目名称:didactic,代码行数:41,代码来源:s01_d030_makeUsable.py

示例12: nodes

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def nodes(self):
        # The nodes function will filter through the nodes and make sure we only give back valid nodes
        validNodes = []

        # The selection list will help us validate whether a node exists or not
        sel = om.MSelectionList()

        # Lets iterate through the node list we've captured
        for node in self.__nodes:
            # If the node is null, it means the MObject no longer points to valid data so we can ignore it
            if node.isNull():
                continue

            # We now have to get the path of the node
            # If the node is a dagNode (checked by seeing if it has that function set)
            # Then we need to get its shortest unique path
            if node.hasFn(om.MFn.kDagNode):
                # We create an MFnDagNode for it
                dag = om.MFnDagNode(node)
                # The partial path is the shortest unique name to the object
                # A full path can be wasteful in terms of memory
                # But just the name can lead to ambiguity if multiple objects share the name
                # The partial path instead gives us the shortest name we know to be unique
                path = dag.partialPathName()
            else:
                # If it isn't a DAGNode, then it's a DG node and always has a unique name
                dg = om.MFnDependencyNode(node)
                path = dg.name()

            # Even once we have the path, it may not exist anymore (if deleted etc)
            # We'll try and add it to the selection list and if it fails to add then we'll assume it no longer exists
            try:
                sel.add(path)
            except:
                continue

            # Then add it to the validNodes list
            validNodes.append(path)

        # Finally return the node list
        return validNodes 
开发者ID:dgovil,项目名称:AdvancedPythonForMaya,代码行数:43,代码来源:createdNodesContext.py

示例13: lsattrs

# 需要导入模块: from maya.api import OpenMaya [as 别名]
# 或者: from maya.api.OpenMaya import MFnDagNode [as 别名]
def lsattrs(attrs):
    """Return nodes with the given attribute(s).

    Arguments:
        attrs (dict): Name and value pairs of expected matches

    Example:
        >> # Return nodes with an `age` of five.
        >> lsattr({"age": "five"})
        >> # Return nodes with both `age` and `color` of five and blue.
        >> lsattr({"age": "five", "color": "blue"})

    Return:
         list: matching nodes.

    """

    dep_fn = om.MFnDependencyNode()
    dag_fn = om.MFnDagNode()
    selection_list = om.MSelectionList()

    first_attr = attrs.iterkeys().next()

    try:
        selection_list.add("*.{0}".format(first_attr),
                           searchChildNamespaces=True)
    except RuntimeError as exc:
        if str(exc).endswith("Object does not exist"):
            return []

    matches = set()
    for i in range(selection_list.length()):
        node = selection_list.getDependNode(i)
        if node.hasFn(om.MFn.kDagNode):
            fn_node = dag_fn.setObject(node)
            full_path_names = [path.fullPathName()
                               for path in fn_node.getAllPaths()]
        else:
            fn_node = dep_fn.setObject(node)
            full_path_names = [fn_node.name()]

        for attr in attrs:
            try:
                plug = fn_node.findPlug(attr, True)
                if plug.asString() != attrs[attr]:
                    break
            except RuntimeError:
                break
        else:
            matches.update(full_path_names)

    return list(matches) 
开发者ID:getavalon,项目名称:core,代码行数:54,代码来源:lib.py


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