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.
Assume a scenario where 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, manipulate the working area and reduce it to a smaller one resulting in faster output. In order to achieve this use "set clipping region" activity.
Below example should give a fair idea on different ways to work with clipping region.
NOTE: Unless there is a reset of the clipping region to default, the region remains the same throughout the runtime. Reset the clipping region by simple adding a new "Set Clipping Region" and pass (0,0,0,0) to all 4 end regions.
- 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).
- 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 to identify the position of element or image, 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, to move the region to the right of the screen, then directions shall 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)
- Setting a region by passing a rectangle object
Set the region by passing the rectangle object. Add by using example below.
UiPath.Core.Region(New Rectangle(20,832,150,130)) here, 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".
See Set Clipping Region Documentation for more details.
To download an example of how the Set Clipping Region activity is used, that incorporates multiple activities.