Re-use images captured before

Asked by Stuart Ng

Is there a way to re-use an image capture before?

For example, I have automated script A to click certain buttons on screen. Now, I need to automated script B which interacts with the same button. How would I accomplish this without having to recapture the same button twice?

It seems everything related to a script (python, html, png) are all stored in a folder, and different scripts have different folders.

Also, even if I want to interact with the same button twice in the same script, I can't do it in the IDE. (i.e. can not copy and paste the images and re-use for different commands like wait and click). I basically had to go into the python code and copy and paste the code myself.

Thanks!

Question information

Language:
English Edit question
Status:
Answered
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Rod Tietjen (rtietjen) said :
#1

The way I have been able to do this is to copy the command from Script A to Script B. This results in a command like click('somepic.png') appearing in the ide. The I have to open the ScriptA.sikuli folder and copy that .png to ScriptB.sikuli folder. Time consuming and annoying, I typically just recapture the image and more forward with that instead.

For reusing the image again in the same script, in the IDE I have been able to copy the orginal command and then paste it reusing the saved image on Windows, Mac and linux. I am uncertain why that does not work for you.

In my testing I have a adobe flash element that has a next button for navigation. I reuse that image close to 40 times per script.

Hope that helps,
Rod Tietjen

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

in script B:

scriptA = "path-to-the-scriptfolder.sikuli"
addImagePath(scriptA)

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

if you want to use images in more than on or two scripts here is another possibility:

- make up a myImages.sikuli, that only contains captured images in the form:

buttonOK = "captured image of button OK"
imageSomeName = "another captured image"

in the scripts that need the image, just say
from myImages import *
(look the docs mentioned above), and say:

find(imageSomeName)
click(buttonOK)

Be aware: Since the IDE does not reset imports on rerun, you have to stop and restart the IDE, after making changes to myImages.sikuli.

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

Can you help with this problem?

Provide an answer of your own, or ask Stuart Ng for more information if necessary.

To post a message you must log in.