697 Views
Hi Gregers,
Hopefully this helps you get started. You should be able to drop everything between the dashed ("-") lines into LEAP's internal script editor and click "Run Script".
----------------------------------------------------
' ============================================
' Bulk energy demand export tool for LEAP
' Taylor Binnington, Stockholm Environment Institute
' Copyright 2015
' ============================================
' Instantiate objects
' ============================================
If Not IsObject(LEAP) Then
set LEAP = CreateObject("Leap.LEAPApplication")
End If
set xla = CreateObject("Excel.Application")
' ============================================
dim tech_branches
set tech_branches = CreateObject("Scripting.Dictionary")
for each b in LEAP.Branches
if b.Branchtype = 4 then
tech_branches.Add b.BranchID, b.Name
end if
next
xla.Visible = false
xla.ScreenUpdating = true
set xlw = xla.Workbooks.Add
LEAP.Verbose = 4
LEAP.Visible = true
set xls = xla.sheets.add
xls.name = "Exported from LEAP"
' Add headers to Excel worksheet
r = 1
xls.Cells(r, 1).Value = "Scenario"
xls.Cells(r, 2).Value = "Year"
xls.Cells(r, 3).Value = "Branch"
xls.Cells(r, 4).Value = "Fuel"
xls.Cells(r, 5).Value = "Value (GJ)"
' Loop through scenarios, years, branches and export final energy demand in gigajoules
for each s in LEAP.Scenarios
for y = LEAP.BaseYear to LEAP.EndYear
for each key in tech_branches.keys
r = r + 1
xls.Cells(r, 1).Value = s
xls.Cells(r, 2).Value = y
xls.Cells(r, 3).Value = LEAP.Branch(key).FullName
xls.Cells(r, 4).Value = LEAP.Branch(key).Fuel.Name
xls.Cells(r, 5).Value = LEAP.Branch(key).Variable("Energy Demand Final Units").Value(y, "Gigajoule")
next
next
next
xla.screenupdating = true
xla.visible = true
----------------------------------------------------
Take care,
Taylor