stassius

Houdini - Premiere Timecode list parser

Aug 31st, 2017
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.44 KB | None | 0 0
  1. ## This should be pasted into the Python node in SOPs
  2. ## Add two interface parameters - "txt" of type File and "framerate" of type int
  3. ## This script is parsing a marker list from Adobe Premiere Pro. It should be saved as CSV file and next resaved with UTF-8
  4. ## On the output it creates a number of points equal to number of markers.
  5. ## Each point has attribute start as marker start (in frames) and end as marker end (in frames)
  6.  
  7. import hou
  8. import string
  9.  
  10. node = hou.pwd()
  11. geo = node.geometry()
  12.  
  13. fileParm = node.parm("txt").evalAsString()
  14. framerate = node.parm("framerate").eval()
  15.  
  16. def timecode_to_frames(timecode):
  17.     return sum(f * int(t) for f,t in zip((3600*framerate, 60*framerate, framerate, 1), timecode.split(':')))
  18.    
  19. with open(fileParm, 'r') as f:
  20.     lines = f.read().splitlines()   # Read lines
  21. f.close()
  22. Attribstart = geo.addAttrib(hou.attribType.Point, "start", 0)
  23. Attribend = geo.addAttrib(hou.attribType.Point, "end", 0)
  24. lines.pop(0) ## delete first line (text)
  25. current=0
  26. for line in lines:
  27.     times=line.split(chr(9))
  28.     current=0
  29.     for time in times:
  30.         if len(time)>0:
  31.             if time[0].isdigit():            
  32.                 if current==0:
  33.                     pt=geo.createPoint()  
  34.                     pt.setAttribValue(Attribstart, timecode_to_frames(time))
  35.                 if current==1:
  36.                     pt.setAttribValue(Attribend, timecode_to_frames(time))
  37.                 current=(current+1)%3
Advertisement
Add Comment
Please, Sign In to add comment