I am using EveryImageLocation(Image:“image path”, SearchRectangular:(search_area)) to find the location and number of images in a window. When there is no image to find, I want the statement to be as quick as possible and give me zero. The reason is the window closes after 10 seconds and script fails.
I can include max wait time in ImageFound() statement but not in EveryImageLocation().
How can I include a duration in EveryImageLocation()?
When there is no image to find, I want the statement to be as quick as possible and give me zero. How can I include a duration in EveryImageLocation()?
You can’t. The command doesn’t provide for that.
I would just do an
before doing the EveryImageLocation(). The imageFound() will find the image quickly if it exists and the everyImageLocation() will then also quickly identify where the images are.
The reason is the window closes after 10 seconds and script fails.
This seems like a bad design. Why bother displaying something that the user will only see if they happen to be looking at the screen for those ten seconds? If it’s important enough to display, put it up and leave it up until the user dismisses it. Otherwise, just don’t bother to display it at all. If I were you, I would log a bug against that behavior.
Also, if you want to run just the everyImageLocation() command and not have the script fail if the image isn’t found, you could use this code:
Try to put EveryImageLocation(Image:"image path", SearchRectangle:(search_area)) into someVar
The “try to” is an abbreviated form of a try/catch block and it will catch the exception if no image is found so that the script doesn’t fail at that point.
Lastly, there is an error in your code as posted here:
EveryImageLocation(Image:"image path", SearchRectangular:(search_area))
The correct property name is searchRectangle, not searchRectangular. If your actual code contains searchRectangular, then that property is just being ignored and not doing anything to constrain the search area.[/quote]