本文整理匯總了Python中maya.cmds.keyframe方法的典型用法代碼示例。如果您正苦於以下問題:Python cmds.keyframe方法的具體用法?Python cmds.keyframe怎麽用?Python cmds.keyframe使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類maya.cmds
的用法示例。
在下文中一共展示了cmds.keyframe方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: ui
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def ui():
'''
User interface for ml_setKey
'''
with utl.MlUi('ml_setKey', 'SetKey', width=400, height=220, info='''Press Set Key to set a keyframe with the current checkbox settings.
Right click the button to create a hotkey or shelf button
with the currently selected settings.''') as win:
mc.checkBoxGrp('ml_setKey_chanBox_checkBox', label='Selected Channels', annotation='Only key channels that are selected in the Channel Box')
mc.checkBoxGrp('ml_setKey_graphVis_checkBox', label='Visible in Graph Editor', annotation='Only key curves visible in Graph Editor')
mc.checkBoxGrp('ml_setKey_keyKeyed_checkBox', label='Key Only Keyed Channels', annotation='Only set keys on channels that are already keyed')
mc.checkBoxGrp('ml_setKey_subFrames_checkBox', label='Delete Sub-Frames', annotation='Delete sub-frame keys surrounding the current frame')
mc.checkBoxGrp('ml_setKey_insert_checkBox', label='Insert Key', annotation='Insert key (preserve tangents)')
mc.checkBoxGrp('ml_setKey_shapes_checkBox', label='Key Shapes', annotation='Set keyframes on shapes')
win.ButtonWithPopup(label='Set Key', name=win.name, command=setKey, annotation='Set a keyframe.',
readUI_toArgs={
'selectedChannels':'ml_setKey_chanBox_checkBox',
'visibleInGraphEditor':'ml_setKey_graphVis_checkBox',
'keyKeyed':'ml_setKey_keyKeyed_checkBox',
'deleteSubFrames':'ml_setKey_subFrames_checkBox',
'insert':'ml_setKey_insert_checkBox',
'keyShapes':'ml_setKey_shapes_checkBox',
})
示例2: selected
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def selected(*args):
curves = mc.keyframe(query=True, selected=True, name=True)
if not curves:
return
try:
mc.delete(ATTR_FILTER_NAME)
except:pass
try:
mc.delete(OBJ_FILTER_NAME)
except:pass
filters = list()
for c in curves:
plug = mc.listConnections(c, plugs=True, source=False, destination=True)[0]
print plug
filters.append(mc.itemFilter(byName=plug, classification='user'))
print filters
selectedFilter = mc.itemFilter(union=filters)
#mc.delete(filters)
print selectedFilter
mc.outlinerEditor('graphEditor1OutlineEd', edit=True, attrFilter=selectedFilter)
示例3: dragLeft
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def dragLeft(self):
'''This is activated by the left mouse button, and weights to the next or previous keys.'''
#clamp it
if self.x < -1:
self.x = -1
if self.x > 1:
self.x = 1
if self.x > 0:
self.drawString('>> '+str(int(self.x*100))+' %')
for curve in self.keySel.curves:
for i,v,n in zip(self.time[curve],self.value[curve],self.next[curve]):
mc.keyframe(curve, time=(i,), valueChange=v+((n-v)*self.x))
elif self.x <0:
self.drawString('<< '+str(int(self.x*-100))+' %')
for curve in self.keySel.curves:
for i,v,p in zip(self.time[curve],self.value[curve],self.prev[curve]):
mc.keyframe(curve, time=(i,), valueChange=v+((p-v)*(-1*self.x)))
示例4: minimizeRotationCurves
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def minimizeRotationCurves(obj):
'''
Sets rotation animation to the value closest to zero.
'''
rotateCurves = mc.keyframe(obj, attribute=('rotateX','rotateY', 'rotateZ'), query=True, name=True)
if not rotateCurves or len(rotateCurves) < 3:
return
keyTimes = mc.keyframe(rotateCurves, query=True, timeChange=True)
tempFrame = sorted(keyTimes)[0] - 1
#set a temp frame
mc.setKeyframe(rotateCurves, time=(tempFrame,), value=0)
#euler filter
mc.filterCurve(rotateCurves)
#delete temp key
mc.cutKey(rotateCurves, time=(tempFrame,))
示例5: setAnimValue
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def setAnimValue(plug, value, tangentType=None):
'''
Sets key if the channel is keyed, otherwise setAttr
'''
if mc.keyframe(plug, query=True, name=True):
mc.setKeyframe(plug, value=value)
if tangentType:
time = mc.currentTime(query=True)
itt = tangentType
ott = tangentType
if tangentType == 'step':
itt = 'linear'
mc.keyTangent(plug, time=(time,), edit=True, itt=itt, ott=ott)
mc.setAttr(plug, value)
示例6: time
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def time(self):
'''
The keySelection's time, formatted for maya's various keyframe command arguments.
'''
if self._time:
if isinstance(self._time, list):
return tuple(self._time)
elif isinstance(self._time, float) or isinstance(self._time, int):
return (self._time,)
return self._time
elif self._timeRangeStart and self._timeRangeEnd:
return (self._timeRangeStart,self._timeRangeEnd)
elif self._timeRangeStart:
return (str(self._timeRangeStart)+':',)
elif self._timeRangeEnd:
return (':'+str(self._timeRangeEnd),)
elif self.selected:
#if keys are selected, get their times
timeList = self.keyframe(query=True, timeChange=True)
return tuple(set(timeList))
return (':',)
示例7: selectedLayers
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def selectedLayers(self, includeLayerWeight=True):
'''
This affects keys on all layers that the node belongs to.
If includeLayerWeight, the keys on the layer's weight attribute will be affected also.
'''
layers = getSelectedAnimLayers()
curves = list()
for layer in layers:
layerCurves = mc.animLayer(layer, query=True, animCurves=True)
if layerCurves:
curves.extend(layerCurves)
if includeLayerWeight:
weightCurve = mc.keyframe(layer+'.weight', query=True, name=True)
if weightCurve:
curves.append(weightCurve[0])
self._curves = curves
#we only want to use curves, since nodes or channels wont accurately represent all layers
self._nodes = None
self._channels = None
示例8: scaleValue
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def scaleValue(percent=100, selectionOption=1, pivotOption=0):
value = percent/100.0
keySel = _getKeySelection(selectionOption)
valuePivot = 0
if pivotOption:
values = keySel.keyframe(query=True, valueChange=True)
values = sorted(list(set(values)))
if pivotOption == 1:
valuePivot = values[-1]
elif pivotOption == 2:
valuePivot = values[0]
elif pivotOption == 3:
valuePivot = (values[0]+values[-1])/2
keySel.scaleKey(valueScale=value, valuePivot=valuePivot)
示例9: rippleCut
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def rippleCut(selectionOption=1, setKey=True):
keySel = _getKeySelection(selectionOption)
if keySel.selectedFrameRange():pass
else: return
start, end = keySel.time
if setKey:
if keySel.findKeyframe('previous', time=(start-1,)) < start-1:
mc.setKeyframe(keySel.curves, time=(start-1,), insert=True)
if keySel.findKeyframe('next', time=(end,)) > end:
mc.setKeyframe(keySel.curves, time=(end,), insert=True)
mc.setKeyframe(keySel.curves, time=(start-1,end), insert=True)
keySel.cutKey()
#move everything after the cut
keySel.keyframe(edit=True, time=(str(end)+':',), relative=True, timeChange=start-end)
示例10: keyObj
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def keyObj(model, object_names):
"""Set the keyframe in the controls pass by a list in obj_names variable
Args:
model (Str): Name of the namespace that will define de the model
object_names (Str): names of the controls, without the name space
Returns:
None
"""
with pm.UndoChunk():
nodes = []
nameSpace = getNamespace(model)
for name in object_names:
if nameSpace:
node = getNode(nameSpace + ":" + name)
else:
node = getNode(name)
if not node:
continue
if not node and nameSpace:
mgear.log("Can't find object : %s:%s" % (nameSpace, name),
mgear.sev_error)
elif not node:
mgear.log("Can't find object : %s" % (name), mgear.sev_error)
nodes.append(node)
if not nodes:
return
pm.setKeyframe(*nodes)
示例11: commands
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def commands():
"""This function will use the Maya commands API to query keyframes in a scene"""
# Get the start time so we can calculate how long this took
start = time.time()
# Ask Maya to fetch all the animCurves for the joints
curves = cmds.ls(type='animCurveTA')
# Then query all the keyframes
keyframes = set(cmds.keyframe(curves, q=True))
# Finally calculate how long those two lines took
delta = time.time() - start
# And then return it so we tally it up
return delta
示例12: bakePivot
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def bakePivot(self):
if not mc.objExists(self.pivotHandle) or not mc.objExists(self.node):
self.cleanup()
return
newPivot = mc.getAttr(self.pivotHandle+'.translate')[0]
if newPivot == mc.getAttr(self.node+'.rotatePivot')[0]:
self.cleanup()
return
if not mc.keyframe(self.node, attribute=('tx','ty','tz','rx','ry','rz'), query=True, name=True):
mc.setAttr(self.node+'.rotatePivot', *newPivot)
self.cleanup()
return
tempPosition = mc.group(em=True)
mc.delete(mc.parentConstraint(self.pivotHandle, tempPosition))
utl.matchBake(source=[self.node], destination=[tempPosition], bakeOnOnes=True, maintainOffset=True, preserveTangentWeight=False, rotate=False)
mc.setAttr(self.node+'.rotatePivot', *newPivot)
utl.matchBake(source=[tempPosition], destination=[self.node], bakeOnOnes=True, maintainOffset=False, preserveTangentWeight=False, rotate=False)
mc.delete(tempPosition)
mc.select(self.node)
self.cleanup()
#end context
try:
qt_maya_window.removeEventFilter(self.keypressFilter)
except:
pass
示例13: dragMiddle
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def dragMiddle(self):
'''This is activated by the middle mouse button, and weights to the average of the surrounding keys.'''
#clamp it
if self.x < -1:
self.x = -1
if self.x > 1:
self.x = 1
self.drawString('Average '+str(int(self.x*100))+' %')
for curve in self.keySel.curves:
for i,v,n in zip(self.time[curve],self.value[curve],self.average[curve]):
mc.keyframe(curve, time=(i,), valueChange=v+((n-v)*self.x))
示例14: dragShiftLeft
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def dragShiftLeft(self):
'''This is activated by Shift and the left mouse button, and weights to the next or previous keys, without clamping.'''
if self.x > 0:
self.drawString('>> '+str(int(self.x*100))+' %')
for curve in self.keySel.curves:
for i,v,n in zip(self.time[curve],self.value[curve],self.next[curve]):
mc.keyframe(curve, time=(i,), valueChange=v+((n-v)*self.x))
elif self.x <0:
self.drawString('<< '+str(int(self.x*-100))+' %')
for curve in self.keySel.curves:
for i,v,p in zip(self.time[curve],self.value[curve],self.prev[curve]):
mc.keyframe(curve, time=(i,), valueChange=v+((p-v)*(-1*self.x)))
示例15: castToTime
# 需要導入模塊: from maya import cmds [as 別名]
# 或者: from maya.cmds import keyframe [as 別名]
def castToTime(time):
'''
Maya's keyframe commands are finnicky about how lists of times or indicies are formatted.
'''
if isinstance(time, (list, tuple)):
return [(x,) for x in time]
return (time,)