1 Like
1930 Views
I'm reposting something here that I emailed earlier to you Shoibal - so that all can see it...
Below is a script that does something similar to what you had. This one is designed to run INSIDE LEAP in the Advanced: Edit Scripts window. You can also save it as a VBS file...
CLS ‘ This just clears the area of the screen used to receive print statements.
Area = "Freedonia"
PRINT "Export LEAP Data" ‘ The print statement causes text to be sent to the lower part of the script editing screen.
LEAP.ActiveArea = AREA
for each s in LEAP.Scenarios
if (S.ResultsShown) and (S.ID <> 1) then 'Only show scenarios that have been marked for calculation and not Current Accounts
s.Active = TRUE
PRINT "Scenario: " & S.Name & ", Energy Demand Results"
for each b in LEAP.Branch("Demand").Children
SET V = B.Variable("Energy Demand Final Units") ‘I have noticed that VBScript is quite picky. Sometimes needs the SET statement
for yr = LEAP.BaseYear to LEAP.EndYear
if yr mod 5 = 0 then 'only do every 5 years
PRINT b.FullName & ": " & yr & ", " & Round(v.Value(Yr,"TJ"),2) & " TJ"
end if
next ‘yr
next ‘branch
end if
next ‘scenario
My suggestion is to try prototyping these scripts directly within LEAP before running them elsewhere (eg in Excel). Note that when you create a script in LEAP you don’t have to explicitly create the LEAP object. That is already created implicitly. The advantage of prototyping in LEAP is that you can make use of the autocomplete and other editing features within the script window.
You can run the above code by pasting it into the script editor (under menu option Advanced: Edit Scripts)
One thing I did different is using the V.Value syntax. The V.ResultValue and V.DataValue functions are no longer functional. Note also that I am only printing out results for particular scenarios and also I am only doing one result variable (Energy Demand Final Units). Note also that some variables are data variables, while others are result variables.