Terrain CSV

Here are two scripts that allow you to work with a terrain by exporting it as a CSV file that can be edited in a spreadsheet and then importing it back into Vue.

Select a terrain and then run terraintocsv.py. A file called terraindata.csv will be saved in the directory you put the script in.

Edit the CSV file in your prefered spreadsheet or text editor. Save a CSV file over the original terraindata.csv

Go back to Vue. With the original terrain selected run the csvtoterrain.py and the altered CSV file will be loaded and used to set the terrains altitudes.

Save Terrain

  1. #******************************************************
  2. # Generate a CSV file from a Terrain
  3. #
  4. # - terraintocsv.py
  5. # - By Mark Caldwell
  6. # - Version 0.1
  7. # - 29th August 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 file to set where the file will be saved
  15. #
  16. # 3. Select a Terrain Object
  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='terraindata.csv' # Full Path to where you want the CSV data saved
  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 and it is a terrain
  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. # Read the terrain and generate a CSV file from it
  50. #--------------------------------------------------------------------------
  51.  
  52. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  53.  
  54. if bObject.IsTerrain()==False:
  55. message="Please select a terrain."
  56. elif bObject.IsLocked(): # Check object isn't locked
  57. message="Please select an object that isn't locked."
  58. else:
  59. TerrainObj=bObject.ToTerrain() # Get Terrain Object
  60.  
  61. height= TerrainObj.Height() # Get Terrain Objects Height
  62. width= TerrainObj.Width() # Get Terrain Objects Width
  63.  
  64. altitudes=TerrainObj.TerrainAltitudes () # Get the Terrain Objects Altitude Array
  65. output=open (file,'w')
  66. for i in range (0,height):
  67. line=""
  68. for j in range (0,width):
  69. line=line+str(altitudes[i][j])
  70. if j<(width-1):
  71. line=line+','
  72. output.write(line)
  73. output.write('\n')
  74. output.close()
  75. message="Terrain to CSV Successful"
  76. else:
  77. message="No Scene Loaded"
  78.  
  79. Message(message) # Display message
  80.  
  81. #--------------------------------------------------------------------------
  82. # End of Script
  83. #--------------------------------------------------------------------------

Load Terrain

  1. #******************************************************
  2. # Generate a CSV file from an ecosystem
  3. #
  4. # - terraintoeco.py
  5. # - By Mark Caldwell
  6. # - Version 0.1
  7. # - 29th August 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='terraindata.csv' # Full Path to where you saved the CSV file
  29.  
  30. #--------------------------------------------------------------------------
  31. # Test the user has a scene loaded
  32. #--------------------------------------------------------------------------
  33.  
  34. if TestLoaded():
  35.  
  36. #--------------------------------------------------------------------------
  37. # Test the user has 1 object and that it is a terrain
  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. bObject=GetSelectedObjectByIndex(0) # Get first selected object
  48.  
  49. if bObject.IsTerrain()==False:
  50. message="Please select a terrain."
  51. elif bObject.IsLocked(): # Check object isn't locked
  52. message="Please select an object that isn't locked."
  53. else:
  54.  
  55. #--------------------------------------------------------------------------
  56. # Apply terrain data to terrain
  57. #--------------------------------------------------------------------------
  58.  
  59. altitudes=[]
  60. TerrainObj=bObject.ToTerrain()
  61.  
  62. file=open(file,'r')
  63.  
  64. while 1:
  65. line = file.readline()
  66. if not(line):
  67. break
  68.  
  69. bits=line.split(',')
  70.  
  71. alt=[]
  72. for x in bits:
  73. alt.append(float(x))
  74. altitudes.append(alt)
  75.  
  76. TerrainObj.SetTerrainAltitudes (altitudes) # Set terrain heights
  77.  
  78. message="CSV to Eco Successful"
  79.  
  80. else:
  81. message="No Scene Loaded"
  82.  
  83. Refresh()
  84.  
  85. Message(message) # Display message
  86.  
  87. #--------------------------------------------------------------------------
  88. # End of Script
  89. #--------------------------------------------------------------------------

impworks © Copyright Mark Caldwell 1996 - 2017