Jump to content
Sign in to follow this  
khandan

How to attach a CSV file

Recommended Posts

khandan

I have a software called CLimex for modelling, I should do parameter fitting and save the results lots of times. By parameter setting I mean in following image I should change Temperature Index (DV0) from -2 to to -1 and other numbers on and on again, I heard I can make a csv file and put it in the scipt to read the number form CSV file one by one and each time run the model.

So far after 6 days of working with AutoIt i have written this script that do a single job (just change on parameter ) runs the model and saves the result(map). I neccesarily need to make a function as well, this is what i have written so far.

Posted Image

; Script Function:

; Opening Climex

; Prompt the user to run the script - use a Yes/No prompt

; Run the Dymex Simulator

; REsulution should be 1440*900 and Climex windows maximized mode should be used

Run("C:\Program Files\CSIRO Entomology\Dymex\DxSim3.exe") ; runs the software

MouseClick("left",830,400,1); clicks on welcoming window

Send("{ESC}") ; closes welcoming window

WinWait ( 'CLIMEX - Compare Locations (1 species)', '' ); activates the main window

WinActivate ( 'CLIMEX - Compare Locations (1 species)', '' )

MouseClick ( 'Left', 50, 241, 1 ); click on parameters window

sleep(2000)

MouseClick ( 'Left', 46, 169, 1 ); opens temperature Index

sleep(2000)

MouseClick ( 'Left', 48, 198, 2 ); click on temperature Index DV0 filed

sleep(2000)

Send("1"); changes parameter from -2 to 1

sleep(2000)

Send("{Enter}"); goes to the next filed to confirm entered number (1)

sleep(2000)

Send("{ESC}"); gets out of fileds

sleep(2000)

MouseClick ( 'Left', 471, 111, 1 ); closes the parameters window

sleep(2000)

Send("^r"); Runs the model

sleep(2000)

Sleep(27000) ;waits 27seconds for model to run; awaits for model to run fully

Send("{Alt}"); activates menue

send("r"); activates run menue

send("m"); opens the produced map

sleep(3000) ; 3 seconds shows the map

MouseClick ( 'Left', 590, 241, 1 )

sleep(2000)

Send("{Alt}")

send("m")

MouseClick ( 'Left', 109, 329, 1 ); clicks on Export File

sleep(2000)

send("{BS}"); deletes the default name

ControlClick("Save As", "", "[CLASS:Button; INSTANCE:1]",""); clo

sleep(2000)

ControlSend("Save As", "", "[CLASS:Edit; INSTANCE:1]","mapi"); saves the map by the name of "mapi"

sleep(2000)

ControlClick("Save As", "", "[CLASS:Button; INSTANCE:2]","")

sleep(5000); waits 4 seconds to save the file

Send("{enter}")

Share this post


Link to post
Share on other sites
enaiman

Using a csv file is quite trivial.

The structure should be: on each line a number of values separated by commas to be used within one cycle.

you have 2 options here: using one of the csv UDF to be found on this forum - or - go this way:

You read the whole csv file using _FileReadToArray

Make a function called ... example _GetMyResults then run the function in a loop having the values passed to that function everytime.

See my example.

Take care about the saveAs part - in this form it will overwrite "mapi" everytime.

#include <file.au3>
#include <array.au3>

Global $CSV_Array

Run("C:\Program Files\CSIRO Entomology\Dymex\DxSim3.exe") ; runs the software
MouseClick("left",830,400,1); clicks on welcoming window
Send("{ESC}") ; closes welcoming window

_FileReadToArray("your csv file here", $CSV_Array)

;The script will change greatly if you want to modify more than one parameter at the time
;you will need to click somewhere and modify that parameter, then click elsewhere ... so on
#cs
This script will work if you have only 1 parameter
your csv file will look like:

1
3
2
5

#ce

;Also - I assume that after you send the "final" "enter" it will go back to step one.
;have fun 

For $i = 1 To $CSV_Array[0]
    _GetMyResults($CSV_Array[$i])
Next

