impworks Logo - a grinning imp in flight

Camera Save and Load as CSV Files

Two python scripts for Vue for loading and saving camera information to and from CSV files (comma separated values). savecameradata.py saves camera position, focus and other data into a CSV file. loadcameradata.py loads a CSV file into Vue and applies it to the camera. The two scripts are useful for moving camera animations between scenes.

It also allows a stationary camera to be moved between scenes.

Python Code – Save Camera Animation

  1. #******************************************************
  2. # Save Camera Data to a CSV file
  3. #
  4. # - savecameradata.py
  5. # - By Mark Caldwell
  6. # - Version 0.3
  7. # - 1st September 2009
  8. # - Copyright Mark Caldwell 2006
  9. # - Tested with Vue 7 Infinite 7.5
  10. #
  11. # How to use in 4 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Change Path to Saved File
  16. #
  17. # 3. Then run script and wait for it to work
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. # 4. Camera path and rotation are now stored in the CSV
  22. # File and can be loaded using loadcameradata.csv
  23. #
  24. #******************************************************
  25.  
  26. #------------------------------------------------------------------
  27. # Filename to Save Data To - Change as required for your computer
  28. #------------------------------------------------------------------
  29.  
  30. filename="C:\Users\foo\Documents\e-on software\camera.csv"
  31.  
  32. #----------------------------------------------
  33. # Internal Variables Set Up: Don't alter these
  34. #----------------------------------------------
  35.  
  36. end=0
  37. frames=[]
  38. currentframe=0
  39. oldframe=currentframe+1
  40. SetCurrentFrame (0)
  41.  
  42. #----------------------------------------------
  43. # Find the camera
  44. #----------------------------------------------
  45.  
  46. SelectByType(VuePython.VOT_Camera)
  47. camobj = GetSelectedObjectByIndex(0)
  48. cam=camobj.ToCamera()
  49.  
  50. #----------------------------------------------
  51. # Find the first key frame if it comes before
  52. # frame 0
  53. #----------------------------------------------
  54.  
  55. SetCurrentFrame(currentframe)
  56.  
  57. while end==0:
  58. PreviousKeyFrame ()
  59. currentframe=CurrentFrame ()
  60. if currentframe<oldframe:
  61. oldframe=currentframe
  62. else:
  63. end=1
  64.  
  65. #----------------------------------------------
  66. # Step through key frames and read camera info
  67. #----------------------------------------------
  68.  
  69. end=0
  70. oldframe=currentframe-2
  71. SetCurrentFrame(currentframe-1)
  72. framecount=0
  73.  
  74. while end==0:
  75. NextKeyFrame ()
  76. currentframe=CurrentFrame ()
  77.  
  78. if currentframe>oldframe:
  79. oldframe=currentframe
  80. pos=camobj.Position()
  81. rot=camobj.GetRotationAngles()
  82. dof=cam.DepthOfField()
  83. exp=cam.Exposure ()
  84. foc=cam.Focal ()
  85. focdis=cam.FocusDistance ()
  86. abr=cam.LensAberration ()
  87. hor=cam.HorizontalFilmShift()
  88. ver=cam.VerticalFilmShift ()
  89. frames.append([currentframe,pos[0],pos[1],pos[2],rot[0],rot[1],rot[2],dof,exp,foc,focdis,abr,hor,ver])
  90. framecount=framecount+1
  91. else:
  92. end=1
  93.  
  94. #----------------------------------------------
  95. # Write out camera data to file
  96. #----------------------------------------------
  97.  
  98. output=open (filename,'w')
  99. for f in frames:
  100. if framecount==1:
  101. f[0]=0
  102. line=str(f[0])+','+str(f[1])+','
  103. for n in range (2,14):
  104. line=line+str(float(f[n]))
  105. if n<13:
  106. line=line+','
  107. else:
  108. line=line+'\n'
  109. output.write(line)
  110. output.close()
  111.  
  112. Refresh ()
  113.  
  114. #----------------------------------------------
  115. # End of Script
  116. #----------------------------------------------

Python Code – Load Camera Animation

  1. #******************************************************
  2. # Loads Camera Data from a CSV file
  3. #
  4. # - loadcameradata.py
  5. # - By Mark Caldwell
  6. # - Version 0.3
  7. # - 1st September 2009
  8. # - Copyright Mark Caldwell 2006
  9. # - Tested with Vue 7 Infinite 7.5
  10. #
  11. # How to use in 3 easy steps
  12. #
  13. # 1. Download this file onto your computer
  14. #
  15. # 2. Change Path to Saved File if required and camera to be edited
  16. #
  17. # 3. Then run script and wait for it to work
  18. # To run it go to Python -> Run Python Script
  19. # Then locate the file on your computer
  20. #
  21. #******************************************************
  22.  
  23. #-------------------------------------------------------------------
  24. # Change yo the same as savecameradata.py
  25. #-------------------------------------------------------------------
  26.  
  27. #Filename to Load Data From - Change if different on your computer
  28. filename="C:\Users\foo\Documents\e-on software\camera.csv"
  29.  
  30. #----------------------------------------------
  31. # End of Changeable Parts
  32. #----------------------------------------------
  33.  
  34. frames=[]
  35.  
  36. #----------------------------------------------
  37. # Select or create the Camera
  38. #----------------------------------------------
  39.  
  40. cam=StoreCamera ()
  41. SelectByType(VuePython.VOT_Camera)
  42. camobj = GetSelectedObjectByIndex(0)
  43. cam=camobj.ToCamera()
  44.  
  45. #----------------------------------------------
  46. # Read Camera Data in from CSV file
  47. #----------------------------------------------
  48.  
  49. file=open(filename,'r')
  50.  
  51. while 1:
  52. line = file.readline()
  53. if not(line):
  54. break
  55.  
  56. b=line.split(',')
  57. frames.append([float(b[0]),float(b[1]),float(b[2]),float(b[3]),float(b[4]),float(b[5]),float(b[6]),
  58. float(b[7]),float(b[8]),float(b[9]),float(b[10]),float(b[11]),float(b[12]),float(b[13])])
  59.  
  60. file.close()
  61.  
  62. #----------------------------------------------
  63. # Apply animation
  64. #----------------------------------------------
  65.  
  66. for data in frames:
  67. SetCurrentFrame (data[0])
  68. camobj.SetPosition(data[1],data[2],data[3])
  69. camobj.SetRotationAngles(data[4],data[5],data[6],true)
  70. cam.SetDepthOfField(data[7])
  71. cam.SetExposure (data[8])
  72. cam.SetFocal (data[9])
  73. cam.SetFocusDistance (data[10])
  74. cam.SetLensAberration (data[11])
  75. cam.SetHorizontalFilmShift(data[12])
  76. cam.SetVerticalFilmShift (data[13])
  77.  
  78. Refresh ()
  79.  
  80. #----------------------------------------------
  81. # End of Script
  82. #----------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017