Specify targetOffset(). to match object

Asked by Chetan on 2021-02-16

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2021-02-25
Last query:
2021-02-25
Last reply:
2021-02-17

This question was reopened

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))

Chetan (cshamdas) said : #2

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

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

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

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)

Chetan (cshamdas) said : #6

Thanks for your help

Chetan (cshamdas) said : #7

Thanks RaiMan, that solved my question.