Jump to content

Trouble with Looping


Recommended Posts

Hey guys, nice forum, I have learned a ton from reading what you guys are doing!

I am new to autoIT and have been working with some scripts for a few days. I'd imagine my script is a little ambitious for a first timer, but I have broken it down into accomplishible bits to make sure I understand what is going on.

I am working with an oil and gas Log analysis application called LAS Tools Pro. It doesn't have any batching capabilities and no command line features, nor does it accept hot key commands at all. : )

I have created a script that opens the application and a file using ShellExecute.

It waits for a second,

Then it usings some mouse clicks to save the file and exit the program. (This is making the ascii in the file uniform through some optimizations it does during the save process)

I want to do this to 3119 files.

I also cut and pasted some example code to make an array from a list of files in a directory.

So I am trying to figure out how to take the ShellExecute line and dump the files names that I have in the array, into the place where I have the path.

I thought I would want to do this with a loop statement, and I have toyed with a few, but I have some questions that are preventing me from fully understanding the process.

1. After I have created an array as in the BuildArray.au3 attached, are those elements already loaded into variables related to the name of the array? I assumed so, because of the $FileList name.

2. Should I be shooting to combine the whole thing into a single script when it is complete? 2a. If so, should the $FileList Array be a Global variable?

3. Can someone provide an example of how I would call a file name from the array into an iteration of the shellexecute so that I could open two files? (The application will only deal with one file at a time, and that is why I have made the mouse clicks save and exit the application)

So that is why I need to be able to loop the operation.

Recap:

The application Opens the application with a LAS file, I have it wait a second for the application to fully open, then I use mouse clicks to hit Save and Optimize button, and navigate to the appropriate location then click save to complete the save dialog.

I would like to loop this, but am missing a little info that I am so far unable to glean from examples and tutorials.

Any and all help and suggestions are greatly Appreciated!

Thanks very much for your attention guys.

Link to comment
Share on other sites

just a few ideas:

You can replace lines 4-9 with a single winwait("LAS tools pro")

Is it possible to use keyboard to save that file? I think it would be faster and maybe more reliable...

And about that loop. Put the lines from buildarray.au3 into the same file as the rest of the code. I don't see many reasons to have it separate.

Put lines 27-38 into a function with a parameter $filename and then just make the rest like this

$FileList = _FileListToArray("c:logs")

for $a=1 to $FileList[0]

processfile($filelist[$a])

next

Func processfile($filename)

...

_WinWaitActivate("LAS tools pro [C:Logs"&$filename&"]","Delete Selected Curv")

...

endfunc

something like that should do it :oops:

Edited by LoWang
Link to comment
Share on other sites

36 Views and no replies.....

I must have asked something wrong. Well, I am still working on it. So i figured out how to post code.. ;p

I figured out how to call the array data that I needed(of course it would be in reading "arrays" again in the wiki that I was able to put it together) , just worked with some simpler stuff till I got that.

I seem to be having trouble injecting a variable/element from an array into the "filename" portion of the ShellExecute function.

ShellExecute ( "filename" [, "parameters" [, "workingdir" [, "verb" [, showflag]]]] )

