Python maya.cmds 模块,listConnections() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用maya.cmds.listConnections()

项目:config    作者:mindbender-studio    | 项目源码 | 文件源码
def transfer_outgoing_connections(src, dst):
    """Connect outgoing connections from `src` to `dst`

    Connections that cannot be made are ignored.

    Arguments:
        src (str): Absolute path to source node
        dst (str): Absolute path to destination node

    """

    for destination in cmds.listConnections(src,
                                            source=False,
                                            plugs=True) or []:
        for source in cmds.listConnections(destination,
                                           destination=False,
                                           plugs=True) or []:
            try:
                cmds.connectAttr(source.replace(src, dst),
                                 destination, force=True)
            except RuntimeError:
                continue
项目:surume    作者:tm8r    | 项目源码 | 文件源码
def get_unused_utility_nodes():
    u"""?????????????????????

    :return: ??????????????????
    :rtype: list of unicode
    """
    utility_node_types = cmds.listNodeTypes("utility")
    utility_nodes = []
    for ul in utility_node_types:
        nodes = cmds.ls(type=ul)
        if not nodes:
            continue
        utility_nodes.extend(nodes)

    unused = []
    for u in utility_nodes:
        if not [x for x in cmds.listConnections(u) if x != "defaultRenderUtilityList1"]:
            unused.append(u)
    return unused
项目:surume    作者:tm8r    | 项目源码 | 文件源码
def get_unused_shading_engines():
    u"""????ShadingEngine???????

    :return: ????ShadingEngine????
    :rtype: list of unicode
    """
    shading_engines = cmds.ls(type="shadingEngine")

    unused_shading_engines = []
    for s in shading_engines:
        if s in _DEFAULT_SHADING_ENGINES:
            continue
        unused = True
        for c in cmds.listConnections(s):
            node_type = cmds.nodeType(c)
            if "shader" in cmds.getClassification(node_type)[0]:
                unused = False
                break
        if unused:
            unused_shading_engines.append(s)
    return unused_shading_engines
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_ConnectSetup(set = None):

    if not set or not cmds.objExists(set):
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Setup already connected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    for i in range(0, len(transforms)):
        try:
            BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
        except:
            pass

    mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide')
    if mults:
        cmds.delete(mults)

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_ConnectSetup(set = None):

    if not set or not cmds.objExists(set):
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Setup already connected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    for i in range(0, len(transforms)):
        try:
            BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
        except:
            pass

    mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide')
    if mults:
        cmds.delete(mults)

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_ConnectSetup(set = None):

    if not set or not cmds.objExists(set):
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Setup already connected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    for i in range(0, len(transforms)):
        try:
            BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
        except:
            pass

    mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide')
    if mults:
        cmds.delete(mults)

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_ConnectSetup(set = None):

    if not set or not cmds.objExists(set):
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Setup already connected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    for i in range(0, len(transforms)):
        try:
            BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])
        except:
            pass

    mults = cmds.listConnections(btNode, d = True, type = 'multiplyDivide')
    if mults:
        cmds.delete(mults)

    return True
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def copyShader(src = "", tgts = [], *args):
    """
    gets the shader from the src and assigns it to the tgt objs

    Args:
        src (string): the object we're getting the shader FROM
        tgts (list[strings]): the objects we're setting the shaders TO
    """
    confirm = confirmDialog("Should I copy shaders?")
    if confirm == "Yes":
        for tgt in tgts:
            shp = cmds.listRelatives(src, s=True)[0]
            sg = cmds.listConnections(shp, t="shadingEngine")[0]
            tshp = cmds.listRelatives(tgt, s=True)[0]
            cmds.sets(tshp, e=True, forceElement=sg)
    else:
        print "Copy shader assignment cancelled"
        return()
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def delete_later_keys(obj, frame, *args):
    """sets a key at 'frame' and then deletes all subsequent keys in the timeline (time based only)"""
    animTypes = ["animCurveTL","animCurveTA", "animCurveTT", "animCurveTU"]
    animNodes = cmds.listConnections(obj, type="animCurve")
    if not animNodes:
        return()
    for a in animNodes:
        if (cmds.objectType(a)in animTypes):
            cmds.setKeyframe(a, time=frame)
            cmds.cutKey(a,clear=1, time=(frame + 1, 100000))
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def get_channel_attributes(obj, chnl):
    """
    gets and returns attributes of given channel on given object
    """
    attrType = cmds.attributeQuery(chnl, node=obj, at=True)
    hasMin = cmds.attributeQuery(chnl, node=obj, mne=True)
    hasMin = cmds.attributeQuery(chnl, node=obj, mne=True)
    hasMax = cmds.attributeQuery(chnl, node=obj, mxe=True)
    attrMin = None
    if hasMin:
        attrMin = cmds.attributeQuery(chnl, node=obj, min=True)
    attrMax = None
    if hasMax:
        attrMax = cmds.attributeQuery(chnl, node=obj, max=True)
    value = cmds.getAttr("{0}.{1}".format(obj, chnl))
    inConnection = cmds.listConnections("{0}.{1}".format(obj, chnl), plugs=True, destination=False, source=True)
    outConnection = cmds.listConnections("{0}.{1}".format(obj, chnl), plugs=True, destination=True, source=False)
    locked = cmds.getAttr("{0}.{1}".format(obj, chnl), lock=True)

    return (attrType, hasMin, attrMin, hasMax, attrMax, value, inConnection, outConnection, locked)
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def getRootAndCOM(node):
    '''
    Given either the root or COM, return root and COM based on connections.
    '''

    com = None
    root = None

    if mc.attributeQuery(COM_ATTR, node=node, exists=True):
        com = node
        messageCon = mc.listConnections(com+'.'+COM_ATTR, source=True, destination=False)
        if not messageCon:
            raise RuntimeError('Could not determine root from COM, please select root and run again.')
        root = messageCon[0]
    else:
        messageCon = mc.listConnections(node+'.message', source=False, destination=True, plugs=True)
        if messageCon:
            for each in messageCon:
                eachNode, attr = each.rsplit('.',1)
                if attr == COM_ATTR:
                    com = eachNode
                    root = node
                    break

    return root, com
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def listAnimCurves(objOrAttrs):
    '''
    This lists connections to all types of animNodes
    '''

    animNodes = list()

    tl = mc.listConnections(objOrAttr, s=True, d=False, type='animCurveTL')
    ta = mc.listConnections(objOrAttr, s=True, d=False, type='animCurveTA')
    tu = mc.listConnections(objOrAttr, s=True, d=False, type='animCurveTU')

    if tl:
        animNodes.extend(tl)
    if ta:
        animNodes.extend(ta)
    if tu:
        animNodes.extend(tu)

    return animNodes
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def pivot_driver_attr(node):
    '''
    Start with supporting pivots driven by remap value nodes, more support in the future as requested.
    '''
    #rpSrc = mc.listConnections(node+'.rotatePivot', source=True, destination=False, plugs=True)
    #if rpSrc and rpSrc[0].endswith('.translate') and mc.getAttr(rpSrc[0], keyable=True):
        #return rpSrc[0]

    for each in ('rotatePivotX', 'rotatePivotY', 'rotatePivotZ'):
        src = mc.listConnections(node+'.'+each, source=True, destination=False)
        if not src:
            continue
        srcType = mc.nodeType(src[0])
        if srcType == 'remapValue':
            src = mc.listConnections(src[0]+'.inputValue', source=True, destination=False, plugs=True)
            if src and mc.getAttr(src[0], keyable=True) and not mc.getAttr(src[0], lock=True):
                return src[0]
    return None
