How to access last match --- assign match to variable or use Region.getLastMatch()

Asked by Linus Holmeros

Hi, i´m trying to axcess the last found object and make a region from that.

what object contains the last match which i can use?

code:

if find(Pattern(TargetDialog).similar(0.90)):
        print "found"
 m = Match
 x = m.getX()-20
 y = m.getY()-10
 w = 1000
 h = 220
 FKURegion = Region(x,y,w,h)

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
RaiMan (raimund-hocke) said :
#1

if exists(Pattern(TargetDialog).similar(0.90)):
        print "found"
        m = getLastMatch()
        FKURegion = Region(m.x-20,m.y-10,1000,220)
else:
        print ("Sorry, not found"); exit() # or any corrective action

--- comment:
if find(Pattern(TargetDialog).similar(0.90)):
        print "found"

does not make much sense:
- if not found, your script will stop anyway with exception FindFailed
- so if your script continues, you know, it was found ;-)

so this would be sufficient:

m = find(Pattern(TargetDialog).similar(0.90))
x = m.getX()-20
y = m.getY()-10
w = 1000
h = 220
FKURegion = Region(x,y,w,h)

Can you help with this problem?

Provide an answer of your own, or ask Linus Holmeros for more information if necessary.

To post a message you must log in.