cwisbg

DataRead

Jan 17th, 2019
720
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # cwisbg.com
  2. # updated 1-17-19
  3. # 9-27-17
  4.  
  5. # Current Data Structure, comma seperated
  6. # Frame, translate.x, translate.y, translate.z, rotate.x, rotate.y, rotate.z
  7. # will bake animation to a locator based on data
  8. from pymel.core import *
  9. w = workspace(act=1, q=1)
  10. fileLocation = fileDialog2(dir = w, ds=1, fm = 1 )[0].replace("\\","/")  
  11. fname = fileLocation
  12. src = open(fname, 'r').readlines()
  13. src = [x.rstrip() for x in src]
  14. i = 0
  15. def grpr(name):
  16.     g = ls(name)
  17.     if not g:
  18.         g = group(n=name,em=1)
  19.     return g
  20. name = "Data"
  21. dataGrp = grpr(name)
  22. l = ls("{0}{1}_lctr".format(name,i))
  23. if not l:
  24.     l = spaceLocator(n = "{0}{1}_lctr".format(name,i))
  25. lineTracker = 0
  26. for line in src:
  27.     doLine = True
  28.     #print "At line ", lineTracker
  29.     data = line.split(",") # Split at Comma, change ',' to desired split character
  30.     if len(data) < 1:
  31.         print "line is empty, skipping"
  32.         pass
  33.     else:
  34.         #print data
  35.         frame = data[0] # Frame
  36.         tx = data[1] # Translate X
  37.         ty = data[2] # Translate Y
  38.         tz = data[3] # Translate Z
  39.         rx = data[4] # Rotation X
  40.         ry = data[5] # Rotation Y
  41.         rz = data[6] # Rotation Z
  42.         if not tx or not ty or not tz or not rx or not ry or not rz:
  43.             doLine = False
  44.         if doLine:
  45.             currentTime(frame, u=1)
  46.             ll = spaceLocator(n = "{0}_{1}_lctr".format(name, frame))
  47.             move(ll, float(tx),float(ty),float(tz))
  48.             rotate(ll, float(rz),float(ry),float(rx))
  49.             parent(ll, dataGrp)
  50.             move(l, float(tx),float(ty),float(tz))
  51.             rotate(l, float(rz),float(ry),float(rx))
  52.             setKeyframe(l, at = "translate")
  53.             setKeyframe(l, at = "rotate")
  54.            
  55.         i += 1
  56.         lineTracker += 1
Advertisement
Add Comment
Please, Sign In to add comment