Jump to content
Sign in to follow this  
cassetti

WinWait not working on a working process?

Recommended Posts

cassetti

Hello All!

Longtime user of AutoIt - LOVE the language.

Right now I'm running into a bit of an issue and I need some help. I'm attempting to automate some processes in an open-source 3D model software called meshlab (http://meshlab.sourceforge.net/) - It's quite processor intensive. Though I've run into an issue where my work computer is MUCH faster than my home computer.

When I execute WinWait("MeshLab") it won't wait, nor will it wait when I run one of the 'filters' - Filters > Remeshing > Surface Reconstruction: VCG  -  WinWait("Surface Reconstruction: VCG")

I found something called "ProcessWait" in the helpfile (never had to use it before) - but when I run   ProcessWait("meshlab.exe") - it doesn't work!

Is there an alternative method to check/poll the system ever X milliseconds to determine if the process is finished executing? Some of these filters I run on my CAD models can take minutes to execute, and it varies drastically from computer to computer.

Here's what I'm making - I take my 3D models, and run them through a bunch of filters to create this effect, called a "Voronoi Tessellation"

674x501_14323_87012_1338413385.jpg

 

 

Share this post


Link to post
Share on other sites
BrewManNH

Won't wait for what? WinWait waits until the window exists, ProcessWait waits until the process exists. Are you perhaps thinking of something like ProcessWaitClose, which will unpause the script once the process closes. Or WinWaitClose which does the same thing except for a window?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cassetti

Well then, I must be having a brain fart.

When I click "Apply Filter", Meshlab runs a bunch of calculations which take seconds to minutes to apply depending on several factors.

I want to pause my script until meshlabs is 'available', or finished executing it's processes,

My goal is to create a script which executes one command, waits for the process to finish executing, then run the next 'filter' in the sequence. The problem is the time to run depends on the complexity of the 3D model supplied, large complex models (like 3D scans) can take over 5 minutes to execute

Edited by cassetti

Share this post


Link to post
Share on other sites
BrewManNH

Maybe you need WinActive which checks to see if the window is active or not. Or perhaps the window that it showing while it's processing is the one you want to check and not the window that is always there. Does the window title change when it's processing, or is there some other way of determining when the process has finished and it's ready for the next step?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cassetti

Unfortunately the new windows that pop up remain open when the process is complete.

When I run WinActivate (or mouseclick in the main window) the whole program freezes up and the title changes to add (not responding) to both the main meshlab window, and the filter window (though it doesn't always add the "not responding" text, that only happens for the extreme CPU intensive filters like re-meshing)

Sadly, there is no definitive way, not even a status bar pops up (it's integrated into the interface).

There's ProcessGetStats, but I can't quite figure out how I could interpret the data? Get a baseline reading before triggering the filter, and then monitoring the CPU usage until it drops below a certain level?

Edited by cassetti

Share this post


Link to post
Share on other sites
BrewManNH

Well, how does a user know the process has completed and is ready for the next process? Screen shots of the windows before and after, or use the AU3Info tool to read the windows and post the summary tab information.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cassetti

Sometimes, I know the program is finished 'processing' when I can click menu's and buttons, othertimes I can watch the status bar in the lower right corner of the screen - although the green status bar usually sticks at 1 or 2%, then shoots up in a millisecond to 75% then a milisecond later, up to 100% then blank.

On some filters (not all), a new layer is created (in the screenshots, you'll see the new layers called "plymcout.ply" - but not always.

Sometimes when I'm running very long complicated calculations and I click anywhere on the layout and watch as the entire screen goes gray and shows "(not responding)" in the title (windows 7 computer)..... But this doesn't always happen.... It seems to depend on which filter I'm running (and which computer I'm running on, it happens more often on my slower Lenovo laptop)

I do see there is a console status box on the lower right corner of the screenshots, I wonder if I can monitor that text... Unfortunately from the AutoIt Window Info Tool, I don't see a way to grab that text - otherwise perhaps I could store that text to a variable first, apply the filter, and then montior that text box to see if the text has changed (inidicating the next "applied filter XYSZ" text has been added).

Currently, I have been using the Sleep command to pause for 10 seconds between the applied filters, but this is horribly inefficient as the delay changes with each 3D model I load. In order to make this code work on either of my machines, I'd have to add a 60-480 second delay between each step. This wouldn't work very well for me as built this script to help automate the process of tweaking and adjusting only a few key parameters of the process and watching the output, then restarting with slightly different params.

Thanks again for the help!

post-6885-0-47901700-1395246098_thumb.pn

post-6885-0-10322300-1395246154_thumb.pn

post-6885-0-07695100-1395246460_thumb.pn

Edited by cassetti

Share this post


Link to post
Share on other sites
jdelaney

While the application is 'thinking' it's probably not 'enabled'.

You can queue off that, using wingetstate.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
cassetti

While the application is 'thinking' it's probably not 'enabled'.

You can queue off that, using wingetstate.

 

Just created a simple script to execute to see if there is a change, here's my example code:

Local $state = WinGetState("MeshLab")
MsgBox(0, "MeshLab State", "Current state is " & $state)

When I run this code without doing anything in MeshLab, I get 39 - which isn't on the list of states listed in the help document. But none the less, when I run my filter, and quickly execute this code while the program is still busy, I still get 39

When I run the same code on the filter window

Local $state = WinGetState("Surface Reconstruction")
MsgBox(0, "MeshLab State", "Current state is " & $state)

I get 7. When I run the same code while the system is busy processing, I still get 7.

Doesn't look like I can use this method...

Just an update - I've done more testing, and get some strange results. When running these scripts (with and without a winactivate before the WinGetStat)e, I get results that change by themselves. For Example, I thought I had found 39 meant the system was busy while 47 meant the program was idle, but as I ran more tests, the program jumped between statuses, even when not doing anything in the application. When running long processes, the system still flucutates between the numbers.

Same results for monitoring the filter itself.....

Edited by cassetti

Share this post


Link to post
Share on other sites
BrewManNH

39 is on the list for WinGetState, it equals 32 + 4 + 2 + 1.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cassetti

39 is on the list for WinGetState, it equals 32 + 4 + 2 + 1.

 

Gotcha, I finally figured out how to use the BitAND

I've run a bunch of tests using this code (first run the long process, then I run this code while the process is still running:

$x = 0
While $x < 10 
   Sleep(100)
   WinActivate("MeshLab")
   If BitAND(WinGetState("MeshLab"), 4) = 4  Then
      $x = $x + 1  
  Else
      $x = 0  
      Beep()
      EndIf
   WEnd

Msgbox(0, "Test", "Ready for next process")

Unfortunately, I can't seem to get it to work.....

Is there any way to measure CPU loads? I can see a 50% increase in CPU load when I run the longest processes

Share this post


Link to post
Share on other sites
somdcomputerguy

I use this code to click a button in an application, then wait until the process it started is done. The button that gets 'clicked' is disabled while the program is doing it's thing, then becomes enabled when it's done. I doubt this code will solve your problem, but maybe it'll give you another idea or something. Good Luck.

If $Submittable <> 00 And MsgBox(4 + 32 + 4096 + 262144, StringTrimRight(@ScriptName, 4), $SubmitToQuestion) = 6 Then
    ControlClick("Forum Spam List Checker", "", "Button5") ;Submit button
    Sleep(250)
    Do
        Sleep(10)
    Until ControlCommand("Forum Spam List Checker", "", "Button5", "IsEnabled") ; Wait until Submission is done
EndIf

 

Ignore the If loop, it's not really related to this situation, I just ate too much copy/pasta..

  • Like 1

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites
cassetti

I use this code to click a button in an application, then wait until the process it started is done. The button that gets 'clicked' is disabled while the program is doing it's thing, then becomes enabled when it's done. I doubt this code will solve your problem, but maybe it'll give you another idea or something. Good Luck.

If $Submittable <> 00 And MsgBox(4 + 32 + 4096 + 262144, StringTrimRight(@ScriptName, 4), $SubmitToQuestion) = 6 Then
    ControlClick("Forum Spam List Checker", "", "Button5") ;Submit button
    Sleep(250)
    Do
        Sleep(10)
    Until ControlCommand("Forum Spam List Checker", "", "Button5", "IsEnabled") ; Wait until Submission is done
EndIf

Ignore the If loop, it's not really related to this situation, I just ate too much copy/pasta..

 

Awesome Idea, but unfortunately, it doesn't seem I can use the controlclick or control command as there is no ID number associated. I am using my finder tool in the window info, but it's not giving me anything. Attached is a screenshot of the finder tool results when selecting the apply tool in the uniform mesh resampling window.

Here's the code I'm attempting to run to clickt he apply button (trying to ensure I have the right control before I run a Do/Until loop.

WinActivate("Uniform Mesh")
ControlClick("[CLASS:QWidget; INSTANCE:3]", "","", "Left")

post-6885-0-91910300-1395328223_thumb.pn

Share this post


Link to post
Share on other sites
BrewManNH

You're using the control information in the parameter for the window's information, and you have no control information listed for the control to click.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
cassetti

I figured out how to use controlclick and control command to monitor both the main window and the filter window, unfortunately they both report the same "Enabled" and "visible" no matter what is happening (if the filter is processing or not).

ControlCommand("Uniform Mesh","", "[CLASS:QWidget; INSTANCE:3]", "IsEnabled","")

Really doesn't look like the program is being disabled, as I can still click on the file or edit menu options and click around while it's processing.....

Is there any way to monitor CPU loads? It's looking like that's the only way to monitor the actions. Unless I find some way to monitor the status bar colors - if it's tan the system is not running, if it's green at the 1% mark, it means the system is still processing data.....

Share this post


Link to post
Share on other sites
cassetti

 

All I could find was memory usage:

_WinAPI_GetProcessMemoryInfo

 

Unfortuantely, the memory usage doesn't spike when the process is running. I can see from the task manager the Meshlab.exe process averages around 0 to 1% cpu load under normal clicking, but it spikes to 25% when the one major filter is running.

I've been going through the helpfile trying to find anything that might help me monitor that, but coming up short.

I'm suprised this is such a complicated task, I was certain there was an easy way to halt Autoit while the program is executing commands....

Share this post


Link to post
Share on other sites
qwiqshot

This is right down what the center of what I am trying to achieve here. Not sure if anyone has tried detecting that a print process has ended before, but if you have any suggestions, please post on my referring thread.

 

 

Edited by qwiqshot

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • ur
      By ur
      if ControlClick("[CLASS:MsiDialogCloseClass]"," ","[CLASS:SysTreeView32; INSTANCE:1]") Then $htreeview=ControlGetHandle($hwnd,"","[CLASS:SysTreeView32; INSTANCE:1]") ControlTreeView($hwnd," ",$htreeview,"Select","#4") The above code worked well to enable the martupgrade feature on windows 7.
      As part of our Installation Testing Automation before delivering the installer to end user.To confirm whether all the screens are working good.

      But it is not working on windows 10.
       
      $h= ControlTreeView($hwnd," ",$htreeview,"Select","#4") The $h is getting value 1,which means error.
    • ur
      By ur
      I have automated an install process by using the below code.
       
      Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc $win1 = "Text 1" $win2 = "Text 2" _WinWaitActivate($win1,"WARNING: This progra") Send("{ALTDOWN}n{ALTUP}");Send("{SPACE}") _WinWaitActivate($win1,"I DISAGREE and &do n") Send("{UP}n") _WinWaitActivate($win1,"Customer Information") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}{TAB}n") _WinWaitActivate($win1,"Click Next to instal") Send("{ALTDOWN}n{ALTUP}");Send("n") _WinWaitActivate($win1,"This feature require") Send("{ALTDOWN}n{ALTUP}");Send("{TAB}n") _WinWaitActivate($win1,"Ready to Install the") Send("{ALTDOWN}i{ALTUP}");Send("i") _WinWaitActivate($win1,"The InstallShield Wi") Send("{ALTDOWN}f{ALTUP}");Send("f") _WinWaitActivate($win2,"You must restart you") Send("{ALTDOWN}n{ALTUP}");Send("n") Now if any new screen comes in the middle of installation, like some VC++ installation error or like that.
      The AutoIT is waiting in the background.
      Is there any way to skip the new screens with just "enter" and continue the installation??
    • TheInfamousOne
      By TheInfamousOne
      I have a small exe I created in AutoIt that seems to be causing some problems in OutLook when people go to save a PDF or Reply to emails.

      Here is my code.
       
      TraySetState(2) WinWait("[CLASS:#32770]", "Make sure that your sign-in address, user name, and password are correct and try again.", 0) WinClose( "Lync")  
      So this works just fine, it closes these message prompts we are trying to suppress.  But if the autoit executable is running when someone is using Outlook and they go to Save as PDF.  When they click "Save As" and go to type in the name of the file to save, they can't type in the box.  So if they close the autoit executable that's running only the code above, then they can use type in the name of the file.  So we know the EXE is preventing users from saving documents.

      Now, I'm sure it could be the way I've written this code, but I'm new to AutoIt and I'm not sure what could be causing this.  This little script seems like it' targeting the correct CLASS # and Window TItle and exact message.  So I don't understand why it's interfering with other applications.

      Any ideas?
    • feelie75
      By feelie75
      Hi. i googled and searched a lot before posting this. thanks for any help.
      I need to locate a window that has no title or discernible text, BUT is always the same size. The autoit documentation says:
      "X \ Y \ W \ H - The position and size of a window
      One or more properties are used in the title parameter of a window command in the format:
      [PROPERTY1 : Value1; PROPERTY2:Value2]"
      However, i can't figure out exactly how to do that. i tried:
      Local $winAW = WinWait("[W:506;H:288]", "", 30);
      That didn't work. I couldn't find an example of the specific format I need to use. Can someone provide a proven working example? Maybe that example can be added to the documentation? Thanks!
    • DeeJay7
      By DeeJay7
      I'm looking possible ways to optimize sleep time in a script which has multiple sleep times for save, refresh etc.
      The sleep duration varies from 5 secs to 17 secs time to time (depending upon the record, computer performance etc).
      Currently I set max sleep duration. ie sleep(17000).
      I'm looking possible ways to dynamically change sleep duration rather than fixed maximum duration.
      Note: winwait is not helpful in my script.
      Thanks in advance for your responses
×