Need help storing user input and calling it back later. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

29 Jul 2021, 17:12

thanks That is kind of what I was thinking. a text file will work better for what I am doing I think.
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

30 Jul 2021, 08:33

Ok I got it writing to a text file, and then reading it back in a msgbox. Next question is I will have 3 types of files in that directory. 1 .frm file, some .prt files, and some .drw files. I want to either only save the .drw files to the text doc, or when I read the files back have an if statement saying if the text contains .drw then do this, else go to next line. I can not do this by file type because the program always appends a .numeric extension to all of it's files. So the files would look like this 42xxxx-1.prt.8, 42xxxx1_c.drw.10, 4xyz.drw.12, 4xyz.prt.1, 1234.drw.38 ect...
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.

30 Jul 2021, 08:54

Code: Select all

; Demonstration of function
For each, filename in ["42xxxx-1.prt.8", "42xxxx1_c.drw.10", "4xyz.drw.12", "4xyz.prt.1", "1234.drw.38"]
 new .= "`n" ext(filename)
MsgBox, 64, Result, % SubStr(new, 2)

ext(file) {
 RegExMatch(file, "\.\K\w*", ext)
 Return ext
}
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

30 Jul 2021, 09:19

thanks for that, I am looking at the code to see if I can figure out what it is doing. please forgive my ignorance. It looks like it would only look at the data ins the [ ] and get their extensions. then do something based off what extension they are. if this is correct, I would have to account for the data in the [ ] being something that would change based on the directory, and some times the .prt will have the same numeric extension as the .drw. If this is not what is going on in the code I apologize. I am going to try to alter it a little and run it in my test script to see what is happening.


so it looks like it strips off the numeric extension, at least in the results section. pretty cool. then I should be able to sort by extension, I am guessing
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.

30 Jul 2021, 09:35

The array is just for the demo. You do not need to use it. Yes, the function looks for a dot followed by a word, which is a sequence of letter, digit, or underscore. It then ignores the dot and returns the rest. Since the next dot is not a word character, that suffix is ignored.

Another example of a method is below.

Code: Select all

Loop, Files, %A_MyDocuments%\*.pdf.* ; Return only the PDF files
 MsgBox, 64, Matching path, %A_LoopFilePath%
Or:

Code: Select all

files =
(
img20210710_12524389.pdf.2
img20210710_12524389.pdf.3
img20210710_12524389.txt
img20210710_12524389.txt.8
img20210710_12524389.pdf.4
img20210710_12524389.pdf.5
img20210710_12524389.pdf
)
Loop, Parse, % files, `n, `r
 Switch ext(A_LoopField) {
   Case "pdf": MsgBox, 64, PDF FILE, %A_LoopField%
   Case "txt": MsgBox, 48, TXT FILE, %A_LoopField%
 }
Return

ext(file) {
 RegExMatch(file, "\.\K\w*", extx)
 Return extx
}
Similarly:

Code: Select all

files =
(
img20210710_12524389.pdf.2
img20210710_12524389.pdf.3
img20210710_12524389.txt
img20210710_12524389.txt.8
img20210710_12524389.pdf.4
img20210710_12524389.pdf.5
img20210710_12524389.pdf
)
For each, filename in StrSplit(files, "`n")
 Switch ext(filename) {
   Case "pdf": MsgBox, 64, PDF FILE, %filename%
   Case "txt": MsgBox, 48, TXT FILE, %filename%
 }
Return

ext(file) {
 RegExMatch(file, "\.\K\w*", extx)
 Return extx
}
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

30 Jul 2021, 10:12

Ok thanks! using your code, with a slight mod, appears to do what I need it to do.

Code: Select all

Loop, Files, %currDir%\*.drw.* ; Return only the drw files
 MsgBox, 64, Matching path, %A_LoopFilePath%


now I have no idea yet how to implement it. I need to some how go from the msgbox showing only the drw files to having the code read the files and the first .drw it finds it goes to a subroutine, does the defined actions, then jumps to the next file in the list. and repeats. I do have a working script right now that does what I need it to do, but for only the one file that I set it to. I am trying to take it from that, to doing what ever .drw files are in the directory. I can post the script if it helps see what my goals are. it is sloppy and is a first pass, but It does work for that 1 file.