项目:PythonForMayaSamples    作者:dgovil    | 项目源码 | 文件源码
def createPipe(self, spans):
        # We set the transform and shape to the class variables
        self.transform, self.shape = cmds.polyPipe(subdivisionsAxis=spans)

        # I didn't like having to find the constructor from the extrude node
        # Lets just find it now and save it to the class because it won't change
        for node in cmds.listConnections('%s.inMesh' % self.transform):
            if cmds.objectType(node) == 'polyPipe':
                self.constructor = node
                break
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def get_shape(node, intermediate=False):
    """Get the shape node of a tranform

    This is useful if you don't want to have to check if a node is a shape node
    or transform.  You can pass in a shape node or transform and the function
    will return the shape node.

    :param node:  node The name of the node.
    :param intermediate:  intermediate True to get the intermediate shape
    :return: The name of the shape node.
    """
    if cmds.nodeType(node) == 'transform':
        shapes = cmds.listRelatives(node, shapes=True, path=True)
        if not shapes:
            shapes = []
        for shape in shapes:
            is_intermediate = cmds.getAttr('%s.intermediateObject' % shape)
            if intermediate and is_intermediate and cmds.listConnections(shape, source=False):
                return shape
            elif not intermediate and not is_intermediate:
                return shape
        if shapes:
            return shapes[0]
    elif cmds.nodeType(node) in ['mesh', 'nurbsCurve', 'nurbsSurface']:
        is_intermediate = cmds.getAttr('%s.intermediateObject' % node)
        if is_intermediate and not intermediate:
            node = cmds.listRelatives(node, parent=True, path=True)[0]
            return get_shape(node)
        else:
            return node
    return None
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def get_stack_count(node):
    """Get the number of transforms in the stack.

    :param node: Node to query.
    :return: The number of transforms in the stack.
    """
    connections = cmds.listConnections('{0}.message'.format(node), plugs=True) or []
    count = 0
    for connection in connections:
        connected_node, attribute = connection.split('.')
        if attribute == STACK_ATTRIBUTE:
            count += 1
    return count
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def add_from_selected(self, field_layout):
        # Get parentConstraints from the selected nodes
        sel = cmds.ls(sl=True) or []
        constraints = [x for x in sel if cmds.nodeType(x) == 'parentConstraint']
        transforms = [x for x in sel if cmds.nodeType(x) in ['transform', 'joint']]
        for transform in transforms:
            constraints += (cmds.listConnections(transform, type='parentConstraint') or [])
        constraints = list(set(constraints))
        for constraint in constraints:
            # Update the UI with the added constraint
            data = constraint_data(constraint)
            self.constraints.add_element(data=data, field_layout=field_layout)
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def constraint_data(constraint):
    """Gets the parentConstraint data dictionary of the given constraint.

    The data dictionary can be used as input into the Component.
    :param constraint: Name of a parentConstraint node.
    :return: The parentConstraint data dictionary.
    """
    data = {
        'drivers': cmds.parentConstraint(constraint, q=True, targetList=True),
        'driven': cmds.listConnections('{0}.constraintParentInverseMatrix'.format(constraint), d=False)[0],
        'maintain_offset': False,
        'skip_tx': False,
        'skip_ty': False,
        'skip_tz': False,
        'skip_rx': False,
        'skip_ry': False,
        'skip_rz': False,
    }

    offset = cmds.getAttr('{0}.target[0].targetOffsetTranslate'.format(constraint))[0]
    offset += cmds.getAttr('{0}.target[0].targetOffsetRotate'.format(constraint))[0]
    for value in offset:
        if abs(value) > 0.000001:
            data['maintain_offset'] = True
            break
    for x in 'xyz':
        connection = cmds.listConnections('{0}.t{1}'.format(data['driven'], x), d=False)
        if not connection or connection[0] != constraint:
            data['skip_t{0}'.format(x)] = True

        connection = cmds.listConnections('{0}.r{1}'.format(data['driven'], x), d=False)
        if not connection or connection[0] != constraint:
            data['skip_r{0}'.format(x)] = True
    return data
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_IsSetupConnected(set = None):
    if not set or not cmds.objExists(set):
        return None

    #test the first transform in the set
    setItems = cmds.listConnections(set +'.dagSetMembers')
    if not setItems:
        return None

    connections = cmds.listConnections(setItems[0], source = True, type = 'BlendTransforms')
    if connections:
        return True

    return False
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_Setup(set = None):

    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_IsSetupConnected(set = None):
    if not set or not cmds.objExists(set):
        return None

    #test the first transform in the set
    setItems = cmds.listConnections(set +'.dagSetMembers')
    if not setItems:
        return None

    connections = cmds.listConnections(setItems[0], source = True, type = 'BlendTransforms')
    if connections:
        return True

    return False
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_Setup(set = None):

    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_DisconnectSetup(set = None):

    if not set:
        return False

    if not BT_IsSetupConnected(set = set):
        cmds.warning('Setup already disconnected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    numOutputs = cmds.getAttr(btNode +'.output', size = True)
    print numOutputs
    tempMult = None
    for i in range(0, numOutputs):

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputT', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputT', conns[0] +'.translate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputT', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputR', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputR', conns[0] +'.rotate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputR', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputS', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputS', conns[0] +'.scale')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputS', tempMult +'.input1')

    cmds.select(cl = True)

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_IsSetupConnected(set = None):
    if not set or not cmds.objExists(set):
        return None

    #test the first transform in the set
    setItems = cmds.listConnections(set +'.dagSetMembers')
    if not setItems:
        return None

    connections = cmds.listConnections(setItems[0], source = True, type = 'BlendTransforms')
    if connections:
        return True

    return False
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_Setup(set = None):

    if not set:
        return False

    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    if not cmds.attributeQuery('Blend_Node', n = set, ex = True):
        cmds.addAttr(set, ln = 'Blend_Node', k = False, h = True, dt = 'string')
    else:
        return False

    btNode = cmds.createNode("BlendTransforms")
    cmds.setAttr(set +'.Blend_Node', btNode, type = "string")

    for i in range(0, len(transforms)):
        baseMatrix = cmds.xform(transforms[i], q = True, m = True)
        baseScale = cmds.getAttr(transforms[i] +'.scale')[0]
        baseRotOffset = [0.0, 0.0, 0.0]

        if cmds.objectType(transforms[i], isType = 'joint'):
            baseRotOffset = cmds.getAttr(transforms[i] +'.jointOrient')[0]

        btAttr = 'transforms[' +str(i) +'].baseMatrix'
        btScaleAttr = 'transforms[' +str(i) +'].baseScale'
        btRotOffsetAttr = 'transforms[' +str(i) +'].baseRotOffset'

        BT_MatrixValuesToNode(values = baseMatrix, node = btNode, attr = btAttr)
        BT_Double3ValuesToNode(values = baseScale, node = btNode, attr = btScaleAttr)
        BT_Double3ValuesToNode(values = baseRotOffset, node = btNode, attr = btRotOffsetAttr)
        BT_ConnectOutputs(index = i, node = btNode, transform = transforms[i])

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_DisconnectSetup(set = None):

    if not set:
        return False

    if not BT_IsSetupConnected(set = set):
        cmds.warning('Setup already disconnected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    numOutputs = cmds.getAttr(btNode +'.output', size = True)
    print numOutputs
    tempMult = None
    for i in range(0, numOutputs):

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputT', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputT', conns[0] +'.translate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputT', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputR', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputR', conns[0] +'.rotate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputR', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputS', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputS', conns[0] +'.scale')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputS', tempMult +'.input1')

    cmds.select(cl = True)

    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_IsSetupConnected(set = None):
    if not set or not cmds.objExists(set):
        return None

    #test the first transform in the set
    setItems = cmds.listConnections(set +'.dagSetMembers')
    if not setItems:
        return None

    connections = cmds.listConnections(setItems[0], source = True, type = 'BlendTransforms')
    if connections:
        return True

    return False
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_DisconnectSetup(set = None):

    if not set:
        return False

    if not BT_IsSetupConnected(set = set):
        cmds.warning('Setup already disconnected!')
        return False

    btNode = cmds.getAttr(set +'.Blend_Node')
    if not btNode or not cmds.objExists(btNode):
        return False

    numOutputs = cmds.getAttr(btNode +'.output', size = True)
    print numOutputs
    tempMult = None
    for i in range(0, numOutputs):

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputT', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputT', conns[0] +'.translate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputT', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputR', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputR', conns[0] +'.rotate')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputR', tempMult +'.input1')

        conns = cmds.listConnections(btNode +'.output[' +str(i) +'].outputS', s = False, d = True)
        if conns:
            tempMult = cmds.createNode('multiplyDivide')
            cmds.disconnectAttr(btNode +'.output[' +str(i) +'].outputS', conns[0] +'.scale')
            cmds.connectAttr(btNode +'.output[' +str(i) +'].outputS', tempMult +'.input1')

    cmds.select(cl = True)

    return True
