我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用maya.cmds.disconnectAttr()。
def clearShaderConnections(ts="", geo="", *args): myShape = cmds.listRelatives(geo, s=True)[0] tsList = cmds.listAttr(ts, m=True, st=["*input*"]) if tsList: # delete empty entries? ? # for tsInput in tsList: # shpList = cmds.connectionInfo("{0}.{1}.inShape".format(ts, tsInput), sfd=True) # if not shpList: # cmds.removeMultiInstance("blinn1_TripleSwitch.{0}".format(tsInput)) for tsInput in tsList: shpList = cmds.connectionInfo("{0}.{1}.inShape".format(ts, tsInput), sfd=True).partition(".") shp = "" if shpList: shp = shpList[0] if shp == myShape: # clear out the shape node cmds.disconnectAttr("{0}.instObjGroups[0]".format(shp), "{0}.{1}.inShape".format(ts, tsInput)) # clear out the texture (delete if we can) txt = cmds.connectionInfo("{0}.{1}.inTriple".format(ts, tsInput), sfd=True).partition(".")[0] cmds.disconnectAttr("{0}.outColor".format(txt), "{0}.{1}.inTriple".format(ts, tsInput)) p2d = cmds.connectionInfo("{0}.uvCoord".format(txt), sfd=True).partition(".")[0] cmds.delete(txt, p2d)
def doit(cage_tgt=None): if not cage_tgt: cage_tgt = cmds.ls(sl=True, o=True) cage = cage_tgt[0] tgt = cage_tgt[1:] cmds.loadPlugin('greenCageDeformer.py', qt=True) deformer = cmds.deformer(tgt, type='greenCageDeformer')[0] freezer = cmds.createNode('transformGeometry') cmds.connectAttr(cage + '.o', freezer + '.ig') cmds.connectAttr(cage + '.wm', freezer + '.txf') cmds.connectAttr(freezer + '.og', deformer + '.bc') cmds.disconnectAttr(freezer + '.og', deformer + '.bc') cmds.delete(freezer) cmds.connectAttr(cage + '.w', deformer + '.ic') cmds.dgeval(cmds.listConnections(deformer + '.og', s=False, d=True, sh=True, p=True)) #doit([cmds.polyCube(w=2.5, d=2.5, h=2.5)[0], cmds.polySphere()[0]])
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
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)
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