EcoSystem to CSV

  • EcoSystem to CSV / CSV to EcoSystem
  • Version: 0.2
  • July 4, 2006
  • 11.3 KB
  • ecocsv.zip a

This download contains two Python scripts originally written for Vue 5 Infinite. ecotocsv.py saves a selected EcoSystem as a CSV file that can be edited in most spreadsheet packages or a text editor, csvtoeco.py, loads the edited CSV file back into Vue, modifying the instances with any changes you made in the CSV. My turorial Using Eco To CSV / CSV to Eco has more detail on how to make use of these scripts.

Save EcoSystem
  1. #******************************************************
  2. # Generate a CSV file from an ecosystem
  3. #
  4. # - ecotocsv.py
  5. # - By Mark Caldwell
  6. # - Version 0.2
  7. # - 2nd July 2006
  8. # - Tested with Vue 5 Infinite 5.10 and Vue 6 Pre Release
  9. #
  10. # How to use in 4 easy steps
  11. #
  12. # 1. Download this file onto your computer
  13. #
  14. # 2. Edit the configuration variable maximum_objects below
  15. # if you want to risk more that 1000 instances.
  16. # Edit start if you want to start with an instance other than
  17. # object 0
  18. # Edit file to set where the file will be saved
  19. #
  20. # 3. Select an object with a populated EcoSystem applied
  21. #
  22. # 4. Then run script and wait for it to work
  23. # To run it go to Python -> Run Python Script
  24. # Then locate the file on your computer
  25. #
  26. #******************************************************
  27.  
  28. #----------------------------------------------
  29. # Configuration: Set these to alter end result
  30. #----------------------------------------------
  31.  
  32. maximum_objects=15000 # maximum_objects sets the maximum number of instances that the script will read
  33. # this stops it running away and crashing Vue by trying to create a billion line CSV file
  34.  
  35. start=0 # The number of the instance to start generating the CSV with
  36.  
  37. file="C:\Program Files\e-on software\Vue 5 Infinite\Python\Scripts\Impworks\ecotocsv2\eco.csv" # Full Path to where you want the CSV data saved
  38.  
  39. object_filename_clean="C:\Program Files\e-on software\Vue 5 Infinite\objects" # Remove this from the filename of instance object (Don't include last \ or it will break the script!)
  40.  
  41. #--------------------------------------------------------------------------
  42. # Test the user has a scene loaded
  43. #--------------------------------------------------------------------------
  44.  
  45. if TestLoaded():
  46.  
  47. #--------------------------------------------------------------------------
  48. # Test the user has 1 object selected with an Eco System on it
  49. #--------------------------------------------------------------------------
  50.  
  51. numselected=CountSelectedObjects()
  52.  
  53. if numselected>1:
  54. message="Please select only one object."
  55. elif numselected<1:
  56. message="Please select an object."
  57. else:
  58.  
  59. #--------------------------------------------------------------------------
  60. #Set Up a Few Variables
  61. #--------------------------------------------------------------------------
  62.  
  63. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  64. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  65.  
  66. length=len(object_filename_clean)
  67.  
  68. objlist=[bObject]
  69.  
  70. if Eco==None:
  71. message="Please select an object with an EcoSystem material applied to it."
  72. elif bObject.IsLocked(): # Check object isn't locked
  73. message="Please select an object that isn't locked."
  74. else:
  75. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  76.  
  77. if ecocount>(maximum_objects+start): # If this is greater than maximum_objects restrict it to maximum objects
  78. ecocount=(maximum_objects+start)
  79.  
  80. if ecocount==0:
  81. message="Please select an EcoSystem that has been populated."
  82. else:
  83.  
  84. #--------------------------------------------------------------------------
  85. # Create Objects
  86. #--------------------------------------------------------------------------
  87.  
  88. output=open (file,'w')
  89. firstline='Instance,Position X,Position Y,Position Z,Rotation X,Rotation Y,Rotation Z,Scale X,Scale Y,Scale Z,Filename,Action'
  90. output.write(firstline)
  91. output.write('\n')
  92. for i in range(start,ecocount):
  93. pos=Eco.GetInstancePosition (i) # Get instance position
  94. rot=Eco.GetInstanceRotation (i) # Get instance rotation
  95. sca=Eco.GetInstanceScale (i) # Get instance scale
  96. filename=Eco.GetInstanceFilename (i) # Get instance filename
  97. filename=filename[length:]
  98. csvline=str(i)+','+str(pos[0])+','+str(pos[1])+','+str(pos[2])+','+str(rot[0])+','+str(rot[1])+','+str(rot[2])+','+str(sca[0])+','+str(sca[1])+','+str(sca[2])+','+filename+',T'
  99. output.write(csvline)
  100. output.write('\n')
  101. output.close()
  102. message="Eco to CSV Successful"
  103. else:
  104. message="No Scene Loaded"
  105.  
  106. Message(message) # Display message
  107.  
  108. #--------------------------------------------------------------------------
  109. # End of Script
  110. #--------------------------------------------------------------------------

