Jump to content

WinWait not working on a working process?


Recommended Posts

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

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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

Link to comment
Share on other sites

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

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

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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..

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.....

Link to comment
Share on other sites

 

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....

Link to comment
Share on other sites

  • 2 years later...

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
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

×
×
  • Create New...