Archive site for Autodesk Ecotect Analysis educational resources, notes and tutorials



Script example 04

CreateXMLDataFile.scr

This script demonstrates the process of writing calculation data to a file. It creates a simple ecoXML file containing a single <annualHourlyData> data array. The resulting XML file can then be read and displayed by tools that support that entity.

The contents of the output file should be similar to the following (where the ... items represent other values not shown for purposes of brevity):

<?xml version="1.0" ?>
<ecoXML>
  <model>Project_5.eco</model>
  <date>02/07/07 15:54:01</date>
  <annualHourlyData>
    <data units=Watts>Hourly Direct Solar Gains (sQd)</data>
    <day no=001>0,0,0,0,0,1026,23771, ... 0,0,0,0,</day>
    <day no=002>0,0,0,0,0,2764,48315, ... 0,0,0,0,</day>
    ...
    <day no=365>0,0,0,0,0,2873,32211, ... 0,0,0,0,</day>
  </annualHourlyData>
</ecoXML>

Script Contents (Lang: lua)

-- ---------------------------------------------
-- EXTRACT HOURLY DIRECT SOLAR GAINS:
-- This script extracts hourly direct solar gains
-- (sQg) from the current model over the year.
-- ---------------------------------------------
-- IMPORTANT NOTE: 
-- To use it, first load a model and make sure you
-- can successfully calculate thermal gains.  Then
-- open the Graphical Results page and select the 
-- zone you want to derive the results for.
-- ---------------------------------------------

-- Specify a full pathname if you want the output 
-- file created in a different directory to this script.
filename = getUserFile(1, "Select ecoXML File to Create:")

-- Check for valid filename
-- (in case user hits Cancel instead).
if filename ~= nil then

    -- Create file for writting.
    file = openfile(filename, "w")

    -- Keep the user 
    print("Running - please wait...");
        
    -- Output first line of file.
    output = "<?xml version=\"1.0\" ?>\n";
    write(file, output)

    output = "<ecoXML>\n";
    write(file, output)

    -- Output name of model file.
    output = format("  <model>%s</model>\n", get("model.file"));
    write(file, output)

    -- Output date/time file generated.
    output = format("  <date>%s</date>\n", date());
    write(file, output)

    -- Output known ecoXML data format.
    output = "  <annualHourlyData>\n";
    write(file, output)

    -- Output data description.
    output = "    <data units=Watts>Hourly Direct Solar Gains (sQd)</data>\n";
    write(file, output)
        
        -- Cycle through each day of the year.
    for day = 1,365 do
        
                -- Set date.
        set("dayoftheyear", day);
        
                -- Calculate daily loads.
        cmd("calc.thermal.gains");
        
        -- Begin hourly gains tag.
        output = format("    <day no=%03d>", day);
        write(file, output)

                -- Cycle through hours.
        for hr = 0,23 do
            output = format("%0.0f,", get("results.array", 3, hr));               
            write(file, output)
        end
        
        -- Complete hourly gains tag.
        output = "</day>\n";
        write(file, output)

    end
        
end

output = "  </hourlyValues>\n";
write(file, output)

output = "</ecoXML>\n";
write(file, output)

closefile(file)
print("Done.")

HOW WOULD YOU RATE THIS SCRIPT ?

No votes yet


Navigation

User login

Translate Site To: