Use of image library within Sikuli IDE

Asked by surfdork

I looked and did not find a clear answer to this issue.

Using SikuliIDE can I access a self defined image library in my scripts?

I use Sikuli to define the pattern then refactor or at least I tried.

This fails

openApp ("C:\\srinstall\\setup.exe")#works
while not exists(Pattern("C:\\SikuliImageLibrary\\Install\\1.png").targetOffset(-48,43), 0):#fails
 wait (1)
doubleClick(Pattern("C:\\SikuliImageLibrary\\Install\\1.png").targetOffset(-50,43), 0):
while not exists("C:\\SikuliImageLibrary\\Install\\2.png", 0):
 wait(1)

[sikuli] An error occurs at line 4
[sikuli] Error message:
SyntaxError: ("mismatched input ':' expecting NEWLINE", ('C:\\Users\\OVADMI~1.OVE\\AppData\\Local\\Temp\\sikuli-tmp4113924293878987047.py', 4, 53, 'doubleClick(Pattern("1.png").targetOffset(-35,44), 0):\n'))

I'm lost

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

on the line
doubleClick.... there is an ending colon, that should not be there (exactly what the error message tells you ;-)

tip 1:
if the scripts use images that are stored elsewhere, just say in your case:
setLibPath("C:\\SikuliImageLibrary\\Install\\")

then SikuliScript will look for images in this directory:
while not exists(Pattern("1.png").targetOffset(-48,43), 0): # e.g.

tip 2:
using exists(img) and afterwards click(img) is not efficient, since you have 2 searches for the same visual object.
so either save the match from exists() (mandatory if there are other find operations before you use the match again in a click) or use getLastMatch() (in your case).
while not exists(img):
   wait(1)
doubleClick(getLastMatch()) # will click on what exists() has matched.

Revision history for this message
surfdork (surfdork) said :
#2

Thank You!

Revision history for this message
surfdork (surfdork) said :
#3

Thanks RaiMan, that solved my question.

Revision history for this message
Linus Holmeros (linus-holmeros) said :
#4

Where do you put setLibPath("C:\\SikuliImageLibrary\\Install\\")?
in the funtion or main program?

Revision history for this message
RaiMan (raimund-hocke) said :
#5

Sorry, I mixed up the method name.

It is:

setBundlePath("C:\\SikuliImageLibrary\\Install\\")

and has to be somewhere in the beginning, before the first reference to an image stored in this folder.

Revision history for this message
RaiMan (raimund-hocke) said :
#6

But if you use this, **ALL** images you use have to be there.

If you want to mix different locations including captured images in the script itself, you have to use addImagePath()
or import some_script (a some_script.sikuli is stored in a folder, that has to be in sys.path).

read: http://sikuli.org/docx/globals.html#importing-other-sikuli-scripts-reuse-code-and-images