well never mind. my code above was not doing what I though it was doing. I changed it to .prt and it still gave me the .drw names...
ok fixed that part, not i can get the msgbox to show prt or drw. still don't know how to take that further yet
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.

30 Jul 2021, 11:03

Code: Select all

currdir := A_MyDocuments
Loop, Files, %currDir%\*.drw.* ; Return only the drw files
{ file := A_LoopFilePath
  Gosub, Subroutine
}
MsgBox, 64, Done, I'm done now! That was a lot of work.
Return

Subroutine:
MsgBox, I am doing a defined action right now!`n`n%file%
Return
Or:

Code: Select all

currdir := A_MyDocuments
Loop, Files, %currDir%\*.drw.* ; Return only the drw files
 subroutine(A_LoopFilePath)
MsgBox, 64, Done, I'm done now! That was a lot of work.
Return

subroutine(file) {
 MsgBox, I am doing a defined action right now!`n`n%file%
}
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

02 Aug 2021, 11:38

Awesome thanks! that should help a lot. I will try working with that when I get a chance to work on the script some more.
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

03 Aug 2021, 12:33

I am having a little issues writing an if else for image searches. I have done it in the past, but can't find any of the code I used. I will post what I am trying.

Code: Select all

savewltableCSV5:
{
mousemove, 365, 750
sleep 250
mouseclick, left
sleep 500
}
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\yes table.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Mousemove, 240, 70
sleep 500

MouseClick, left
Mousemove, 210, 116 
sleep 250

MouseClick, left
send %A_LoopFileName%_w5
sleep 500

ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\save.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
sleep 500

}
else
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\no table.png
If Errorlevel = 0
{
EnvAdd, Found, 1
sleep 500
gosub closecurrent
}
}
}
}
gosub savewltableCSV6
return
What I am trying to do is after clicking look for an image. if the image is there then I need to click on it and then do something. if it is not there then I need to go do something else. "no table.png" is when it is greyed out and not available. I am guessing I am making it more complicated then it needs to be. I thought I should be able to search for the "yes table.png" and if it finds it do something, and if not, do something else and skip the seemingly unneeded image search for the "no table.png"
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

03 Aug 2021, 12:41

Thought I had it, but still goes through the whole thing regardless if it finds the image

Code: Select all

savewltableCSV5:
sleep 2000
;msgbox running csv5
{
mousemove, 365, 750
sleep 250
mouseclick, left
sleep 500
}

{
;Found = 0
;While Found < 1
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\no table.png
If Errorlevel = 0
{
msgbox, yes table was not found
EnvAdd, Found, 1
;mouseclick, left, 625, 1830
sleep 500
}

else
{
;Found = 0
;While Found < 1
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\yes table.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Mousemove, 240, 70
sleep 500

MouseClick, left
Mousemove, 210, 116 
sleep 250

MouseClick, left
send %A_LoopFileName%_w5
sleep 500

ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\save.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
sleep 500
}
}
}
}
}
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

03 Aug 2021, 16:56

Ok it appears to be working. I do have a few mouse moves and clicks that are happening that I don't want to happen. I think it is still trying to do the rest of the actions, but it is just moving and clicking in a blank screen so right now it isn't hurting. I will have to try to fix that though. here is the code.

Code: Select all

savewltableCSV5:
{
mousemove, 365, 750
sleep 250
mouseclick, left
sleep 500
}

{
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\no table.png
If Errorlevel = 0
{
EnvAdd, Found, 1
gosub closecurrent
return
sleep 500
}

else
{
ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\yes table.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
Mousemove, 240, 70
sleep 500

MouseClick, left
Mousemove, 210, 116 
sleep 250

MouseClick, left
send %A_LoopFileName%_w5
sleep 500

ImageSearch, imageX, imageY, 0, 0, %a_ScreenWidth%, %A_ScreenHeight%, *24 C:\Users\smoore\Desktop\save.png
If Errorlevel = 0
{
EnvAdd, Found, 1
MouseClick, left, %imageX%, %imageY%
sleep 500

}
}
}
}
}
gosub savewltableCSV6
return
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.

03 Aug 2021, 17:17

Here are some indentations in case helpful in your debugging.

Code: Select all

