forked from sschwungsau/Maya-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_speed.py
50 lines (40 loc) · 1.82 KB
/
add_speed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import maya.cmds as cmds
import math
Psel = cmds.ls( selection=True )
try:
nodeT = cmds.nodeType( Psel[0] )
print nodeT
if nodeT == 'transform':
checkAttr = cmds.objExists(Psel[0]+'.speed')
print checkAttr
if checkAttr == True:
listexpr = cmds.listConnections(Psel[0]+'.speed')
if listexpr == None :
ex1 = 'float $lastPosX = `getAttr -t (frame-1) '+Psel[0]+'.tx`;'
ex2 = 'float $lastPosY = `getAttr -t (frame-1) '+Psel[0]+'.ty`;'
ex3 = 'float $lastPosZ = `getAttr -t (frame-1) '+Psel[0]+'.tz`;'
ex4 = Psel[0]+'.speed = abs (mag (<<'+Psel[0]+'.translateX,'+Psel[0]+'.translateY,'+Psel[0]+'.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );'
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
cmds.delete(listexpr[0])
ex1 = 'float $lastPosX = `getAttr -t (frame-1) '+Psel[0]+'.tx`;'
ex2 = 'float $lastPosY = `getAttr -t (frame-1) '+Psel[0]+'.ty`;'
ex3 = 'float $lastPosZ = `getAttr -t (frame-1) '+Psel[0]+'.tz`;'
ex4 = Psel[0]+'.speed = abs (mag (<<'+Psel[0]+'.translateX,'+Psel[0]+'.translateY,'+Psel[0]+'.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );'
exAll = ex1+ex2+ex3+ex4
cmds.expression( o=Psel[0], s=exAll)
else:
print "test"
cmds.addAttr( Psel[0],longName='speed' )
ex1 = 'float $lastPosX = `getAttr -t (frame-1) '+Psel[0]+'.tx`;'
ex2 = 'float $lastPosY = `getAttr -t (frame-1) '+Psel[0]+'.ty`;'
ex3 = 'float $lastPosZ = `getAttr -t (frame-1) '+Psel[0]+'.tz`;'
ex4 = Psel[0]+'.speed = abs (mag (<<'+Psel[0]+'.translateX,'+Psel[0]+'.translateY,'+Psel[0]+'.translateZ>>)- mag (<<$lastPosX,$lastPosY,$lastPosZ>>) );'
exAll = ex1+ex2+ex3+ex4
print exAll
cmds.expression( o=Psel[0], s=exAll)
else:
print '---> select transform !'
except TypeError :
print '---> select transform !'