项目:mayakit    作者:danbradham    | 项目源码 | 文件源码
def inColor(self):
        inputs = cmds.listConnections(self.attr('inColor'), d=False, s=True)
        if inputs:
            return inputs[0]
项目:metan    作者:utatsuya    | 项目源码 | 文件源码
def inputs(self, **kws):
        kws["source"] = True
        kws.pop("s", None)
        kws["destination"] = False
        kws.pop("d", None)
        return self.listConnections(**kws)
项目:metan    作者:utatsuya    | 项目源码 | 文件源码
def outputs(self, **kws):
        kws["source"] = False
        kws.pop("s", None)
        kws["destination"] = True
        kws.pop("d", None)
        return self.listConnections(**kws)
项目:metan    作者:utatsuya    | 项目源码 | 文件源码
def listConnectionsStr(self, **kws):
        items = cmds.listConnections(self.name(), **kws)
        if items is None:
            return []
        return items
项目:metan    作者:utatsuya    | 项目源码 | 文件源码
def listConnections(self, **kws):
        return self._listConnectionsUsedCmds(**kws)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def zbw_FK2IKSnap(*args):
    """
    select FK wrist joint(or control), fk elbow joint (or ctrl), FK shoulder joint (or ctrl), IK wrist ctl and IK pole vector in that order
    """

    sel = cmds.ls(sl=True)
    fkEndC = cmds.listConnections((sel[0]+".fkEndCtrl"))
    fkMidC = cmds.listConnections((sel[0]+".fkMidCtrl"))
    fkTopC = cmds.listConnections((sel[0]+".fkTopCtrl"))
    ikTopJ = cmds.listConnections((sel[0]+".ikTopJnt"))
    ikMidJ = cmds.listConnections((sel[0]+".ikMidJnt"))
    ikEndJ = cmds.listConnections((sel[0]+".ikEndJnt"))

    #get FK wrist joint position & rot
    ikEndPos = cmds.xform(ikEndJ, q=True, ws=True, t=True)
    iep = om.MVector(ikEndPos[0], ikEndPos[1], ikEndPos[2])
    ikEndRot = cmds.xform(ikEndJ, q=True, ro=True)
    ier = om.MVector(ikEndRot[0], ikEndRot[1], ikEndRot[2])

    #get FK shoulder position & rot
    ikTopPos = cmds.xform(ikTopJ, q=True, ws=True, t=True)
    itp = om.MVector(ikTopPos[0], ikTopPos[1], ikTopPos[2])
    ikTopRot = cmds.xform(ikTopJ, q=True, ro=True)
    itr = om.MVector(ikTopRot[0], ikTopRot[1], ikTopRot[2])

    #get midJnt pos & rot
    ikMidPos = cmds.xform(ikMidJ, q=True, ws=True, t=True)
    imp = om.MVector(ikMidPos[0], ikMidPos[1], ikMidPos[2])
    ikMidRot = cmds.xform(ikMidJ, q=True, ro=True)
    imr = om.MVector(ikMidRot[0], ikMidRot[1], ikMidRot[2])

    #rotate joints to rotations
    cmds.xform(fkEndC, ro=(ier.x, ier.y, ier.z))
    cmds.xform(fkMidC, ro=(imr.x, imr.y, imr.z))
    cmds.xform(fkTopC, ro=(itr.x, itr.y, itr.z))

    #snap FK ctrl to positions
