image not found during 2nd run

Asked by Daniel de Winter


I hope someone can help me with the following problem

Kind regards,

1. I run the script as shown below.
2. the first run, object1 is created and "mypicture.png" is found.
3. object 2 is created with a rectangle with size 123,123,123,123 problem so far...

4. the second time I let the IDE run the script (ctrl+r): the image "mypicture.png" is NOT FOUND. Note the area where it's looking for has the size of the rectangle from class 2. 3rd, 4th run: same problem
6. restarting the Sikulix IDE 'solves' the problem

IDE: 2.0.5 build: 2021-3-3 9:10

from sikuli import *

class Myclass1:

    def mydef1(self):
        match1 = find("mypicture.png")

class Myclass2:

    def mydef2(self):
        myRect = setRect(123,123,123,123)

myobj1 = Myclass1()

myobj2 = Myclass2()
Error after running this script for the 2nd (!!!!!!) time:

[error] script [ module1 ] stopped with error in line 18
[error] FindFailed ( mypicture.png: (48x25) seen at (527, 325) with 0.90 in R[123,123 123x123]@S(0) )
[error] --- Traceback --- error source first
line: module ( function ) statement
6: main ( mydef1 ) match1 = find("mypicture.png")
18: main ( <module> ) myobj1.mydef1()
[error] --- Traceback --- end --------------

Question information

English Edit question
SikuliX Edit question
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Daniel de Winter (daniwin82) said (last edit ):

=== UPDATE ===

When I remove the line: from sikuli import *

the script can be run multiple times without an error.
...but this no solution, since then the sikuli stuff isn't imported

=== UPDATE #2 ===
btw: I'm using the construction:
import x
from x import * stated here:

...but this doesn't make a difference.
So far, restarting the IDE is the only solution to the problem....but this is a bit cumbersome

Revision history for this message
Daniel de Winter (daniwin82) said :
Revision history for this message
RaiMan (raimund-hocke) said :

In the first run find() searches on the whole screen.
After that you use setRect(), which also changes the constant SCREEN (main screen), to only the given area.

Since the Python interpreter context is static, changes to global variables are remembered in the next run.

As the error tells you:
FindFailed ( mypicture.png: (48x25) seen at (527, 325) with 0.90 in R[123,123 123x123]@S(0)

it was found at (527, 325) which surely is outside of R[123,123 123x123].

So you should use Region() to define area objects:
myRect = Region(123,123,123,123)

Not sure if you know that:
from sikuli import *
is not needed in the main script, when using SikuliX to run the script.

Can you help with this problem?

Provide an answer of your own, or ask Daniel de Winter for more information if necessary.

To post a message you must log in.