def invertCurve(self, animationCurve): """ Scale the values by negative one, """ pm.scaleKey( animationCurve, valueScale=-1, valuePivot=0, )
def scaleChara(self, mayaFalse): #this part does the importing and admin stuff try: pm.createReference( '//p.sv/Prism/project/Parallel/element/character_Roll/scenes/' + pm.optionMenu(self.charalist, q=True, value=True)[-4:-1] + '001_SP01.mb', namespace=':') except: pm.confirmDialog(title=u'Parallel scaling', message=u'Parallel フォルダーの許可がないです。') #this part does the scaling pm.optionMenu('listofchara', q=True, value=True) inverseScale = 1 / self.nameScale[pm.optionMenu( self.charalist, q=True, value=True)] pm.scale('Reference|Root', inverseScale, inverseScale, inverseScale) for i in pm.listRelatives('Reference', ad=True, type='joint'): try: pm.copyKey(i) pm.pasteKey(i.replace('Reference', 'Reference1')) except: print 'no keys to copypasta' pm.scaleKey('Reference1|Root|Hips', valueScale=inverseScale, valuePivot=0, attribute='translate') #this part cleans up the file pm.delete('Reference') pm.listReferences()[0].importContents(removeNamespace=False) pm.rename('Reference1', 'Reference')
def convertFrameRate(fromFPS, toFPS, nodes='all'): ''' :param fromFPS: originial frame rate, eg 25 :param toFPS: target frame rate, eg 24 :param nodes: the nodes to scale. All will scale all keyframes in the scene :return: scaledKeys: Nr of keys to be scaled example: convertFrameRate(25, 24, nodes='all') ''' scaledKeys = [] by = (float(fromFPS) * 1.0000000) / (float(toFPS) * 1.000000) print 'Scaling by %s' % by if nodes == 'all': anim_curves = cmds.ls( type=['animCurveTA', 'animCurveTL', 'animCurveTT', 'animCurveTU']) else: anim_curves = nodes for each in anim_curves: try: pm.scaleKey(each, timeScale=by) scaledKeys.append(each) except: pass print 'Done. Scaled %s Keyframe by %s' % (len(scaledKeys), by) return len(scaledKeys)
def spaceScale(attr, cvNew, scale): """ """ # Translate if attr.startswith('translate'): pm.scaleKey(cvNew, vs= scale, vp= 0, ssk= False) # Scale if attr.startswith('scale'): pm.scaleKey(cvNew, vs= scale, vp= 1, ssk= False)
def keyMirror(attr, cvNew, mirror): """ """ for axis in mirror: # Translate if axis.startswith('t') and attr.startswith('translate' + axis[-1].upper()): pm.scaleKey(cvNew, vs= -1, vp= 0, ssk= False) # Rotation if axis.startswith('r') and attr.startswith('rotate' + axis[-1].upper()): pm.scaleKey(cvNew, vs= -1, vp= 0, ssk= False)
def scaleKeyframes(by=1.041666666666667, nodes='all'): # to do a scene conversion from 25 to 24 frames per sec if nodes == 'all': anim_curves = cmds.ls( type=['animCurveTA', 'animCurveTL', 'animCurveTT', 'animCurveTU']) else: anim_curves = nodes for each in anim_curves: pm.scaleKey(each, timeScale=by) print 'Done. Scaled %s Keyframe' % len(anim_curves)
def reverseCurve( timePiv=None ): """ Reverse the selected curve(s). If timePiv is C{'None'}, curve will be reversed at current time. @param timePiv: timePiv: C{None} If timePiv is C{'None'}, curve will be reversed at current time. @type timePiv: float """ for curve in getSelectedCurvesKeys().iterkeys(): if timePiv is None: timePiv = ( pm.findKeyframe( curve, which='first' ) + pm.findKeyframe( curve, which='last' ) ) / 2 else: pass pm.scaleKey( curve, timeScale= -1.0, timePivot=timePiv )
def scale_keys_value_multi(self): """Scales each selected curve's keys independently on their own pivots""" # Go through each curve, finding the times and values for each and apply the pivot for that curve for curve in self.curves: self.key_values = self.get_key_values(curve) self.key_times = self.get_key_times(curve) pivot = self.get_pivot() for i in xrange(len(self.key_values)): pm.scaleKey(curve, valuePivot=pivot, valueScale=self.scale, time=(self.key_times[i], self.key_times[i]))
def scaleani(arg): selACs = pm.textScrollList("keyattr",q=1,si=1) start = pm.textField('startnum',q=True,tx=True) end =pm.textField('endnum',q=True,tx=True) sel = pm.ls(sl=1) if sel !=[]: for i in range(len(sel)): selAC = pm.listConnections(sel[i],d=0,type="animCurve") if selAC !=[]: selattr = pm.listConnections(sel[i],d=0,plugs=1,type="animCurve") for a in range(len(selattr)): aniattr = pm.listConnections(selattr[a],s=0,plugs=1) if aniattr!=[]: if aniattr[0] in selACs: attrname = str(aniattr[0])[(len(aniattr[0].split(".")[0])+1):] pm.scaleKey(iub=False,newStartTime=start,newEndTime=end,attribute=attrname)
def flipCurve( curves=None, valuePiv=None ): """ Flip the selected curve(s). If valuePiv is C{'None'}, curve will be flipped over value at current time. @param valuePiv: default: C{None} If valuePiv is C{'None'}, curve will be flipped over value at current time. @type valuePiv: float """ if curves is None: curves = getSelectedCurvesKeys().iterkeys() for curve in curves: if valuePiv is None: valuePiv = pm.keyframe( curve, query=True, eval=True )[0] else: pass pm.scaleKey( curve, valueScale= -1.0, valuePivot=valuePiv )
def scale_keys_time_multi(self): """Scales each selected curve's keys independently in time on their own pivots""" for curve in self.curves: self.key_times = self.get_key_times(curve) # if we're scaling time from the last key, we need to iterate backwards through the scaling or some values # will give weird results as the first keys end up after ones not yet scaled if self.pivot == 'pivot_last_time': key_range = reversed(xrange(len(self.key_times))) else: key_range = xrange(len(self.key_times)) for i in key_range: pm.scaleKey(curve, timePivot=(self.get_pivot()), timeScale=self.scale, time=(self.key_times[i], self.key_times[i])) pm.snapKey(tm=1.0)
def scale_keys_time(self): """Scales all selected keys in time from a single pivot for all""" pm.scaleKey(timePivot=(self.get_pivot()), timeScale=self.scale) # Snap all keys so there are no subframe keys pm.snapKey(tm=1.0)
def scale_keys_value(self): """Scales all selected keys in value from a single pivot for all""" pm.scaleKey(valuePivot=self.get_pivot(), valueScale=self.scale)