#-------try:except this part . . . Will only work if the channels aren't locked . . .
    cmds.move(iep.x, iep.y, iep.z, fkEndC, ws=True)
    cmds.move(imp.x, imp.y, imp.z, fkMidC, ws=True)
    cmds.move(iep.x, iep.y, iep.z, fkEndC, ws=True)
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def saveShaderList(self, *args):
        """
        """
        sgs = []
        objs = []
        connections = {}

        #get the shaders
        sgs = cmds.ls(type="shadingEngine")

        #get the objects assigned to those shaders
        for sg in sgs:
            objs = cmds.listConnections("%s.dagSetMembers"%sg)
            if objs:
                connections[sg] = objs
            else:
                pass

        #write these lists out to file
        #check if that file exists already . . .
        self.path = cmds.textFieldButtonGrp(self.widgets["destinationTFBG"], q=True, tx=True)
        #print self.path
        file = open(self.path, "w")

        #can't write a dictionary
        #file.write(connections)
        #so. . .
        for key in connections.keys():
            file.write("%s,%s\n"%(key, connections[key]))
        file.close()
项目:zTools    作者:zethwillie    | 项目源码 | 文件源码
def doSpaceMatch(*args):

    #check for correct attrs
    obj = cmds.textFieldButtonGrp(widgets["objTFG"], q=True, tx=True)


   #look for message attr re: constraint
    if (cmds.attributeQuery("spaceConstraint", node=obj, exists=True)):
        constraint = cmds.listConnections("%s.spaceConstraint"%obj)
    else:
        cmds.warning("this object has no \"spaceConstraint\" message attribute and thus is not set up for this matching")

    #----------look for string attributes for weights of constraints



    #get ws pos of obj before
    ws1Pos = cmds.xform(obj, q=True, ws=True, t=True)
    ws1Rot = cmds.xform(obj, q=True, ws=True, ro=True)

    #pull the constraint info from the message and string attrs
    #attr = cmds.listAttr(sel,ud=True )

    #-----------here just key the space value!!!
    #switch the spaces, set up "cases", i.e. if world, then set all to 0 except world, etc
    cmds.setAttr("group1_parentConstraint1.pCube1W0", 0)
    cmds.setAttr("group1_parentConstraint1.pCube2W1", 1)

    #set ws pos, rot of obj after
    cmds.xform(obj, ws=True, t=ws1Pos)
    cmds.xform(obj, ws=True, ro=ws1Rot)

    #add in scriptjob?

    #-----------try this
    #set up constraints as normal, maybe DO NOT have to moniter them specifically, set them up as SDKs
    #constraint goes in as message mapped "spaceConstraint"
    #create string attrs for constraint, each space attrname = space , attrVal = constraintAttr(ie. nameW1)
    #Create one tab to set it up
    #creat one tab to do it - get spaces
