Specify targetOffset(). to match object

Asked by Chetan

Hi
i am searching for image and if image exists if return match object.
now in this match object i want to click on certain location
 click(obj.targetOffset(2,2))
where obj is match object

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:

This question was reopened

Revision history for this message
Manfred Hampl (m-hampl) said :
#1

You can specify the targetOffset when defining the match object.
obj = region.find(...).targetOffset(2,2)

And

Since a match object is a region, you could work with the location
click(obj.getCenter().offset(2,2))

Revision history for this message
Chetan (cshamdas) said :
#2

i am using s obj.setTargetOffset(20,20) that works for me

Revision history for this message
Chetan (cshamdas) said :
#3

when i use SCREEN.find("1613534584953.png").targetOffset(2,2)
then get below error
    obj=SCREEN.find("1613534584953.png").targetOffset(2,2)
TypeError: 'org.sikuli.script.Location' object is not callable

Revision history for this message
Chetan (cshamdas) said :
#4

when i use SCREEN.find("1613534584953.png").targetOffset(2,2))
then get below error
    obj=SCREEN.find("1613534584953.png").targetOffset(2,2)
TypeError: 'org.sikuli.script.Location' object is not callable

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

The intended use of targetOffset() is with a Pattern() object:
somePattern = Pattern(someImage).targetOffset(x, y)
click(somePattern)

Your approach only makes sense, if you want to assign more than one offset to a match, that is found once and reused several times.

- modifying the match:
match = find(someImage)
click(match.setTargetOffset(x,y))

- not modifying the match (see Manfed Hampel above comment#1):
match = find(someImage)
click(match.getCenter().offset(x, y))

or even shorter:
click(match.offset(x, y))
(this creates a new Region with top-left offset and same size and it's center is clicked then)

Revision history for this message
Chetan (cshamdas) said :
#6

Thanks for your help

Revision history for this message
Chetan (cshamdas) said :
#7

Thanks RaiMan, that solved my question.