Save Terrain
[codesyntax lang=”python”]
#******************************************************
# Generate a CSV file from a Terrain
#
# - terraintocsv.py
# - By Mark Caldwell
# - Version 0.1
# - 29th August 2006
# - Tested with Vue 5 Infinite 5.10 and Vue 6 Pre Release
#
# How to use in 4 easy steps
#
# 1. Download this file onto your computer
#
# 2. Edit file to set where the file will be saved
#
# 3. Select a Terrain Object
#
# 4. Then run script and wait for it to work
# To run it go to Python -> Run Python Script
# Then locate the file on your computer
#
#******************************************************
#----------------------------------------------
# Configuration: Set these to alter end result
#----------------------------------------------
file='terraindata.csv' # Full Path to where you want the CSV data saved
#--------------------------------------------------------------------------
# Test the user has a scene loaded
#--------------------------------------------------------------------------
if TestLoaded():
#--------------------------------------------------------------------------
# Test the user has 1 object selected and it is a terrain
#--------------------------------------------------------------------------
numselected=CountSelectedObjects()
if numselected>1:
message="Please select only one object."
elif numselected<1:
message="Please select an object."
else:
#--------------------------------------------------------------------------
# Read the terrain and generate a CSV file from it
#--------------------------------------------------------------------------
bObject=GetSelectedObjectByIndex(0) # Get first selected object
if bObject.IsTerrain()==False:
message="Please select a terrain."
elif bObject.IsLocked(): # Check object isn't locked
message="Please select an object that isn't locked."
else:
TerrainObj=bObject.ToTerrain() # Get Terrain Object
height= TerrainObj.Height() # Get Terrain Objects Height
width= TerrainObj.Width() # Get Terrain Objects Width
altitudes=TerrainObj.TerrainAltitudes () # Get the Terrain Objects Altitude Array
output=open (file,'w')
for i in range (0,height):
line=""
for j in range (0,width):
line=line+str(altitudes[i][j])
if j<(width-1):
line=line+','
output.write(line)
output.write('\n')
output.close()
message="Terrain to CSV Successful"
else:
message="No Scene Loaded"
Message(message) # Display message
#--------------------------------------------------------------------------
# End of Script
#--------------------------------------------------------------------------
[/codesyntax]
Load Terrain
[codesyntax lang=”python”]
#******************************************************
# Generate a CSV file from an ecosystem
#
# - terraintoeco.py
# - By Mark Caldwell
# - Version 0.1
# - 29th August 2006
# - Tested with Vue 5 Infinite 5.10 and Vue 6 Pre Release
#
# How to use in 4 easy steps
#
# 1. Download this file onto your computer
#
# 2. Edit the configuration variable file to set where the file was saved
#
# 3. Select an object with a populated EcoSystem applied
#
# 4. Then run script and wait for it to work
# To run it go to Python -> Run Python Script
# Then locate the file on your computer
#
#******************************************************
#----------------------------------------------
# Configuration: Set these to alter end result
#----------------------------------------------
file='terraindata.csv' # Full Path to where you saved the CSV file
#--------------------------------------------------------------------------
# Test the user has a scene loaded
#--------------------------------------------------------------------------
if TestLoaded():
#--------------------------------------------------------------------------
# Test the user has 1 object and that it is a terrain
#--------------------------------------------------------------------------
numselected=CountSelectedObjects()
if numselected>1:
message="Please select only one object."
elif numselected<1:
message="Please select an object."
else:
bObject=GetSelectedObjectByIndex(0) # Get first selected object
if bObject.IsTerrain()==False:
message="Please select a terrain."
elif bObject.IsLocked(): # Check object isn't locked
message="Please select an object that isn't locked."
else:
#--------------------------------------------------------------------------
# Apply terrain data to terrain
#--------------------------------------------------------------------------
altitudes=[]
TerrainObj=bObject.ToTerrain()
file=open(file,'r')
while 1:
line = file.readline()
if not(line):
break
bits=line.split(',')
alt=[]
for x in bits:
alt.append(float(x))
altitudes.append(alt)
TerrainObj.SetTerrainAltitudes (altitudes) # Set terrain heights
message="CSV to Eco Successful"
else:
message="No Scene Loaded"
Refresh()
Message(message) # Display message
#--------------------------------------------------------------------------
# End of Script
#--------------------------------------------------------------------------
[/codesyntax]

