python类listConnections()的实例源码

wrapclass.py 文件源码 项目:metan 作者: utatsuya 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def outputs(self, **kws):
        kws["source"] = False
        kws.pop("s", None)
        kws["destination"] = True
        kws.pop("d", None)
        return self.listConnections(**kws)
wrapclass.py 文件源码 项目:metan 作者: utatsuya 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def listConnectionsStr(self, **kws):
        items = cmds.listConnections(self.name(), **kws)
        if items is None:
            return []
        return items
wrapclass.py 文件源码 项目:metan 作者: utatsuya 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def listConnections(self, **kws):
        return self._listConnectionsUsedCmds(**kws)
zbw_FK2IKSnap.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
zbw_shaderSaver.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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()
zbw_spaceMatch_overComplex.py 文件源码 项目:zTools 作者: zethwillie 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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
clip.py 文件源码 项目:maya2katana 作者: ababak 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
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
jtChannelBox_Commands_Default.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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)
jtChannelBox_Commands_Default.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
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)


# --
jtChannelBox_Commands_Default.py 文件源码 项目:ModularChannelBox 作者: Vaei 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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])


# --
dataReader.py 文件源码 项目:pw_mGeoExporter 作者: paulwinex 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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']
dataReader.py 文件源码 项目:pw_mGeoExporter 作者: paulwinex 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
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_resetBind.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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_utilities.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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_pivot.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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_graphEditorMask.py 文件源码 项目:ml_tools 作者: morganloomis 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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])
orientjoints.py 文件源码 项目:cmt 作者: chadmv 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:BlendTransforms 作者: duncanskertchly 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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.py 文件源码 项目:BlendTransforms 作者: duncanskertchly 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号