cwisbg

locateAnimation_v1

Oct 10th, 2012
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.80 KB | None | 0 0
  1. # locateAnimation_v1
  2. # Works with transform, and component selection
  3. # www.cwisbg.com
  4. from pymel.core import *
  5. import maya.cmds as cmds
  6. currentSceneScale = currentUnit(q=1, l=1)
  7. tempSceneScale = currentUnit(l = "cm")
  8. def setMotion(sl,ll):
  9.     slType = nodeType(sl[0])
  10.     if slType == "transform":
  11.         x = 0
  12.         for s in sl:
  13.             papCheck = listRelatives(s,p=1)
  14.             parent(s,w=1)
  15.             st = s.getTranslation()
  16.             sr = s.getRotation()
  17.             move(ll[x], st, ws=1)
  18.             rotate(ll[x], sr)
  19.             setKeyframe(ll[x], at = "translate")
  20.             setKeyframe(ll[x], at = "rotate")
  21.             parent(s, papCheck)
  22.             x += 1
  23.     elif slType == "mesh":
  24.         select(cl=1)
  25.         select(sl)
  26.         setToolTo('Move')
  27.         piv = manipMoveContext('Move', q=True, p=True,m=2)
  28.         move(ll[0], piv, ws=1)
  29.         setKeyframe(ll[0], at = "translate")
  30.     else:
  31.         print "nope, select something else"
  32.         pass   
  33. def locateList(sl):
  34.     ll = []
  35.     for s in sl:
  36.         l = spaceLocator(p = (0,0,0), n = "{0}_savedPlace".format(s))
  37.         ll.append(l)
  38.     return ll
  39. tStart = playbackOptions(q=1,ast=1)
  40. tEnd = playbackOptions(q=1,aet=1)
  41. sl = selected()
  42. ll = locateList(sl)
  43. #aniLen = tStart + tEnd -1
  44. progWin = progressWindow(isInterruptable=1, t= "Please wait", min = tStart, max = tEnd)
  45. runing = 1
  46. i = 0
  47. while runing:
  48.     progressControl = progressWindow(progWin, edit=True, pr = i)
  49.     if len(sl)  == 0:
  50.         break
  51.     if i == tEnd:
  52.         break
  53.     i += 1
  54.     currentTime(i, u=1)
  55.     setMotion(sl,ll)# gets and sets Animation
  56.     tStart += 1
  57.     if progressWindow(progWin, query=1, isCancelled=1):
  58.         print "killed at Frame", i
  59.         break  
  60. progressWindow(progWin, endProgress=1)
  61. currentUnit(l = currentSceneScale)
  62. print "Done"
Advertisement
Add Comment
Please, Sign In to add comment