Need help storing user input and calling it back later.
Posted: 29 Jul 2021, 09:14
I am writing a script for my work. what it does is launches a program, then sets some options in that program, then opens files in the program, searches for tables and exports them as .csv files. I currently have it working, but it needs some clean up, and I need to add more capabilities to it.
For now I got it to do most of the first tasks using imagesearch. I did this just to get it into testing stages quickly. I wont want the final version to rely on the imagesearch because I wont have the image of those file names. Instead what I need it to do is start a GUI with a multi line input, ask for the files names, and store those names for later use. then instead of using the image of the file it will go through and get the name from the user input. it will run the program then go to the next file name from the user input. I want it to continue until it has opened all files the user put into the box. Some times it might be 3, sometimes it might be 15.
I have a stand alone GUI already with a multi line input for testing outside of the main script. I got it from stackexchange so it is not my work. I think it is working correctly though, except I will need to store the data it collects and get it back later. here is that GUI.
Here is a section of code from the main script. I have a few problems and some cleaning up to do still, but it does run.
Ok first off on the above script. I was trying to launch the program from the desktop. it has to be launched from the desktop to work correctly. I would prefer to do something besides clicking a mouse location to start it. I also was trying to get it to wait for the window to be active, but that wasn't working, so I put a 20 second sleep timer. I would like to fix this. after launching it does some actions using imagesearch. these can stay imagesearch, but it could also be done another way. then calls out gosub, openfile this is where I need to start getting data from the user input. currently it has.
I already commented out the one imagesearch and replaced it with a "send" followed by a text string. what I need to do is replace this with the first filename captured from the user input gui and place it here. and I will need to also place it in a few options later in the code (see below). then once all of the tables are exported I will need to call out the fileopen: again and have it repeat using the next file name from the user input gui.
I mentioned that I needed to also use that data elsewhere. so when I am saving the tables as .csv files, right now it is working because I am using
send 4055AS4061_wl1 then the next one I say send 4055AS4061_wl2 ect. what I need to do is replace "4055AS4061" with what ever file name it is working on at the time, and I would prefer to change the "wl1" "wl2" ect... input to have the number at the end increase by 1 each time it is saved. i think this would be cleaner. I think I remember how to do that and I think I can clean up most of this, but I do need help with the getting the data from the user, storing it for later use then recalling it when needed. I have done some of this a few years ago, but I have not used AHK for for a few years, and even when I was using it a lot, I was not really good with it.
Thanks in advance for the help. I am open to ideas and suggestions for doing this.
For now I got it to do most of the first tasks using imagesearch. I did this just to get it into testing stages quickly. I wont want the final version to rely on the imagesearch because I wont have the image of those file names. Instead what I need it to do is start a GUI with a multi line input, ask for the files names, and store those names for later use. then instead of using the image of the file it will go through and get the name from the user input. it will run the program then go to the next file name from the user input. I want it to continue until it has opened all files the user put into the box. Some times it might be 3, sometimes it might be 15.
I have a stand alone GUI already with a multi line input for testing outside of the main script. I got it from stackexchange so it is not my work. I think it is working correctly though, except I will need to store the data it collects and get it back later. here is that GUI.
Code: Select all
f1::
MsgBox % MultiLineInputBox("Please Enter the file names you want to export tables from.", "", "Eclypse Drawing Table Export Utility")
return
MultiLineInputBox(Text:="", Default:="", Caption:="Multi Line Input Box"){
static
ButtonOK:=ButtonCancel:= false
if !MultiLineInputBoxGui{
Gui, MultiLineInputBox: add, Text, r1 w600 , % Text
Gui, MultiLineInputBox: add, Edit, r10 w600 vMultiLineInputBox, % Default
Gui, MultiLineInputBox: add, Button, w60 gMultiLineInputBoxOK , &OK
Gui, MultiLineInputBox: add, Button, w60 x+10 gMultiLineInputBoxCancel, &Cancel
MultiLineInputBoxGui := true
}
GuiControl,MultiLineInputBox:, MultiLineInputBox, % Default
Gui, MultiLineInputBox: Show,, % Caption
SendMessage, 0xB1, 0, -1, Edit1, A
while !(ButtonOK||ButtonCancel)
continue
if ButtonCancel
return
Gui, MultiLineInputBox: Submit, NoHide
Gui, MultiLineInputBox: Cancel
return MultiLineInputBox
;----------------------
MultiLineInputBoxOK:
ButtonOK:= true
return
;----------------------
MultiLineInputBoxGuiEscape:
MultiLineInputBoxCancel:
ButtonCancel:= true
Gui, MultiLineInputBox: Cancel
return
}
Code: Select all
Mousemove, 1240, 262
sleep 500
MouseClick, left
sleep 200
MouseClick, left
;WinWait Creo Parametric ahk_class HCS16139P ahk_exe xtop.exe
;winactivate, Creo Parametric
;winwaitactive,
;Mousemove, 124, 26
sleep 15000
winactivate, Creo Parametric
;return
SetDirectory:
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\select directory.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\c.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
}
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\working directory.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
}
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\ok.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
}
}
gosub, openfile
return
openfile:
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\open.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
send 4055as4601_c.drw
;{
;ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\as4601.png
;If Errorlevel = 0
;{
;EnvAdd, Found, 1
;MouseClick, left, %imageX%, %imageY%
Sleep 500
;}
;}
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\open-1.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
}
}
gosub, savepl
return
Code: Select all
openfile:
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\open.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Sleep 500
}
send 4055as4601_c.drw
;{
;ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\as4601.png
;If Errorlevel = 0
;{
;EnvAdd, Found, 1
;MouseClick, left, %imageX%, %imageY%
I mentioned that I needed to also use that data elsewhere. so when I am saving the tables as .csv files, right now it is working because I am using
send 4055AS4061_wl1 then the next one I say send 4055AS4061_wl2 ect. what I need to do is replace "4055AS4061" with what ever file name it is working on at the time, and I would prefer to change the "wl1" "wl2" ect... input to have the number at the end increase by 1 each time it is saved. i think this would be cleaner. I think I remember how to do that and I think I can clean up most of this, but I do need help with the getting the data from the user, storing it for later use then recalling it when needed. I have done some of this a few years ago, but I have not used AHK for for a few years, and even when I was using it a lot, I was not really good with it.
Thanks in advance for the help. I am open to ideas and suggestions for doing this.