项目:maya2katana    作者:ababak    | 项目源码 | 文件源码
def getAllShadingNodes(nodes):
    if not isinstance(nodes, list):
        nodes = [nodes]
    resultNodes = []
    while nodes:
        resultNodes += nodes
        nodes = cmds.listConnections(nodes, source=True, destination=False)
    return resultNodes
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_break(box, menuItem, key, *args):
    with sysCmd.Undo():
        for plug in channelBox_SelectedPlugs(box):
            if cmds.connectionInfo(plug, isDestination=1):
                destination = cmds.connectionInfo(plug, getExactDestination=1)

                # when delete source conn from character, must remove from character set or set becomes inconsistent
                src_conn = cmds.listConnections(destination, s=1, d=0, type="character")
                if src_conn:
                    warn_msg = "Removed \'^1s\' from character \'^2s\'."
                    cmds.warning(cmds.format(warn_msg, s=(destination, src_conn[0])))
                    cmds.character(destination, e=1, rm=src_conn[0])

                # is tracking edits?
                import maya.api.OpenMaya as om
                obj = om.MSelectionList().add(destination).getDependNode(0)
                depend_fn = om.MFnDependencyNode(obj)
                tracking_edits = depend_fn.isTrackingEdits()
                del obj
                del depend_fn

                if tracking_edits:
                    src = cmds.connectionInfo(destination, sourceFromDestination=1)
                    cmds.disconnectAttr(src, destination)
                else:
                    cmds.delete(destination, icn=1)
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_selectConnection(box, menuItem, key, *args):
    with sysCmd.Undo():
        for plug in channelBox_SelectedPlugs(box):
            if cmds.connectionInfo(plug, isDestination=1):
                destination = cmds.connectionInfo(plug, getExactDestination=1)
                dest_input = cmds.listConnections(destination)
                cmds.select(dest_input[0], r=1)


