Jump to content

Recommended Posts

Posted

In this script I ask the script to assgin filenames based on varaible predefined perfix ("map_") what if the defined file name already exists in that folder?in this case how i can ask the script to save file with a name loke "map_1_1" or something simillar instead of "map_1" that already exists?should I use If then Function?

Here is the script:

#include <file.au3>

#include <array.au3>

Global $CSV_Array

_FileReadToArray("C:\Users\naroueia\Desktop\climexdata.csv", $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

For $i = 1 To $CSV_Array[0]

_GetMyResults($CSV_Array[$i],$i)

Next

Func _GetMyResults($parameter,$index)

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($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(1000)

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

Send("^m")

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]", ""); clicks on the empty field to type the name of file

Sleep(2000)

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

Sleep(2000)

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

Sleep(6000); waits 4 seconds to save the file

Send("{enter}"); justifies the dialoge box showing the map succesfully saved

Sleep("4000")

Send("{ALT}")

Sleep("1000")

Send("w"); activates the Window menue

Sleep("2000")

Send("2"); activates the Run window

Sleep("1000")

Send("^t"); creates the table

Sleep("2000")

Send("S"); opening standard table

sleep("2000")

MouseClick("left",459, 482,2)

sleep("1000")

send ("s"); sends the "save table" command

sleep("1000")

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

sleep("1000")

ControlClick("Save As", "", "[CLASS:Edit; INSTANCE:1]", ""); clicks on the empty field to type the name of file

Sleep(1000)

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

Sleep(1000)

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

sleep("2000")

Send("{ALTDown}+{F4}"); closes the software

Send("{ALTUP}"); releases the ALT button

sleep("2000")

Controlclick("Dymex Simulato","", "[CLASS:Button; INSTANCE:2]","")

EndFunc ;==>_GetMyResults

Cheers

Posted

Simple application of FileExists() and a loop, see if you can learn from this example :mellow:

$i = 0
$sFilename = "test.txt"
While FileExists($sFilename)
    $i += 1
    $sFilename = "test(" & $i & ").txt"
WEnd
FileWriteLine($sFilename, "This is a line in " & $sFilename)

===

it dosen't, actually when it finds that the file name already exist it the message comes up that"do u want to replace it" ,does this While application checks that there is a simillar filename in the directory?Abviously it doesn't coz if it does it do not type the pre-existing file name.

Posted

The example I posted checks for the existence of "test.txt", if that exists, it generates new names "test(1).txt", "test(2).txt" etc until it finds a file-name that doesn't exist, then it creates that file and writes a line of text to it.

You may have wrongly applied the FileExists() function, hence your troubles, post a runnable snippet of your code showing where you attempted to use the FileExists() function.

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
×
×
  • Create New...