Load EcoSystem

  1. #******************************************************
  2. # Generate a CSV file from an ecosystem
  3. #
  4. # - csvtoeco.py
  5. # - By Mark Caldwell
  6. # - Version 0.2
  7. # - 4th July 2006
  8. # - Tested with Vue 5 Infinite 5.10 and Vue 6 Pre Release
  9. #
  10. # How to use in 4 easy steps
  11. #
  12. # 1. Download this file onto your computer
  13. #
  14. # 2. Edit the configuration variable file to set where the file was saved
  15. #
  16. # 3. Select an object with a populated EcoSystem applied
  17. #
  18. # 4. Then run script and wait for it to work
  19. # To run it go to Python -> Run Python Script
  20. # Then locate the file on your computer
  21. #
  22. #******************************************************
  23.  
  24. #----------------------------------------------
  25. # Configuration: Set these to alter end result
  26. #----------------------------------------------
  27.  
  28. file='C:\Program Files\e-on software\Vue 5 Infinite\Python\Scripts\Impworks\ecotocsv2\eco.csv' # Full Path to where you want the CSV data loaded from
  29.  
  30. #--------------------------------------------------------------------------
  31. # Test the user has a scene loaded
  32. #--------------------------------------------------------------------------
  33.  
  34. if TestLoaded():
  35.  
  36. #--------------------------------------------------------------------------
  37. # Test the user has 1 object selected with an Eco System on it
  38. #--------------------------------------------------------------------------
  39.  
  40. numselected=CountSelectedObjects()
  41.  
  42. if numselected>1:
  43. message="Please select only one object."
  44. elif numselected<1:
  45. message="Please select an object."
  46. else:
  47.  
  48. #--------------------------------------------------------------------------
  49. #Set Up a Few Variables
  50. #--------------------------------------------------------------------------
  51.  
  52. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  53. Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
  54.  
  55. objlist=[bObject]
  56.  
  57. if Eco==None:
  58. message="Please select an object with an EcoSystem material applied to it."
  59. elif bObject.IsLocked(): # Check object isn't locked
  60. message="Please select an object that isn't locked."
  61. else:
  62. ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
  63.  
  64. #--------------------------------------------------------------------------
  65. # Apply to Instances
  66. #--------------------------------------------------------------------------
  67.  
  68. file=open(file,'r')
  69. count=0
  70. check=0
  71.  
  72. line = file.readline() # Throw away the header line
  73.  
  74. message="CSV to Eco Successful"
  75.  
  76. while 1:
  77. line = file.readline()
  78. if not(line):
  79. break
  80.  
  81. line=line.strip()
  82.  
  83. bits=line.split(',')
  84.  
  85. if int(bits[0])<=ecocount and str(bits[11])=='T':
  86. name=int(bits[0])
  87. x=float(bits[1])
  88. y=float(bits[2])
  89. z=float(bits[3])
  90. rx=float(bits[4])
  91. ry=float(bits[5])
  92. rz=float(bits[6])
  93. sx=float(bits[7])
  94. sy=float(bits[8])
  95. sz=float(bits[9])
  96.  
  97. Eco.SetInstancePosition(name,x,y,z)
  98. Eco.SetInstanceRotation(name,rx,ry,rz)
  99. Eco.SetInstanceScale(name,sx,sy,sz)
  100. elif int(bits[0])<=ecocount and str(bits[11])=='D':
  101. name=int(bits[0])
  102. Eco.DeleteInstance (name)
  103. else:
  104. message="CSV to Eco Fail"
  105. break
  106. else:
  107. message="No Scene Loaded"
  108.  
  109. Message(message) # Display message
  110.  
  111. #--------------------------------------------------------------------------
  112. # End of Script
  113. #--------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017