How to work with Set Clipping region

How to work with Set Clipping region?

The image projected on the computer screen will be the default region of workspace where image based automation works, finds image, clicks an image etc.

Let's assume a scenario where you have a lot of repetitive images, or your area screen is simply large and would take more time to perform image based automation. In general scenario, a developer will have a fair idea where the image might appear. In such a scenario, you can simple manipulate the working are and reduce it to a smaller one resulting in faster output. In order to achieve this, you will need "set clipping region" activity's help.

Below example should give you a fair idea on different ways you can work with clipping region.

NOTE: Unless you set reset the clipping region to default, the region remains the same throughout the runtime. You can reset the clipping region by simple adding a new "Set Clipping Region" and pass (0,0,0,0) to all 4 end regions.

i) Setting up a static working region

Set clipping region accepts a hard coded co-ordinates where you can set the attributes (Left, Top, Right, Bottom) and manipulate the working region directly.

On the other hand, if the direction property is set to rectangle, it will accept differently, that is, (x,y,width,height). 

ii) Setting up by using find element or find image

Find image, find element activity sets the clipping region to the region covering only the element or the image if it is found in the working region. Provided, put it inside the attach window.

This will help you identifying the position of element or image, late you can manipulate this region by using TRANSLATE property of "Set Clipping Region". Translate property uses base co-ordinates as reference and moves each direction with reference. That is, if you want to move the region to the right of the screen, then your direction's change as defined below.

base co-ordinate: (left: 100, top: 150, right: 200, bottom: 300)

translating 100 px to right: (left: -100 , top 150, right: 300, bottom: 300)

iii) Setting a region by passing a rectangle object

You can set the region by passing the rectangle object. You can add by using example below.

UiPath.Core.Region(New Rectangle(20,832,150,130)) heree, the coordinates mentioned would be (x,y,Width,Height) 

NOTE: 

  • Providing the parameter Region or directly providing the size would be different as one has height/width and the other has right/bottom as a parameter.
  • While Using the "Direction" property of the clipping region you expand the clipping region based on the Direction mentioned.

Example:  In case "LEFT" - > Direction, size "LEFT" would be considered and expand to the pixel mentioned in it and same would go for other Direction parameters "Top/Right/Bottom".