def main(selectedChannels=True, transformsOnly=False, excludeChannels=None):
'''
Resets selected channels in the channel box to default, or if nothing's
selected, resets all keyable channels to default.
'''
gChannelBoxName = mm.eval('$temp=$gChannelBoxName')
sel = mc.ls(sl=True)
if not sel:
return
if excludeChannels and not isinstance(excludeChannels, (list, tuple)):
excludeChannels = [excludeChannels]
chans = None
if selectedChannels:
chans = mc.channelBox(gChannelBoxName, query=True, sma=True)
testList = ['translateX','translateY','translateZ','rotateX','rotateY','rotateZ','scaleX','scaleY','scaleZ',
'tx','ty','yz','rx','ry','rz','sx','sy','sz']
for obj in sel:
attrs = chans
if not chans:
attrs = mc.listAttr(obj, keyable=True, unlocked=True)
if excludeChannels:
attrs = [x for x in attrs if x not in excludeChannels]
if transformsOnly:
attrs = [x for x in attrs if x in testList]
if attrs:
for attr in attrs:
try:
default = mc.attributeQuery(attr, listDefault=True, node=obj)[0]
mc.setAttr(obj+'.'+attr, default)
except StandardError:
pass
utl.deselectChannels()
python类attributeQuery()的实例源码
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
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
def BT_AddPose(set = None, poseName = '', index = None):
prefixedPoseName = 'BT_' +poseName
if not set:
return False
if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
return False
if BT_IsSetupConnected(set = 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
if cmds.attributeQuery(prefixedPoseName, ex = True, n = set):
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
numTransforms = len(transforms)
poseIndex = cmds.getAttr(blendNode +'.transforms[0].poses', size = True)
if index is not None:
poseIndex = index
if index is None:
cmds.addAttr(set, ln = prefixedPoseName, nn = poseName, k = True, min = 0, max = 1.0, at = 'double')
# print ('Num poses = ' +str(numPoses))
for i in range(0, numTransforms):
#get the base matrix
baseScale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseScale')[0]
baseMatrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseMatrix')
#store the scale and set it
transformScale = cmds.getAttr(transforms[i] +'.scale')[0]
#set the scale back to 1.0
cmds.setAttr(transforms[i] +'.scale', 1.0, 1.0, 1.0, type = 'double3')
transformMatrix = cmds.xform(transforms[i], q = True, m = True)
poseMatrix = [x-y for x, y in zip(transformMatrix, baseMatrix)]
poseScale = [x-y for x, y in zip(transformScale, baseScale)]
#set the scale back to what the user had it at
cmds.setAttr(transforms[i] +'.scale', transformScale[0], transformScale[1], transformScale[2], type = 'double3')
cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].matrix', poseMatrix, type = 'matrix')
BT_Double3ValuesToNode(values = poseScale, node = blendNode, attr = 'transforms[' +str(i) +'].poses[' +str(poseIndex) +'].scale' )
if index is None:
cmds.connectAttr(set +'.' +prefixedPoseName, blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].weight')
return True
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
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
def BT_AddPose(set = None, poseName = '', index = None):
prefixedPoseName = 'BT_' +poseName
if not set:
return False
if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
return False
if BT_IsSetupConnected(set = 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
if cmds.attributeQuery(prefixedPoseName, ex = True, n = set):
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
numTransforms = len(transforms)
poseIndex = cmds.getAttr(blendNode +'.transforms[0].poses', size = True)
if index is not None:
poseIndex = index
if index is None:
cmds.addAttr(set, ln = prefixedPoseName, nn = poseName, k = True, min = 0, max = 1.0, at = 'double')
# print ('Num poses = ' +str(numPoses))
for i in range(0, numTransforms):
#get the base matrix
baseScale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseScale')[0]
baseMatrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseMatrix')
#store the scale and set it
transformScale = cmds.getAttr(transforms[i] +'.scale')[0]
#set the scale back to 1.0
cmds.setAttr(transforms[i] +'.scale', 1.0, 1.0, 1.0, type = 'double3')
transformMatrix = cmds.xform(transforms[i], q = True, m = True)
poseMatrix = [x-y for x, y in zip(transformMatrix, baseMatrix)]
poseScale = [x-y for x, y in zip(transformScale, baseScale)]
#set the scale back to what the user had it at
cmds.setAttr(transforms[i] +'.scale', transformScale[0], transformScale[1], transformScale[2], type = 'double3')
cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].matrix', poseMatrix, type = 'matrix')
BT_Double3ValuesToNode(values = poseScale, node = blendNode, attr = 'transforms[' +str(i) +'].poses[' +str(poseIndex) +'].scale' )
if index is None:
cmds.connectAttr(set +'.' +prefixedPoseName, blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].weight')
return True
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
def BT_AddPose(set = None, poseName = '', index = None):
prefixedPoseName = 'BT_' +poseName
if not set:
return False
if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
return False
if BT_IsSetupConnected(set = 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
if cmds.attributeQuery(prefixedPoseName, ex = True, n = set):
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
numTransforms = len(transforms)
poseIndex = cmds.getAttr(blendNode +'.transforms[0].poses', size = True)
if index is not None:
poseIndex = index
if index is None:
cmds.addAttr(set, ln = prefixedPoseName, nn = poseName, k = True, min = 0, max = 1.0, at = 'double')
# print ('Num poses = ' +str(numPoses))
for i in range(0, numTransforms):
#get the base matrix
baseScale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseScale')[0]
baseMatrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseMatrix')
#store the scale and set it
transformScale = cmds.getAttr(transforms[i] +'.scale')[0]
#set the scale back to 1.0
cmds.setAttr(transforms[i] +'.scale', 1.0, 1.0, 1.0, type = 'double3')
transformMatrix = cmds.xform(transforms[i], q = True, m = True)
poseMatrix = [x-y for x, y in zip(transformMatrix, baseMatrix)]
poseScale = [x-y for x, y in zip(transformScale, baseScale)]
#set the scale back to what the user had it at
cmds.setAttr(transforms[i] +'.scale', transformScale[0], transformScale[1], transformScale[2], type = 'double3')
cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].matrix', poseMatrix, type = 'matrix')
BT_Double3ValuesToNode(values = poseScale, node = blendNode, attr = 'transforms[' +str(i) +'].poses[' +str(poseIndex) +'].scale' )
if index is None:
cmds.connectAttr(set +'.' +prefixedPoseName, blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].weight')
return True
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
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
def BT_AddPose(set = None, poseName = '', index = None):
prefixedPoseName = 'BT_' +poseName
if not set:
return False
if not cmds.attributeQuery('Blend_Node', ex = True, n = set):
return False
if BT_IsSetupConnected(set = 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
if cmds.attributeQuery(prefixedPoseName, ex = True, n = set):
return False
transforms = cmds.listConnections(set +'.dagSetMembers')
numTransforms = len(transforms)
poseIndex = cmds.getAttr(blendNode +'.transforms[0].poses', size = True)
if index is not None:
poseIndex = index
if index is None:
cmds.addAttr(set, ln = prefixedPoseName, nn = poseName, k = True, min = 0, max = 1.0, at = 'double')
# print ('Num poses = ' +str(numPoses))
for i in range(0, numTransforms):
#get the base matrix
baseScale = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseScale')[0]
baseMatrix = cmds.getAttr(blendNode +'.transforms[' +str(i) +'].baseMatrix')
#store the scale and set it
transformScale = cmds.getAttr(transforms[i] +'.scale')[0]
#set the scale back to 1.0
cmds.setAttr(transforms[i] +'.scale', 1.0, 1.0, 1.0, type = 'double3')
transformMatrix = cmds.xform(transforms[i], q = True, m = True)
poseMatrix = [x-y for x, y in zip(transformMatrix, baseMatrix)]
poseScale = [x-y for x, y in zip(transformScale, baseScale)]
#set the scale back to what the user had it at
cmds.setAttr(transforms[i] +'.scale', transformScale[0], transformScale[1], transformScale[2], type = 'double3')
cmds.setAttr(blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].matrix', poseMatrix, type = 'matrix')
BT_Double3ValuesToNode(values = poseScale, node = blendNode, attr = 'transforms[' +str(i) +'].poses[' +str(poseIndex) +'].scale' )
if index is None:
cmds.connectAttr(set +'.' +prefixedPoseName, blendNode +'.transforms[' +str(i) +'].poses[' +str(poseIndex) +'].weight')
return True
def get_selected_channels(full=True, long=True, *args):
"""
for ONE object selected, return all selected channels from channel box
:param full: (boolean) return the full name of the object.attr?, if false then returns only the attr names
":param long: (boolean) whether we should get the long name of the attr. False will give us "short" names
:return: list of full obj.channel names selected, or (if not "full") just the channnel names
"""
cBox = mel.eval('$temp=$gChannelBoxName')
sel = cmds.ls(sl=True, l=True)
if len(sel) != 1:
cmds.warning("You have to select ONE node!")
return(None)
obj = sel[0]
channelsRaw = cmds.channelBox(cBox, q=True, selectedMainAttributes=True, selectedShapeAttributes=True,
selectedHistoryAttributes=True,
selectedOutputAttributes=True)
channels = []
if channelsRaw:
if long:
for ch in channelsRaw:
newC = cmds.attributeQuery(ch, node=obj, longName=True)
channels.append(newC)
else:
for ch in channelsRaw:
newC = cmds.attributeQuery(ch, node=obj, shortName=True)
channels.append(newC)
else: return(None)
returnList = []
if channels:
if full:
for c in channels:
full = "{0}.{1}".format(obj, c)
returnList.append(full)
else:
returnList = channels
return(returnList)
else:
cmds.warning("zbw_rig.get_selected_channels: I didn't detect any channels selected!")
return(None)
def zbw_mmConnectM(*args):
"""
uses the items from the textFields to create message attrs in the base obj, and connects to those the objs from the rightmost fields of the UI
"""
#check there's a base obj
if (cmds.textFieldButtonGrp("zbw_tfbg_baseObj", q=True, tx=True)):
#check there are any fields created
if (cmds.rowColumnLayout("mmRCLayout", q=True, ca=True)):
children = cmds.rowColumnLayout("mmRCLayout", q=True, ca=True)
numObj = (len(children)/2)
if numObj:
for num in range(1, numObj+1):
attrTFG = "attr" + str(num)
objTFBG = "obj" + str(num)
baseObj = cmds.textFieldButtonGrp("zbw_tfbg_baseObj", q=True, tx=True)
targetObj = cmds.textFieldButtonGrp(objTFBG, q=True, tx=True)
baseAttr = cmds.textFieldGrp(attrTFG, q=True, tx=True)
baseMAttr = baseObj + "." + baseAttr
objMAttr = targetObj + ".message"
#check to make sure there's something in each field, otherwise skip
if baseAttr and targetObj:
#check that attr doesnt' already exist with connection
if (cmds.attributeQuery(baseAttr, n=baseObj, ex=True)):
#delete the attr that exists, print note about it
cmds.deleteAttr(baseMAttr)
cmds.warning(baseMAttr + " already exists! Deleting for overwrite and reconnection")
cmds.addAttr(baseObj, at="message", ln=baseAttr)
cmds.connectAttr(objMAttr, baseMAttr, f=True)
#print confirmation of connection
print("Connected: "+ objMAttr +"--->"+ baseMAttr)
else:
cmds.warning("Line # " + str(num) + " was empty! Skipped that attr")
#leave a text field saying that it's done
zbw_mmDeleteConfirm()
cmds.separator("mmConfirmSep", h=20, st="single", p="mmAddNewConnections")
cmds.text("mmTextConfirm", l="MESSAGES MAPPED!", p="mmAddNewConnections")
else:
cmds.warning("Please create some attrs and objs to connect to base obj!")
else:
cmds.warning("Please choose a base object to add attrs to!")
def zbw_mmListCurrentMessages(tfbg, *args):
"""
lists the message attrs in the base obj and sets up rt-click menus to change them and a button to delete them
"""
if (cmds.rowColumnLayout("mmRCListLayout", q=True, ex=True)):
cmds.deleteUI("mmRCListLayout")
cmds.rowColumnLayout("mmRCListLayout", w=600, nc=3, cw=[(1, 250),(2,250),(3,100)],p="existingMessages")
#get the base object
baseObj = cmds.textFieldButtonGrp(tfbg, q=True, tx=True)
#find all attr of type message for base obj
userAttrs = cmds.listAttr(baseObj, ud=True)
#print(udAttrs)
messageAttrs = []
messageObjs = []
if userAttrs:
for attr in userAttrs:
isMsg = cmds.attributeQuery(attr, n=baseObj, msg=True)
if isMsg:
fullMsgAttr = baseObj + "." + attr
messageAttrs.append(fullMsgAttr)
targetObj = cmds.listConnections(fullMsgAttr)
if not targetObj:
targetObj = ["no Connection"]
messageObjs.append(targetObj[0])
sizeMsgs = len(messageObjs)
for i in range(0, sizeMsgs):
thisObj = messageObjs[i]
thisAttr = messageAttrs[i]
#create textField based on num already there, non-editable
attrId = "listAttrTFG" + str(i)
objId = "listObjTFG" + str(i)
buttonId = "listButton" + str(i)
cmds.separator(h=15, style="single")
cmds.separator(h=15, style="single")
cmds.separator(h=15, style="single")
#create text field for attr
cmds.textFieldGrp(attrId, p="mmRCListLayout", l=i, cw=[(1,10), (2,190)], ed=False, tx=thisAttr)
#create popup for text field
cmds.popupMenu(("attrPUM"+str(i)), b=3)
cmds.menuItem(l="change attr name", p=("attrPUM"+str(i)), c=partial(zbw_mmChangeConnectAttrUI, baseObj, thisAttr, thisObj))
#create textField obj based on num, non-editable
cmds.textFieldGrp(objId, p="mmRCListLayout", w=200, ed=False, tx=thisObj)
#create pop up
cmds.popupMenu(("objPUM"+str(i)), b=3)
cmds.menuItem(l="change obj", p=("objPUM"+str(i)), c=partial(zbw_mmChangeConnectObjUI, baseObj, thisAttr, thisObj))
#create button to delete attr
cmds.button(buttonId, l="delete", w=50, c=partial(zbw_mmDeleteMsgAttr, thisAttr))
else:
cmds.text("no message attributes on this object", p="mmRCListLayout")
def _get_gozid_mismatches(objs):
"""Return objects from `objs` whose gozbruhBrushID does not match their name
Checks object history for instances of gozbruhBrushID,
returns a list ofgozbruhBrushID/name conflicts
gozbruhBrushID is created by ZBrush on export and is used to track
name changes that can occur in maya
this function compares object current name against the ID
and returns a list of conflicts
this list is handled by the gui to allow for dialog boxes
"""
goz_list = []
for obj in objs:
has_attr = cmds.attributeQuery(
'gozbruhBrushID', node=obj, exists=True)
if has_attr:
# check for 'rename'
goz_id = cmds.getAttr(obj + '.gozbruhBrushID')
if obj != goz_id:
goz_list.append((obj, goz_id))
else:
# check for old ID in history
for old_obj in cmds.listHistory(obj):
has_attr = cmds.attributeQuery('gozbruhBrushID',
node=old_obj,
exists=True)
if has_attr:
goz_id = cmds.getAttr(old_obj + '.gozbruhBrushID')
if obj != goz_id:
goz_list.append((obj, goz_id))
# resulting mismatches to be handled
return goz_list
#------------------------------------------------------------------------------
# Sending / Exporting
#------------------------------------------------------------------------------
def export(objs):
"""Save files.
Checks for gozbruhParent attr.
gozbruhParent is used to import objects in correct order in ZBrush
gozbruhParent determines the top level tool in ZBrush
If no instance exists, it is created
Returns
-------
list of (str, str)
list of object, parent pairs
"""
parents = []
for obj in objs:
# export each file individually
cmds.select(cl=True)
cmds.select(obj)
cmds.delete(ch=True)
ascii_path = utils.make_maya_filepath(obj)
cmds.file(ascii_path,
force=True,
options="v=0",
type="mayaAscii",
exportSelected=True)
if cmds.attributeQuery('gozbruhParent', node=obj, exists=True):
# object existed in zbrush, has 'parent' tool
parent = cmds.getAttr(obj + '.gozbruhParent')
# append to the end of parents
parents.append((obj, parent))
else:
cmds.addAttr(obj, longName='gozbruhParent', dataType='string')
cmds.setAttr(obj + '.gozbruhParent', obj, type='string')
# prepend to the beginning of parents, we want these objects
# imported first
parents = [(obj, obj)] + parents
# maya is often run as root, this makes sure osx can open/save
# files not needed if maya is run un-privileged
os.chmod(ascii_path, 0o777)
return parents
def swapAnimation(fromNode, toNode):
if not mc.keyframe(fromNode, query=True, name=True):
mc.cutKey(toNode, clear=True)
return
attrs = mc.listAttr(fromNode, keyable=True)
if not attrs:
return
for attr in attrs:
if not mc.attributeQuery(attr, node=toNode, exists=True):
mc.cutKey(fromNode, attribute=attr, clear=True)
continue
fromPlug = '{}.{}'.format(fromNode, attr)
toPlug = '{}.{}'.format(toNode, attr)
srcCurve = mc.listConnections(fromPlug, source=True, destination=False, type='animCurve')
dstCurve = mc.listConnections(toPlug, source=True, destination=False, type='animCurve')
copySrc=None
copyDst=None
if srcCurve:
copySrc = mc.duplicate(srcCurve[0])[0]
if dstCurve:
copyDst = mc.duplicate(dstCurve[0])[0]
if copySrc:
try:
mc.cutKey(copySrc)
mc.pasteKey(toNode, attribute=attr, option='replaceCompletely')
except:pass
if copyDst:
try:
mc.cutKey(copyDst)
mc.pasteKey(fromNode, attribute=attr, option='replaceCompletely')
except:pass
for axis in getMirrorAxis(toNode):
mc.scaleKey(toNode, attribute=axis, valueScale=-1)
mc.scaleKey(fromNode, attribute=axis, valueScale=-1)
def reset_pivot(*args):
sel = mc.ls(sl=True)
if not sel:
om.MGlobal.displayWarning('Nothing selected.')
return
if len(sel) > 1:
om.MGlobal.displayWarning('Only works on one node at a time.')
return
node = sel[0]
driver = None
driver_value = None
driver_default = None
if is_pivot_connected(node):
driver = pivot_driver_attr(node)
if driver:
dNode,dAttr = driver.split('.',1)
driver_value = mc.getAttr(driver)
driver_default = mc.attributeQuery(dAttr, node=dNode, listDefault=True)[0]
if driver_default == driver_value:
return
else:
om.MGlobal.displayWarning('Pivot attribute is connected, unable to edit.')
return
if not driver:
pivotPosition = mc.getAttr(node+'.rotatePivot')[0]
if pivotPosition == (0.0,0.0,0.0):
return
tempPosition = mc.group(em=True)
tempPivot = mc.group(em=True)
tempPivot = mc.parent(tempPivot, node)[0]
if driver:
mc.setAttr(driver, driver_default)
newRP = mc.getAttr(node+'.rotatePivot')[0]
mc.setAttr(driver, driver_value)
mc.setAttr(tempPivot+'.translate', *newRP)
else:
mc.setAttr(tempPivot+'.translate', 0,0,0)
mc.setAttr(tempPivot+'.rotate', 0,0,0)
utl.matchBake(source=[tempPivot], destination=[tempPosition], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)
if driver:
mc.setAttr(driver, driver_default)
else:
mc.setAttr(node+'.rotatePivot', 0,0,0)
mc.refresh()
utl.matchBake(source=[tempPosition], destination=[node], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)
mc.delete(tempPosition,tempPivot)
mc.select(node)