Python maya.cmds.setKeyframe() Examples
The following are 18
code examples of maya.cmds.setKeyframe().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
maya.cmds
, or try the search function
.
Example #1
Source File: ml_animCurveEditor.py From ml_tools with MIT License | 6 votes |
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)
Example #2
Source File: ml_animCurveEditor.py From ml_tools with MIT License | 6 votes |
def cutUnselected(selectionOption=1, setKey=True): keySel = _getKeySelection(selectionOption) start = None end = None if keySel.keyRange(): start, end = keySel.time else: start, end = utl.frameRange() if setKey: if keySel.findKeyframe('previous', time=(start,)) < start: mc.setKeyframe(keySel.curves, time=(start,), insert=True) if keySel.findKeyframe('next', time=(end-1,)) > end-1: mc.setKeyframe(keySel.curves, time=(end-1,), insert=True) keySel.cutKey(time=(':'+str(start),)) keySel.cutKey(time=(str(end)+':',))
Example #3
Source File: samplingFunc.py From DeformationLearningSolver with BSD 3-Clause "New" or "Revised" License | 6 votes |
def attrSampling(node, attr, minVal, maxVal, interval=1): """ Args: node (str) attrs (list) minVal (float) maxVal (float) interval (int) Returns: int """ currTime = cmds.currentTime(q=1) currVal = cmds.getAttr('%s.%s' % (node, attr)) vals = [currVal, currVal+minVal, currVal+maxVal, currVal] for i, v in enumerate(vals): if i not in [0, len(vals)-1] and (currVal - v) == 0: continue cmds.setKeyframe(node, at=attr, v=v, t=currTime) currTime += interval return currTime #----------------------------------------------------------------------
Example #4
Source File: main.py From ssds with MIT License | 6 votes |
def bakeJointMotion(skinJoints, skinMatrix): asl = om.MSelectionList() for sj in skinJoints: asl.add(sj.path) om.MGlobal.setActiveSelectionList(asl) startTime = oma.MAnimControl.animationStartTime() endTime = oma.MAnimControl.animationEndTime() frame = 0 ctime = startTime oma.MAnimControl.setCurrentTime(ctime) while ctime <= endTime: oma.MAnimControl.setCurrentTime(ctime) for jid, sj in enumerate(skinJoints): m = om.MMatrix(np.dot(sj.bindPose, skinMatrix[jid, frame]).tolist()) m = om.MTransformationMatrix(m) om.MFnTransform(sj.path).setTransformation(m) cmds.setKeyframe() frame = frame + 1 ctime = ctime + 1 oma.MAnimControl.setCurrentTime(startTime)
Example #5
Source File: tests.py From cmdx with BSD 2-Clause "Simplified" License | 6 votes |
def test_getattrtime(): """getAttr(time=)""" transform = cmdx.createNode("transform") for time, value in ((1, 1.0), (10, 10.0)): cmds.setKeyframe(str(transform), time=[time], attribute="translateY", value=value) cmds.keyTangent(str(transform), edit=True, time=(1, 10), attribute="translateY", outTangentType="linear") # These floating point values can differ ever so slightly assert_almost_equals(transform["ty"].read(time=1), 1.0, places=5) assert_almost_equals(transform["ty"].read(time=5), 5.0, places=5) assert_almost_equals(transform["ty"].read(time=10), 10.0, places=5)
Example #6
Source File: ml_utilities.py From ml_tools with MIT License | 6 votes |
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,))
Example #7
Source File: ml_utilities.py From ml_tools with MIT License | 6 votes |
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)
Example #8
Source File: keyframeReduction.py From maya-keyframe-reduction with MIT License | 5 votes |
def _addKeys(self, keyframes, weightedTangents): """ Loop all the keyframes and create a keyframe and set the correct tangent information. :param list keyframes: :param bool weightedTangents: """ # variables inAngle = Vector2D(-1, 0) outAngle = Vector2D(1, 0) # loop keyframes for keyframe in keyframes: # create keyframe point cmds.setKeyframe(self.path, time=keyframe.point.x, value=keyframe.point.y) # set keyframe tangent variable arguments = {"edit": True, "absolute": True, "time": (keyframe.point.x,)} # set weighted tangents cmds.keyTangent(self.path, weightedTangents=weightedTangents, **arguments) # unlock tangents if either in our out handle is not defined. if not keyframe.inHandle or not keyframe.outHandle: cmds.keyTangent(self.path, lock=False, **arguments) # add in tangent to arguments if keyframe.inHandle: arguments["inAngle"] = math.degrees(inAngle.signedAngle(keyframe.inHandle)) arguments["inWeight"] = keyframe.inHandle.length() # add out tangent to arguments if keyframe.outHandle: arguments["outAngle"] = math.degrees(outAngle.signedAngle(keyframe.outHandle)) arguments["outWeight"] = keyframe.outHandle.length() # set keyframe tangent cmds.keyTangent(self.path, **arguments) # ------------------------------------------------------------------------
Example #9
Source File: dagmenu.py From mgear_core with MIT License | 5 votes |
def __keyframe_nodes_callback(*args): """Wrapper function to call Maya's setKeyframe command on given controls Args: list: callback from menuItem """ cmds.setKeyframe(args[0])
Example #10
Source File: ml_animCurveEditor.py From ml_tools with MIT License | 5 votes |
def cutLater(selectionOption=1, setKey=True): keySel = _getKeySelection(selectionOption) keySel.toEnd() timeValue = keySel._timeRangeStart-keySel.shortestTime if setKey and keySel.findKeyframe('next', time=(timeValue,)) > timeValue: mc.setKeyframe(keySel.curves, time=(timeValue,)) keySel.cutKey()
Example #11
Source File: ml_animCurveEditor.py From ml_tools with MIT License | 5 votes |
def cutEarlier(selectionOption=1, setKey=True): keySel = _getKeySelection(selectionOption) keySel.fromBeginning() if setKey and keySel.findKeyframe('previous', time=(keySel._timeRangeEnd,)) < keySel._timeRangeEnd : mc.setKeyframe(keySel.curves, time=keySel._timeRangeEnd) keySel.cutKey()
Example #12
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def bakeSprings(model=None): """Bake the automatic spring animation to animation curves Args: model (dagNode): The rig top node """ # filters the root node from selection if not model: model = getRootNode() print("Using root: {}".format(model)) # first clear animation clearSprings(model) # bake again springNodes = getControlers(model, gSuffix=PLOT_GRP_SUFFIX) if springNodes: start = pm.playbackOptions(q=True, min=True) end = pm.playbackOptions(q=True, max=True) ct = start for i in range(int(end - start) + 1): pm.currentTime(int(ct)) pm.setKeyframe(springNodes, insertBlend=True, attribute='rotate') ct += 1
Example #13
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def keyGroup(model, groupSuffix): """Keyframe all the members of a given group Args: model (PyNode): Rig top node groupSuffix (str): The group preffix """ controlers = getControlers(model, groupSuffix) pm.setKeyframe(controlers) # ================================================
Example #14
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def keyAll(model): """Keyframe all the controls inside the controls group Note: We use the workd "group" to refer to a set in Maya Args: model (PyNode): Rig top node """ controlers = getControlers(model) pm.setKeyframe(controlers)
Example #15
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
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)
Example #16
Source File: anim_utils.py From mgear_core with MIT License | 5 votes |
def keySel(): """Key selected controls""" pm.setKeyframe() # ================================================
Example #17
Source File: ml_utilities.py From ml_tools with MIT License | 4 votes |
def setKeyframe(self, deleteSubFrames=False, **kwargs): ''' Wrapper for the setKeyframe command. Curve and time arguments will be provided based on how this object was intitialized, otherwise usage is the same as maya's setKeyframe command. Option to delete sub-frames after keying. ''' if not 'time' in kwargs: #still not sure about how I want to do this, but we need a discrete time. #if time is a string set to current time if isinstance(self.time, tuple) and (isinstance(self.time[0], str) or len(self.time)>1): kwargs['time'] = mc.currentTime(query=True) else: kwargs['time'] = self.time if 'insert' in kwargs and kwargs['insert'] == True: #setKeyframe fails if insert option is used but there's no keyframes on the channels. #key any curves with insert, then key everything again without it if self.curves: mc.setKeyframe(self.curves, **kwargs) kwargs['insert'] = False #want to try setting keys on nodes first, since certain setKeyframe arguments wont work #as expected with channels if self._nodes: mc.setKeyframe(self.nodes, **kwargs) self._curves = mc.keyframe(self.nodes, query=True, name=True) else: mc.setKeyframe(self.channels, **kwargs) self._curves = mc.keyframe(self.channels, query=True, name=True) #there's a new selection of curves, so reset the member variables self._channels = list() self._nodes = list() self._time = kwargs['time'] if deleteSubFrames: #remove nearby sub-frames #this breaks at higher frame ranges because maya doesn't keep enough digits #this value is also different for different frame rates if self.currentTime % 1 == 0 and -9999 < self.currentTime < 9999: #the distance that keys can be is independent of frame rate, so we have to convert based on the frame rate. tol = self.shortestTime self.cutKey(time=(self.currentTime+tol, self.currentTime+0.5)) self.cutKey(time=(self.currentTime-0.5, self.currentTime-tol))
Example #18
Source File: ml_stopwatch.py From ml_tools with MIT License | 4 votes |
def addMarksToScene(marks): ''' This is temp and will possibly be rolled into future releases. ''' start,end = utl.frameRange() camera = utl.getCurrentCamera() camShape = mc.listRelatives(camera, shapes=True)[0] aov = mc.getAttr(camShape+'.horizontalFilmAperture') name = 'ml_stopwatch_' numStopwatches = len(mc.ls(name+'*', type='locator')) top = mc.spaceLocator(name=name+'#') ename = ':'.join([str(x) for x in marks]) mc.addAttr(top, longName='keyTimes', at='enum', enumName=ename, keyable=True) markRange = float(marks[-1]-marks[0]) viewWidth = aov*2 viewHeight = -0.4*aov+(numStopwatches*aov*0.08) depth = 5 for mark in marks[1:-1]: ann = mc.annotate(top, text=str(mark)) mc.setAttr(ann+'.displayArrow', 0) #parent annT = mc.parent(mc.listRelatives(ann, parent=True, path=True), top)[0] annT = mc.rename(annT, 'mark_'+str(round(mark))) ann = mc.listRelatives(annT, shapes=True, path=True)[0] #set the position normalX = float(mark-marks[0])/markRange-0.5 mc.setAttr(annT+'.translateX', viewWidth*normalX*2) mc.setAttr(annT+'.translateY', viewHeight) mc.setAttr(annT+'.translateZ', -depth) #keyframe for color mc.setAttr(ann+'.overrideEnabled', 1) mc.setKeyframe(ann, attribute='overrideColor', value=17, time=(int(marks[0]-1),int(mark+1))) mc.setKeyframe(ann, attribute='overrideColor', value=13, time=(int(mark),)) mc.keyTangent(ann+'.overrideColor', ott='step') mc.select(clear=True) mc.parentConstraint(camera, top)