savewltableCSV5:
Click, 365 750
Sleep, 500
ImageSearch, imageX, imageY, 0, 0, A_ScreenWidth, A_ScreenHeight, *24 %A_Desktop%\no table.png
If !ErrorLevel
{
 EnvAdd, Found, 1
 Gosub, closecurrent
 Return
} Else ImageSearch, imageX, imageY, 0, 0, A_ScreenWidth, A_ScreenHeight, *24 %A_Desktop%\yes table.png
If !Errorlevel
{
 EnvAdd, Found, 1
 MouseClick,, imageX, imageY
 Click, 240 70
 Click, 210 116
 Send %A_LoopFileName%_w5
 Sleep, 500
 ImageSearch, imageX, imageY, 0, 0, A_ScreenWidth, A_ScreenHeight, *24 %A_Desktop%\save.png
 If !Errorlevel
 {
  EnvAdd, Found, 1
  MouseClick,, imageX, imageY
  Sleep, 500
 }
}
Gosub, savewltableCSV6
Return
A_LoopFileName seems likely to be null here.
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

04 Aug 2021, 07:43

thanks. I think I need it though. I didn't post the whole code so my fault on that.

before that I have this.

Code: Select all

dir:
Loop, Files, %currDir%\*.drw.* ; Return only the drw files
{ 
  Gosub, openfile  
}

Return

openfile:
winactivate, Creo Parametric
sleep 250
send ^o
sleep 250
send %A_LoopFileName%
sleep 250
send {Enter}
sleep 2000
gosub, savepl
return
so for me what it was doing is using only the names of the .drw files in that directory and putting them into the name when it is saving the tables. I have basically the same subroutines named savewltableCSV1 through savewltableCSV8 with the main differences being mouse click locations, and csv1 says go to csv2, csv2 says go to csv3 ect... probably could have done it with a loop, but that is how I made it work. I can post the whole code if you would like to take a look at it. just remember I am a noob and a sloppy code writer. The final version will get cleaner, I just try to make it work, then look for better more efficient ways of making it work.
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

04 Aug 2021, 08:27

here is a link to a video of it running. sorry about the censored. I probably can't let the data out.

https://drive.google.com/file/d/11Xi0rBcykkPf1uG9VdTycfwbf9Hyq9jq/view?usp=sharing
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.

04 Aug 2021, 09:06

Thanks for explaining. Feel free to post additional questions if any arise.
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

05 Aug 2021, 08:27

Another quick question. I am assuming this is easy to do. Right now it is saving my csv files with the full drw file name. Example: 4055as4601_c.drw.10_pl.csv it is doing this because I am saying, send %A_LoopFileName%_pl what I would like it to do is save the file name without the ".drw.10" in the name so for that file the name would be "4055as4601_c_pl.csv" they will all be .drw files, but the numbers will be different and an unknown.

Thanks
User avatar
mikeyww
Posts: 26437
Joined: 09 Sep 2014, 18:38

Re: Need help storing user input and calling it back later.  Topic is solved

05 Aug 2021, 08:39

Code: Select all

SendInput % RegExReplace(A_LoopFileName, "\.drw.*", "_pl")
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

05 Aug 2021, 08:42

mikeyww wrote:
05 Aug 2021, 08:39

Code: Select all

SendInput % RegExReplace(A_LoopFileName, "\.drw.*", "_pl")
worked perfectly thanks so much!

well the next time I ran it, it saved 2 csv files not one, and it saved the same table but with the file name it was working on, and the next file name it was going to open after that.

and not sure what happened, but ran it again and it worked perfectly the 3rd time... I will try it again and see what happens

worked perfectly the 4th time too. I must have moved the mouse, or did something wrong when I ran it. either way it appears to be working thanks again!
thrawn5499
Posts: 74
Joined: 26 Sep 2017, 15:36

Re: Need help storing user input and calling it back later.

11 Aug 2021, 08:28

I have another simple (i think) thing I am trying to do.
right now I have this code.SendInput % RegExReplace(A_LoopFileName, "\.drw.*", "wl5") what I need to do is change the "wl5" to be "wlx" where "x" counts up each time it is saved. so the first time it save it is 1, then 2, ect...

I found this out when running the script on 20 files. almost all of them worked correctly, but A few only had 3 tables on one sheet, and when it went to the next sheet it started saving them as wl5 instead of 4. By changing that to count up each time this should fix that issue. I will continue trying to figure this out too, and will post a reply if I get it before I get an answer here. Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 200 guests