# --
项目:ModularChannelBox    作者:Vaei    | 项目源码 | 文件源码
def channelbox_command_materialAttributes(box, menuItem, key, *args):
    with sysCmd.Undo(0):
        if not cmds.ls(sl=1):
            return

        shape = cmds.listRelatives(cmds.ls(sl=1)[0], shapes=1)
        shading = cmds.listConnections(shape, type="shadingEngine")
        mel.eval("showEditor " + shading[0])


# --
项目:pw_mGeoExporter    作者:paulwinex    | 项目源码 | 文件源码
def getDisplayLayer(self, obj,op):
        #try transform
        l = cmds.listConnections(obj, type="displayLayer")
        if not l:
            #try shape
            l = cmds.listConnections(cmds.listRelatives(obj, s=1)[0] , type="displayLayer")
        if not l:
            #find parent
            parents = True
            while parents:
                parents = cmds.listRelatives(obj, p=1)
                if parents:
                    l = cmds.listConnections(parents[0] , type="displayLayer")
                    if l:break
                    else:obj = parents[0]
        if l:
            if op[1]:
                tok = self.tokenPrefix(op[1])
                for t in tok:
                    if t in l[0]:
                        return l[0]
                return 'deflayer'
            else:
                return l[0]
        else:
            return self.textVariables['deflayer']
