Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#Create or remove velocity channels for keyframes and expressions

from pymel.core import *


import sys
if not (objExists('velocityChannelStuff')):
selection = ls(sl=1)
curvs = ls(typ='animCurve') + ls(typ='expression')
vChannels = []
vExpressions = []
count = 0
if curvs:
for node in curvs:
for connected in listConnections(node+'.output', p=1):
print connected
addAttr(connected.split('.')[0], ln=connected.split('.')[-
1]+'_velocity', at='float', k=0, h=1)
count +1
vExpression = expression(o=connected.split('.')[0],
s=connected.split('.')[0]+'.'+connected.split('.')[-1]+'_velocity'+' = `getAttr -t
(frame) '+connected+'` - `getAttr -t (frame-1) '+connected+'`',
name='vExpr'+str(count))
vChannels.append(connected.split('.')[0]+'.'+connected.split('.')[-
1]+'_velocity')
vExpressions.append(str(vExpression))
createNode('script', n='velocityChannelStuff')
addAttr('velocityChannelStuff', dt='string', ln='vChannelsList')
addAttr('velocityChannelStuff', dt='string', ln='vExpressionsList')
addAttr('velocityChannelStuff', dt='string', ln='showResultsState')
setAttr('velocityChannelStuff.vChannelsList', ','.join(vChannels))
setAttr('velocityChannelStuff.vExpressionsList', ','.join(vExpressions))
setAttr('velocityChannelStuff.showResultsState',
animCurveEditor('graphEditor1GraphEd', q=1, showResults=1))
animCurveEditor('graphEditor1GraphEd', edit=1, showResults=1)
select(selection)
sys.stdout.write('Created Velocity Channels')
else:
sys.stdout.write('There\'s no animation to add velocity channels to.')
else:
vChannels = getAttr('velocityChannelStuff.vChannelsList').split(",")
vExpressions = getAttr('velocityChannelStuff.vExpressionsList').split(",")
for vChannel in vChannels:
deleteAttr(vChannel)
for vExpression in vExpressions:
delete(vExpression)
animCurveEditor('graphEditor1GraphEd', edit=1,
showResults=(getAttr('velocityChannelStuff.showResultsState')))
delete('velocityChannelStuff')
sys.stdout.write('Removed Velocity Channels')

You might also like