Func _GetMyResults($parameter)
    WinWait ( 'CLIMEX - Compare Locations (1 species)', '' ); activates the main window
    WinActivate ( 'CLIMEX - Compare Locations (1 species)', '' )
    MouseClick ( 'Left', 50, 241, 1 ); click on parameters window
    sleep(2000)
    MouseClick ( 'Left', 46, 169, 1 ); opens temperature Index
    sleep(2000)
    MouseClick ( 'Left', 48, 198, 2 ); click on temperature Index DV0 filed
    sleep(2000)
    Send($parameter); changes parameter 
    sleep(2000)
    Send("{Enter}"); goes to the next filed to confirm entered number (1)
    sleep(2000)
    Send("{ESC}"); gets out of fileds
    sleep(2000)
    MouseClick ( 'Left', 471, 111, 1 ); closes the parameters window
    sleep(2000)
    Send("^r"); Runs the model
    sleep(2000)
    Sleep(27000) ;waits 27seconds for model to run; awaits for model to run fully

    Send("{Alt}"); activates menue
    send("r"); activates run menue
    send("m"); opens the produced map
    sleep(3000) ; 3 seconds shows the map
    MouseClick ( 'Left', 590, 241, 1 )
    sleep(2000)
    Send("{Alt}")
    send("m")
    MouseClick ( 'Left', 109, 329, 1 ); clicks on Export File
    sleep(2000)
    send("{BS}"); deletes the default name
    ControlClick("Save As", "", "[CLASS:Button; INSTANCE:1]",""); clo
    sleep(2000)
    ControlSend("Save As", "", "[CLASS:Edit; INSTANCE:1]","mapi"); saves the map by the name of "mapi"
    sleep(2000)
    ControlClick("Save As", "", "[CLASS:Button; INSTANCE:2]","")

    sleep(5000); waits 4 seconds to save the file
    Send("{enter}")
EndFunc

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites
khandan

Using a csv file is quite trivial.

The structure should be: on each line a number of values separated by commas to be used within one cycle.

you have 2 options here: using one of the csv UDF to be found on this forum - or - go this way:

You read the whole csv file using _FileReadToArray

Make a function called ... example _GetMyResults then run the function in a loop having the values passed to that function everytime.

See my example.

Take care about the saveAs part - in this form it will overwrite "mapi" everytime.

#include <file.au3>
#include <array.au3>

Global $CSV_Array

Run("C:\Program Files\CSIRO Entomology\Dymex\DxSim3.exe") ; runs the software
MouseClick("left",830,400,1); clicks on welcoming window
Send("{ESC}") ; closes welcoming window

_FileReadToArray("your csv file here", $CSV_Array)

;The script will change greatly if you want to modify more than one parameter at the time
;you will need to click somewhere and modify that parameter, then click elsewhere ... so on
#cs
This script will work if you have only 1 parameter
your csv file will look like:

1
3
2
5

#ce

;Also - I assume that after you send the "final" "enter" it will go back to step one.
;have fun 

For $i = 1 To $CSV_Array[0]
    _GetMyResults($CSV_Array[$i])
Next

Func _GetMyResults($parameter)
    WinWait ( 'CLIMEX - Compare Locations (1 species)', '' ); activates the main window
    WinActivate ( 'CLIMEX - Compare Locations (1 species)', '' )
    MouseClick ( 'Left', 50, 241, 1 ); click on parameters window
    sleep(2000)
    MouseClick ( 'Left', 46, 169, 1 ); opens temperature Index
    sleep(2000)
    MouseClick ( 'Left', 48, 198, 2 ); click on temperature Index DV0 filed
    sleep(2000)
    Send($parameter); changes parameter 
    sleep(2000)
    Send("{Enter}"); goes to the next filed to confirm entered number (1)
    sleep(2000)
    Send("{ESC}"); gets out of fileds
    sleep(2000)
    MouseClick ( 'Left', 471, 111, 1 ); closes the parameters window
    sleep(2000)
    Send("^r"); Runs the model
    sleep(2000)
    Sleep(27000) ;waits 27seconds for model to run; awaits for model to run fully

    Send("{Alt}"); activates menue
    send("r"); activates run menue
    send("m"); opens the produced map
    sleep(3000) ; 3 seconds shows the map
    MouseClick ( 'Left', 590, 241, 1 )
    sleep(2000)
    Send("{Alt}")
    send("m")
    MouseClick ( 'Left', 109, 329, 1 ); clicks on Export File
    sleep(2000)
    send("{BS}"); deletes the default name
    ControlClick("Save As", "", "[CLASS:Button; INSTANCE:1]",""); clo
    sleep(2000)
    ControlSend("Save As", "", "[CLASS:Edit; INSTANCE:1]","mapi"); saves the map by the name of "mapi"
    sleep(2000)
    ControlClick("Save As", "", "[CLASS:Button; INSTANCE:2]","")

    sleep(5000); waits 4 seconds to save the file
    Send("{enter}")
EndFunc

========================

thank you very much bro, it really helped me, thank u thank u thank u

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×