ShellExecute ( "C:\Logs\ This is where my entry from the array would go - and the " messes it up, but leaving it out or putting it after Logs, or after Logs\" like so doesn't work either.

Any help is much appreciated. Hopefully I have been more clear.

thanks,

#include <File.au3>
#include <Array.au3>
Global $FileList = _FileListToArray("c:\Logs")
If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    Exit
EndIf
If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    Exit
EndIf


_ArrayDisplay($FileList, "$FileList")
Local $i = 1
While $i <= 5
$i = $i + 1
WEnd

ShellExecute( "C:\Logs\"$FileList[$i], "" ,"C:\Logs\", "open", "@SW_MAXIMIZE","")
   While 1
   sleep(3000)
   If WinExists("LAS tools pro")then
   Exitloop
   Endif
   Wend
  #region ---Au3Recorder generated code Start (v3.3.7.0)  ---
   #region --- Internal functions Au3Recorder Start ---
   Func _Au3RecordSetup()
   Opt('WinWaitDelay',100)
   Opt('WinDetectHiddenText',1)
   Opt('MouseCoordMode',0)
   EndFunc
   Func _WinWaitActivate($title,$text,$timeout=0)
   WinWait($title,$text,$timeout)
   If Not WinActive($title,$text) Then WinActivate($title,$text)
   WinWaitActive($title,$text,$timeout)
   EndFunc
   _AU3RecordSetup()
   #endregion --- Internal functions Au3Recorder End ---
   MouseClick("left",324,217,1)
   _WinWaitActivate("LAS tools pro [C:\Logs\"$FileList[$i],"Delete Selected Curv")
   MouseClick("left",126,87,1)
   _WinWaitActivate("Save As","Save as &type:")
   MouseClick("left",315,41,1)
   MouseClick("left",407,172,1)
   MouseClick("left",70,166,2)
   MouseClick("left",383,210,1)
   MouseClick("left",250,14,1)
   MouseClick("left",14,34,1)
   MouseClick("left",35,133,1)
#endregion --- Au3Recorder generated code End ---
Link to comment
Share on other sites

First,

Thank you very much for the help.

Second,

I am not entirely sure I understand all of it.

"Put lines 27-38 into a function with a parameter $filename"

I didn't know exactly how to do this part.... I thought, ok I understand parameter, and I could see how you were creating Functions, but why am I encapsulating the mouse clicks as part of that?

Below is what I have now. Is this what you meant? I guess I need a little more direction on the creating a function with $filename as a parameter. Also, it doesn't wait with just winwait, I had to go back to the timer. I'll check back in the morning. I am so close to having this I can taste it, but it has been a few days of learning to get here. I don't think I would have gotten to the nested stuff without guidance, so thanks again for everything so far.

Seems like if I am going to call the application open with the array, I have to have that function up top before shell execute, otherwise it wont recognize the variable... since that is technically the first item I want to open from the array.

#include <File.au3>
#include <Array.au3>
Local $FileList = _FileListToArray("c:\Logs")
If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    Exit
EndIf
If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    Exit
EndIf

ShellExecute( "C:\Logs\#503H LAS Final.las","","@SW_MAXIMIZE","")
WinWait ("LAS tools pro")

#region ---Au3Recorder generated code Start (v3.3.7.0)  ---
#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
Opt('WinWaitDelay',100)
Opt('WinDetectHiddenText',1)
Opt('MouseCoordMode',0)
EndFunc
Func _WinWaitActivate($title,$text,$timeout=0)
WinWait($title,$text,$timeout)
If Not WinActive($title,$text) Then WinActivate($title,$text)
WinWaitActive($title,$text,$timeout)
EndFunc
_AU3RecordSetup()
Func _TEST($filename)
MouseClick("left",324,217,1)
_WinWaitActivate("LAS tools pro [C:\Logs\"&$filename&"]","Delete Selected Curv")
MouseClick("left",126,87,1)
_WinWaitActivate("Save As","Save as &type:")
MouseClick("left",315,41,1)
MouseClick("left",407,172,1)
MouseClick("left",70,166,2)
MouseClick("left",383,210,1)
MouseClick("left",250,14,1)
MouseClick("left",14,34,1)
MouseClick("left",35,133,1)
EndFunc
$FileList =_FileListToArray("C:\logs")
for $a=1 to $FileList[0]
processfile($FileList[$a]
Next
Link to comment
Share on other sites

Oh man, so now I see what your nick means :bye: So you have used some au3recorder to generate this clicking code? Interesting...

Just check the code you made and see that you have reading of those filenames twice there: up and also you added it down.

What is the point of putting some code into the function? It is because you need to call this piece of code repeatedly. In your case it is ShellExecute opening of all the files one by one from the folder c:logs and then do some clicking in it. So these lines should be put into a function. And the purpose of the for cycle is to read through the previously made array $filelist and call this function which you named _TEST on each of the values. So of course if I suggested a function name processfile(), you must either define the function with THIS name instead of _TEST or change it in that for cycle :oops:

If there were just function definitions in the #region ---Au3Recorder generated code then you could write any other code before it, but since there is this func _AU3RecordSetup() being called then you have to write the for cycle below it - that's right. So it would be easier to put any other code below this generated region, so I just edited it a bit for you and added some comments:

#include <File.au3>
#include <Array.au3>
#region ---Au3Recorder generated code Start (v3.3.7.0)  ---
#region --- Internal functions Au3Recorder Start ---
Func _Au3RecordSetup()
 Opt('WinWaitDelay',100)
 Opt('WinDetectHiddenText',1)
 Opt('MouseCoordMode',0)
EndFunc
Func _WinWaitActivate($title,$text,$timeout=0)
 WinWait($title,$text,$timeout)
 If Not WinActive($title,$text) Then WinActivate($title,$text)
 WinWaitActive($title,$text,$timeout)
EndFunc

_AU3RecordSetup()

Func _TEST($filename)
 ShellExecute( "C:Logs"&$filename,"","@SW_MAXIMIZE","")
 WinWait ("LAS tools pro")
 MouseClick("left",324,217,1)
 _WinWaitActivate("LAS tools pro [C:Logs"&$filename&"]","Delete Selected Curv")
 MouseClick("left",126,87,1)
 _WinWaitActivate("Save As","Save as &type:")
 MouseClick("left",315,41,1)
 MouseClick("left",407,172,1)
 MouseClick("left",70,166,2)
 MouseClick("left",383,210,1)
 MouseClick("left",250,14,1)
 MouseClick("left",14,34,1)
 MouseClick("left",35,133,1)
EndFunc

;read filenames into $filelist array
$FileList = _FileListToArray("c:Logs")  ;this makes $filelist a global variable because it is being defined on the top level of code (not in a func)
If @error = 1 Then
    MsgBox(0, "", "No Folders Found.")
    Exit
EndIf
If @error = 4 Then
    MsgBox(0, "", "No Files Found.")
    Exit
EndIf
for $a=1 to $FileList[0]    ;this will go through the array and call the function for each of the filenames and do the clicking
_TEST($FileList[$a])
Next
Edited by LoWang
Link to comment
Share on other sites

LoWang,

<gong hit>

/bow

Thanks for the lesson brother. I read and now understand the function and what was intended. I will continue to improve it. You are the man! I really appreciate the help.

Thanks for putting eyes on it and correcting my mistakes. It's working right now.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...