项目:pw_mGeoExporter    作者:paulwinex    | 项目源码 | 文件源码
def getMaterialName(self, sg):
        mat = cmds.listConnections(sg + ".surfaceShader")
        if not mat:
            if cmds.attributeQuery("miMaterialShader",n=sg, ex=1):
                mat = cmds.listConnections(sg + ".miMaterialShader")
            if not mat:
                return 'noShader'
        if self.op['expgeogrp_mtl'][1]:
            tok = self.tokenPrefix(self.op['expgeogrp_mtl'][1])
            for t in tok:
                if t in mat[0]:
                    return mat[0]
            return self.textVariables['defShader']
        return mat[0]
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def main():

    sel = mc.ls(sl=True)

    for each in sel:
        shapes = mc.listRelatives(each, shapes=True)

        for shape in shapes:
            #get skin cluster
            history = mc.listHistory(shape, groupLevels=True, pruneDagObjects=True)
            skins = mc.ls(history, type='skinCluster')

            for skin in skins:
                joints = mc.skinCluster(skin, query=True, influence=True)

                mc.setAttr(skin+'.envelope', 0)
                mc.skinCluster(skin, edit=True, unbindKeepHistory=True)

                #delete bindPose
                dagPose = mc.dagPose(each, query=True, bindPose=True)
                if dagPose:
                    mc.delete(dagPose)
                dagPose = mc.listConnections(skin+'.bindPose', d=False, type='dagPose')
                if dagPose:
                    mc.delete(dagPose)

                mc.skinCluster(joints, shape, toSelectedBones=True)
                mc.setAttr(skin+'.envelope', 1)
    if sel:
        mc.select(sel)
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def getChannelFromAnimCurve(curve, plugs=True):
    '''
    Finding the channel associated with a curve has gotten really complicated since animation layers.
    This is a recursive function which walks connections from a curve until an animated channel is found.
    '''


    #we need to save the attribute for later.
    attr = ''
    if '.' in curve:
        curve, attr = curve.split('.')

    nodeType = mc.nodeType(curve)
    if nodeType.startswith('animCurveT') or nodeType.startswith('animBlendNode'):
        source = mc.listConnections(curve+'.output', source=False, plugs=plugs)
        if not source and nodeType=='animBlendNodeAdditiveRotation':
            #if we haven't found a connection from .output, then it may be a node that uses outputX, outputY, etc.
            #get the proper attribute by using the last letter of the input attribute, which should be X, Y, etc.
            #if we're not returning plugs, then we wont have an attr suffix to use, so just use X.
            attrSuffix = 'X'
            if plugs:
                attrSuffix = attr[-1]

            source = mc.listConnections(curve+'.output'+attrSuffix, source=False, plugs=plugs)
        if source:
            nodeType = mc.nodeType(source[0])
            if nodeType.startswith('animCurveT') or nodeType.startswith('animBlendNode'):
                return getChannelFromAnimCurve(source[0], plugs=plugs)
            return source[0]
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def curves(self):
        '''
        The keySelections's animation curve list.
        '''

        # if self._curves is False or None, then it has been initialized and curves haven't been found.
        if self._curves == []:

            #find anim curves connected to channels or nodes
            for each in (self._channels, self._nodes):
                if not each:
                    continue
                # this will only return time based keyframes, not driven keys
                self._curves = mc.keyframe(each, time=(':',), query=True, name=True)

                if self._curves:
                    self._curvesCulled = False
                    break
            if not self._curves:
                self._curves = False

        # need to remove curves which are unkeyable
        # supposedly referenced keys are keyable in 2013, I'll need to test that and update
        if self._curves and not self._curvesCulled:
            remove = list()
            for c in self._curves:
                if mc.referenceQuery(c, isNodeReferenced=True):
                    remove.append(c)
                else:
                    plug = mc.listConnections('.'.join((c,'output')), source=False, plugs=True)
                    if plug:
                        if not mc.getAttr(plug, keyable=True) and not mc.getAttr(plug, settable=True):
                            remove.append(c)
            if remove:
                for r in remove:
                    self._curves.remove(r)
            self._curvesCulled = True

        return self._curves
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def is_pivot_connected(node):
    for each in ('rotatePivot', 'rotatePivotX', 'rotatePivotY', 'rotatePivotZ'):
        if mc.listConnections(node+'.'+each, source=True, destination=False):
            return True
    return False
项目:ml_tools    作者:morganloomis    | 项目源码 | 文件源码
def selected(*args):

    curves = mc.keyframe(query=True, selected=True, name=True)
    if not curves:
        return

    clear()
    for c in curves:
        plug = mc.listConnections(c, plugs=True, source=False, destination=True)
        mc.selectionConnection('graphEditor1FromOutliner', edit=True, select=plug[0])
