Sikuli Script in Python loop

Asked by Dominik Er

Hello,

I have a python script, which opens data in a programm to Analyse. I wrote a quick and easy Sikuli script for that. How can i execute the Sikuli Script in my loop in python?

Thank you in advance for the help

Question information

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

lets say, analyse.sikuli contains your script.

in analyse.sikuli you have to wrap your current script code into a def():

def runAnalyse():
    #your current code indented

make a new .sikuli (runAnalyse.sikuli) in the same folder where you have analyse.sikuli:

import analyse
while True: #the loop
   analyse.runAnalyse()

... this is the simplest solution and has to be killed to stop.

Revision history for this message
Dominik Er (dominiker97) said :
#2

which Script are you refferung to?
Sikuli is giving me this as an .py Output (i just started using it today, sos sorry for some easy questions):
click("1594805876723.png")
wait("1594806779837.png")
type("6", KeyModifier.ALT)
wait("1594810923451.png")
type("3", KeyModifier.ALT)
click("1594811407539.png")
wait("1594811434094.png")
click("1594811448859.png")
wait("1594811477901.png")
click("1594811496208.png")
wait("1594811550116.png")
click("1594811564717.png")
wait("1594812333917.png")
click("1594812349167.png")
wait("1594812405160.png")
click("1594812422213.png")
wait("1594812448369.png")
click("1594812462632.png")
wait("1594812487205.png")
click("1594812538340.png")
sleep(5)
click("1594815007042.png")

my python loop Looks like this:
print(rohdaten)
for filename in os.listdir(rohdaten):
 if filename.endswith(".svd") and not("Scan") in filename:
  print(os.path.join(rohdaten, filename))
  os.system("start " + filename)
               # TODO : Import Sikulix

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

I suppose this is your analyse.sikuli:

click("1594805876723.png")
wait("1594806779837.png")
type("6", KeyModifier.ALT)
wait("1594810923451.png")
type("3", KeyModifier.ALT)
click("1594811407539.png")
wait("1594811434094.png")
click("1594811448859.png")
wait("1594811477901.png")
click("1594811496208.png")
wait("1594811550116.png")
click("1594811564717.png")
wait("1594812333917.png")
click("1594812349167.png")
wait("1594812405160.png")
click("1594812422213.png")
wait("1594812448369.png")
click("1594812462632.png")
wait("1594812487205.png")
click("1594812538340.png")
sleep(5)
click("1594815007042.png")

... then it has to be modified so:

def runAnalyse():
    click("1594805876723.png")
    wait("1594806779837.png")
    type("6", KeyModifier.ALT)
    wait("1594810923451.png")
    type("3", KeyModifier.ALT)
    click("1594811407539.png")
    wait("1594811434094.png")
    click("1594811448859.png")
    wait("1594811477901.png")
    click("1594811496208.png")
    wait("1594811550116.png")
    click("1594811564717.png")
    wait("1594812333917.png")
    click("1594812349167.png")
    wait("1594812405160.png")
    click("1594812422213.png")
    wait("1594812448369.png")
    click("1594812462632.png")
    wait("1594812487205.png")
    click("1594812538340.png")
    sleep(5)
    click("1594815007042.png")

In another script you want to use your function runAnalyse():

import analyse
print(rohdaten)
for filename in os.listdir(rohdaten):
 if filename.endswith(".svd") and not("Scan") in filename:
  print(os.path.join(rohdaten, filename))
  os.system("start " + filename)
  analyse.runAnalyse()

Revision history for this message
Dominik Er (dominiker97) said :
#4

Thx, calling the function works.
which library for python do you need to execute the analyse function. I get the error that click ist not defined.
I have also been searching in Anaconda and he dont seem to have a Sikuli library.

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

uups, sorry.

forgot to point you to the docs too:
https://sikulix-2014.readthedocs.io/en/latest/scripting.html#importing-other-sikuli-scripts-reuse-code-and-images

the
from sikuli import *
is missing in the imported script

Revision history for this message
Dominik Er (dominiker97) said :
#6

Sorry, but im back again.

seems like with the Proxys on my Workstation it is not possible to integrate the script directly.
i tried using the pyaoutgui click() fkt and got this message:
Mouse actions are blocked generally or by the frontmost application.
i tried running it as an Administrator, but it didint work. any ideas how to fix it?

Revision history for this message
Dominik Er (dominiker97) said :
#7

i found a Workaround.

when you run the script like this:
import pyautogui as pg

pg.click(x = 2206, y = 353)
pg.hotkey('ctrl', 'r')

Then sikuli can use the mouse.