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))
评论列表
文章目录