Save EcoSystem
[codesyntax lang=”python”]
#******************************************************
# Generate a CSV file from an ecosystem
#
# - ecotocsv.py
# - By Mark Caldwell
# - Version 0.2
# - 2nd July 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 maximum_objects below
# if you want to risk more that 1000 instances.
# Edit start if you want to start with an instance other than
# object 0
# Edit file to set where the file will be 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
#----------------------------------------------
maximum_objects=15000 # maximum_objects sets the maximum number of instances that the script will read
# this stops it running away and crashing Vue by trying to create a billion line CSV file
start=0 # The number of the instance to start generating the CSV with
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
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!)
#--------------------------------------------------------------------------
# Test the user has a scene loaded
#--------------------------------------------------------------------------
if TestLoaded():
#--------------------------------------------------------------------------
# Test the user has 1 object selected with an Eco System on it
#--------------------------------------------------------------------------
numselected=CountSelectedObjects()
if numselected>1:
message="Please select only one object."
elif numselected<1:
message="Please select an object."
else:
#--------------------------------------------------------------------------
#Set Up a Few Variables
#--------------------------------------------------------------------------
bObject=GetSelectedObjectByIndex(0) # Get first selected object
Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
length=len(object_filename_clean)
objlist=[bObject]
if Eco==None:
message="Please select an object with an EcoSystem material applied to it."
elif bObject.IsLocked(): # Check object isn't locked
message="Please select an object that isn't locked."
else:
ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
if ecocount>(maximum_objects+start): # If this is greater than maximum_objects restrict it to maximum objects
ecocount=(maximum_objects+start)
if ecocount==0:
message="Please select an EcoSystem that has been populated."
else:
#--------------------------------------------------------------------------
# Create Objects
#--------------------------------------------------------------------------
output=open (file,'w')
firstline='Instance,Position X,Position Y,Position Z,Rotation X,Rotation Y,Rotation Z,Scale X,Scale Y,Scale Z,Filename,Action'
output.write(firstline)
output.write('\n')
for i in range(start,ecocount):
pos=Eco.GetInstancePosition (i) # Get instance position
rot=Eco.GetInstanceRotation (i) # Get instance rotation
sca=Eco.GetInstanceScale (i) # Get instance scale
filename=Eco.GetInstanceFilename (i) # Get instance filename
filename=filename[length:]
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'
output.write(csvline)
output.write('\n')
output.close()
message="Eco to CSV Successful"
else:
message="No Scene Loaded"
Message(message) # Display message
#--------------------------------------------------------------------------
# End of Script
#--------------------------------------------------------------------------
[/codesyntax]
Load EcoSystem
[codesyntax lang=”python”]
#******************************************************
# Generate a CSV file from an ecosystem
#
# - csvtoeco.py
# - By Mark Caldwell
# - Version 0.2
# - 4th July 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='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
#--------------------------------------------------------------------------
# Test the user has a scene loaded
#--------------------------------------------------------------------------
if TestLoaded():
#--------------------------------------------------------------------------
# Test the user has 1 object selected with an Eco System on it
#--------------------------------------------------------------------------
numselected=CountSelectedObjects()
if numselected>1:
message="Please select only one object."
elif numselected<1:
message="Please select an object."
else:
#--------------------------------------------------------------------------
#Set Up a Few Variables
#--------------------------------------------------------------------------
bObject=GetSelectedObjectByIndex(0) # Get first selected object
Eco = GetEcosystemOnObject(bObject) # Get EcoSystem on first selected
objlist=[bObject]
if Eco==None:
message="Please select an object with an EcoSystem material applied to it."
elif bObject.IsLocked(): # Check object isn't locked
message="Please select an object that isn't locked."
else:
ecocount=Eco.GetInstanceCount () # Count number of instances in EcoSystem
#--------------------------------------------------------------------------
# Apply to Instances
#--------------------------------------------------------------------------
file=open(file,'r')
count=0
check=0
line = file.readline() # Throw away the header line
message="CSV to Eco Successful"
while 1:
line = file.readline()
if not(line):
break
line=line.strip()
bits=line.split(',')
if int(bits[0])<=ecocount and str(bits[11])=='T':
name=int(bits[0])
x=float(bits[1])
y=float(bits[2])
z=float(bits[3])
rx=float(bits[4])
ry=float(bits[5])
rz=float(bits[6])
sx=float(bits[7])
sy=float(bits[8])
sz=float(bits[9])
Eco.SetInstancePosition(name,x,y,z)
Eco.SetInstanceRotation(name,rx,ry,rz)
Eco.SetInstanceScale(name,sx,sy,sz)
elif int(bits[0])<=ecocount and str(bits[11])=='D':
name=int(bits[0])
Eco.DeleteInstance (name)
else:
message="CSV to Eco Fail"
break
else:
message="No Scene Loaded"
Message(message) # Display message
#--------------------------------------------------------------------------
# End of Script
#--------------------------------------------------------------------------
[/codesyntax]

