Sunday, September 30, 2007

Drag and Drop



These few video tutorials show you how the script editor in Ecotect makes it extremely easy to write scripts using the "drag and drop" style code editor.



first you will open the ecotect script editor



to start you will want to write this simple framework for exporting data to a txt file.

the code will look like this.

filename = getUserFile(1, "Save Script Output to...")

file = openfile (filename, "w")

write(file, "Print this text to the selected file.")

closefile(file)



next you will want to use the drag and drop code editor to drop in some predefined code that iterates though the analysis grid in ecotet.

under the script editor language help you will go to Example Code templates > User Defined Templates > Customizing your templates > Cycle through grid data and drop that item into your editor window.

when you are done your code will look like this...

filename = getUserFile(1, "save script output to....");

file = openfile (filename, "w");

x,y = get("grid.size")
print("Cells", x, y)

for j = 0, y-1 do

line = ""

for i = 0, x-1 do
value = get("grid.cell", i, j, 0)
line = line..format("%0.4f, ", value);
write(file, value);
write(file, "\n");
end

print(line)

end


closefile(file);

Basics

variable types

integers
x = 1
x,y,z = 5

strings are in quotations
name = "string"

tables can store many variables

table = {1,2,3,4,5,6}
print(table[1])
print(table[4])


you can organize you code into functions if you plan to reuse the same command many times.

function function_name ( args ) body end

function count(n)
return n*2
end

// use the count function

cont(7)

loops

this for loop will print the letter i 11 times
for i = 0, 10 do
print(i)
end

Important Concepts/Commands

For this tutorial there are a few key concepts/commands you will need to understand if you want to begin to export your own data sets from Ecotect.

Firstly, it is important to know where you can store data after calculations are performed and how to access that data after calculations are finished.

- All objects in Ecotect can hold up to three attributes. What these attributes are will change depending on what you kind of calculations you ask the software to preform.

Accessing the attributes:

get.object.XXX object
set.object.XXX object value

result = get("object.attr1", object)

XXX can equal any of the following....



area Surface area (m²) - if planar.
exposure Surface area exposed to outside conditions (m²) - if planar.
length Total length (m) - if linear.
underground Surface area exposed to ground conditions (m²) - if planar.
panelarea Surface overlapping a WINDOW / DOOR in adjacent zone (m²)
resolution Curve resolution for virtual polylines.
attr1 Calculated Attribute Number 1.
attr2 Calculated Attribute Number 2.
attr3 Calculated Attribute Number 3.
index Calculated Numerical Index.

Exporting to Microsoft Excel:

excel("start", "Testing")

-- Fill up 15 rows of data
for i = 1, 15 do
excel("cell", 3, i)
excel("value", i*5)
end

-- Add a formula to the bottom cell.
excel("cell", 5, 16)
excel("value", "=SUM(E1:E15)")
excel("font bold")

-- Make the cell in the 9th row bold and italic.
excel("cell", 5, 9)
excel("font", "bold italic")


Export to a .txt file:

filename = getUserFile(1, "Save Script Output to...")

file = openfile (filename, "w")

write(file, "Print this text to the selected file.")

closefile(file)


if you want to export the contents of ecotect's annalysis grid to a text file your code would look like this. (as outlined in the above tutorial.)


filename = getUserFile(1, "save script output to....");

file = openfile (filename, "w");

x,y = get("grid.size")
print("Cells", x, y)

for j = 0, y-1 do

line = ""

for i = 0, x-1 do
value = get("grid.cell", i, j, 0)
line = line..format("%0.4f, ", value);
write(file, value);
write(file, "\n");
end

print(line)

end

closefile(file);