项目:cmt    作者:chadmv    | 项目源码 | 文件源码
def rebuild_joints(*args):
    if not cmds.objExists(ORIENT_GROUP):
        return
    nodes = cmds.listRelatives(ORIENT_GROUP, ad=True, path=True) or []

    joints = []
    for node in nodes:
        attrs = cmds.listAttr(node, ud=True) or []
        if MESSAGE_ATTRIBUTE not in attrs:
            continue
        joint = cmds.listConnections('{0}.{1}'.format(node, MESSAGE_ATTRIBUTE), d=False)[0]
        joints.append(joint)
        rotation = cmds.getAttr('{0}.rx'.format(node))

        children = cmds.listRelatives(joint, children=True, shapes=False, path=True)
        if children:
            # First unparent children so change in joint orient does not affect children
            children = [cmds.parent(child, world=True)[0] for child in children]

            # Add rotation offset to joint orient
            orient_x = cmds.getAttr('{0}.jointOrientX'.format(joint))
            orient_x += rotation
            while orient_x > 180.0:
                orient_x -= 360.0
            while orient_x < -180.0:
                orient_x += 360.0
            cmds.setAttr('{0}.jointOrientX'.format(joint), orient_x)

            # Reparent child
            for child in children:
                cmds.parent(child, joint)

        else:
            # tip joint, just zero out joint orient
            cmds.setAttr('%s.jointOrientX' % joint, 0)
            cmds.setAttr('%s.jointOrientY' % joint, 0)
            cmds.setAttr('%s.jointOrientZ' % joint, 0)

        # Untemplate
        cmds.setAttr('{0}.template'.format(joint), 0)

    # Delete arrow group
    cmds.delete(ORIENT_GROUP)
    cmds.select(joints)
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_SetPose(set = None, index = None):
    if not set:
        return False

    if BT_IsSetupConnected(set = set):
        cmds.warning('Disconnect setup first!')
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    node = cmds.getAttr(set +'.Blend_Node')
    transforms = cmds.listConnections(set +'.dagSetMembers')
    if not transforms:
        return False

    unitResult = BT_SetUnits()
    if unitResult:
        QtGui.QMessageBox.warning(BT_GetMayaWindow(), "Blend Transforms", "Units set to centimetres.", "Okay")

    for i in range(0, len(transforms)):
        baseM = cmds.getAttr(node +'.transforms[' +str(i) +'].baseMatrix')
        baseS = cmds.getAttr(node +'.transforms[' +str(i) +'].baseScale')[0]
        baseRO = cmds.getAttr(node +'.transforms[' +str(i) +'].baseRotOffset')[0]

        poseM = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
        poseS = [0,0,0]

        if index is not None:
            numPoses = cmds.getAttr(node +'.transforms[0].poses', size = True)
            if not index < numPoses:
                return False 
            poseM = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].matrix')
            poseS = cmds.getAttr(node +'.transforms[' +str(i) +'].poses[' +str(index) +'].scale')[0]

        finalM = [x+y for x, y in zip(poseM, baseM)]
        finalS = [x+y for x, y in zip(poseS, baseS)]

        cmds.xform(transforms[i], m = finalM)
        cmds.setAttr(transforms[i] +'.scale', finalS[0], finalS[1], finalS[2], type = 'double3')
        #hack to fix joint orient stuff
        if cmds.objectType(transforms[i], isType = 'joint'):
            cmds.setAttr(transforms[i] +'.jointOrient', baseRO[0], baseRO[1], baseRO[2], type = 'double3')
            currentRot = cmds.getAttr(transforms[i] +'.rotate')[0]
            cmds.setAttr(transforms[i] +'.rotate', currentRot[0] - baseRO[0], currentRot[1] - baseRO[1], currentRot[2] - baseRO[2], type = 'double3')


    return True
项目:BlendTransforms    作者:duncanskertchly    | 项目源码 | 文件源码
def BT_DeletePose(set = None, poseIndex = None):

    if not set or poseIndex is None:
        return False

    if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
        return False

    if BT_IsSetupConnected(set):
        cmds.warning('Disconnect setup first!')
        return False

    blendNode = cmds.getAttr(set +'.Blend_Node')

    if not cmds.objExists(blendNode) or not cmds.objExists(set):
        return False

    numTransforms = cmds.getAttr(blendNode +'.transforms', size = True)

    if not numTransforms:
        return False

    numPoses = cmds.getAttr(blendNode +'.transforms[0].poses', size = True) 
    allUserDefined = cmds.listAttr(set, ud = True)
    btUserDefined = [x for x in allUserDefined if x.startswith('BT_')]

    if poseIndex >= numPoses:
        return False

    connectionsToBreak = cmds.listConnections(set +'.' +btUserDefined[poseIndex], d = True, s = False, p = True)
    for ctb in connectionsToBreak:
        cmds.disconnectAttr(set +'.' +btUserDefined[poseIndex], ctb)
    cmds.deleteAttr(set +'.' +btUserDefined[poseIndex])

    for i in range(0, numTransforms):
        for p in range(poseIndex, numPoses-1):
            #get the next items vales
            matrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].matrix')
            scale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].scale')[0]
            conn = cmds.listConnections(blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight', s = True, d = False, p = True)[0]

            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].matrix', matrix, type = 'matrix')
            cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].scale', scale[0], scale[1], scale[2], type = 'double3')
            cmds.connectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p) +'].weight', force = True)
            cmds.disconnectAttr(conn, blendNode +'.transforms[' +str(i) +'].poses[' +str(p+1) +'].weight')

    return True