• 358 views | 9 messages Discussion: LEAP
    Topic: Script in LEAPSubscribe | Previous | Next
  • Mostafa Fard 11/3/2017

    Hi,
    Are there any documents/samples to use Script in LEAP (Like WEAP)?
    I read the description of functions in Script Editor (In LEAP), but I could not find the function to select the type of final results.
    Also, how can I select/deselect different fuels for a result (Using API)?
    In addition, when I want to use ReadFromFile in Script, it always omitted "/" from the FileName; so shows the following error to me. the actual path which I use in Script is
    LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:/New Folder/Input.csv)";
    (I am running Script outside of LEAP)
    Thanks


    1.jpg
  • Taylor Binnington 11/8/2017
      Best Response

    Hi Mostafa -

    This question is best answered in the context of a particular script or problem that you're trying to solve. Which result are you trying to use in your script, and how are you currently trying to extract this result using the API?
    To your other question (the removal of slash delimiters from your file path), be sure to use Windows-style path names, which use a backslash "\" between directories. These should also be used to reference LEAP branches within your Branch() method. In other words, try:

    LEAP.Branch("Demand\Household\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:\New Folder\Input.csv)"

    Let me know if this works,

    Taylor

  • Mostafa Fard 11/8/2017
      Best Response

    Hi,
    I do not understand "This question is best answered in the context of a particular script or problem that you're trying to solve.". Could you please refer me to that context?

    Suppose that I am on Demand node in treeview of Result view in LEAP. I can manually select "Demand -> Energy Demand Final Units" see the result, change the fuels or branches. Also, I can change the report to "Transformation -> Requirements", change the fuels or branches and see the report. How can I do the via API?

  • Mostafa Fard 11/8/2017
      Best Response

    About the ReadFromFile, I used different formats.
    • "ReadFromFile(D:\New Folder\Input.csv)"; //{your suggested format}
    Error = Branches,Item: No branch found named "DemandHouseholdUrban" {Error1 in Attachment.}


    Using the following formats:
    • "ReadFromFile(D:\New Folder\Input.csv)";
    • "ReadFromFile(D:\\New Folder\\Input.csv)";
    • "ReadFromFile(D:/New Folder/Input.csv)";
    • "ReadFromFile(D://New Folder//Input.csv)";
    Error = Files "d:new folderinput.csv" not found in ReadFromFile {Error2 in Attachment.}

    It is good to mention that I am writing in JScript (Not VBScript). Does it matter?


    Error1.jpg
  • Taylor Binnington 11/9/2017
      Best Response

    Hi Mostafa,

    Are you trying to manipulate the LEAP Results GUI using the API as you would with your mouse, or are you trying to generate a set of results before (for example) printing them to another file?

    Regarding the error(s) that you've been seeing, without a complete working example I can only speculate. But I think they are being introduced by the interpreter, and not by LEAP or API. I am not very familiar with JScript myself, but do I think that backslashes will need to be escaped properly. Do you see your 'Error 2' for each one of the four ReadFromFile formats that you tried? To help debug, I'd suggest that before trying to pass the expression into LEAP through the API, first ensure that it is correctly being interpreted by JScript as a string.

    Hope this helps,
    Taylor

  • Mostafa Fard 11/9/2017
      Best Response

    I want to do both actually (about the result). I want to manipulate a Result's Report via API as I do in GUI; finally, create output files from those results.
    The following code is my JScript. Different formats that I tested are commented in the code. None of the works to assign ReadFromFile to Expression of a variable. (I see 'Error 2' for each one of the four ReadFromFile formats that you tried)

    var WshShell = new ActiveXObject("WScript.Shell");
    var LEAP;
    var RunCount = 10;

    OpenLEAP();

    LEAP.ActiveArea = "Freedonia";
    LEAP.ActiveScenario = "Reference";
    LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = 50;
    //LEAP.Branch("Demand\Household\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:\New Folder\Input.csv)";
    //LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:\New Folder\Input.csv)";
    //LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:\\New Folder\\Input.csv)";
    //LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = "ReadFromFile(D:/New Folder/Input.csv)";
    //LEAP.Branch("Demand\\Household\\Urban").Variable("Activity Level").Expression = "ReadFromFile(D://New Folder//Input.csv)";

    for (var i = 1; i <= RunCount; i++)
    {
    LEAP.Calculate(false);
    LEAP.ExportResultsCSV("D:/Result_" + i + ".csv");
    }
    WScript.Echo("End");

    //---------------------------------------------------
    function OpenLEAP(){
    LEAP = new ActiveXObject("LEAP.LEAPApplication");
    while (!LEAP.ProgramStarted){
    //WScript.Sleep(100);
    }
    LEAP.Verbose = 1;
    }

  • Taylor Binnington 11/28/2017
      Best Response

    Hi Mostafa -

    I'm able to reproduce your problem by entering the ReadFromFile() function when typed directly into a LEAP expression, without using the API. So I think the problem lies in that function - we'll investigate it, and hopefully have a solution for an upcoming version of LEAP.

    In the meantime, can you accomplish what you want to do using the ReadFromExcel() function, to read from an MS Excel file?

    Taylor

  • Mostafa Fard 9/17/2018
      Best Response

    I am going to use LEAP as a BlackBox software from outside. I mean, I am going to design a framework to set the inputs for different variables (of branches) in LEAP, run it, and save the results for other purposes. It is necessary to use flat files (excel file) in setting values for variable step (initialization for LEAP).
  • Taylor Binnington 10/4/2018
      Best Response

    Hi Mostafa -

    No, it is not necessary. The ReadFromExcel() function takes an Excel range, which contains information about which worksheet the data are found within.

    Taylor