Need help storing user input and calling it back later. Topic is solved
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
thanks That is kind of what I was thinking. a text file will work better for what I am doing I think.
Re: Need help storing user input and calling it back later.
You can use Loop, Read to get each line.
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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...
Re: Need help storing user input and calling it back later.
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
}
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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
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
Re: Need help storing user input and calling it back later.
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.
Or:
Similarly:
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%
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
}
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
}
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
Ok thanks! using your code, with a slight mod, appears to do what I need it to do.
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
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
Re: Need help storing user input and calling it back later.
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
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%
}
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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.
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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.
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"
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
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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
}
}
}
}
}
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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
Re: Need help storing user input and calling it back later.
Here are some indentations in case helpful in your debugging.
A_LoopFileName seems likely to be null here.
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
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
thanks. I think I need it though. I didn't post the whole code so my fault on that.
before that I have this.
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.
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
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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
https://drive.google.com/file/d/11Xi0rBcykkPf1uG9VdTycfwbf9Hyq9jq/view?usp=sharing
Re: Need help storing user input and calling it back later.
Thanks for explaining. Feel free to post additional questions if any arise.
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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
Thanks
Re: Need help storing user input and calling it back later. Topic is solved
Code: Select all
SendInput % RegExReplace(A_LoopFileName, "\.drw.*", "_pl")
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
worked perfectly thanks so much!mikeyww wrote: ↑05 Aug 2021, 08:39Code: Select all
SendInput % RegExReplace(A_LoopFileName, "\.drw.*", "_pl")
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!
-
- Posts: 74
- Joined: 26 Sep 2017, 15:36
Re: Need help storing user input and calling it back later.
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!
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!
Who is online
Users browsing this forum: FanaticGuru and 149 guests