<< Click to Display Table of Contents >> Navigation: 3. Script Language > Image/Pixel-Color Operations > Non-IR Operations > Image/Pixel-Color Operations |
MiniRobotLanguage (MRL)
ILC. / NLC. Conditional Statement
If Line Color
Intention
Conditional Statement.
Test if an defined Color is been found along a defined Line.
Or, test how often a color does not match a defined color along a given line.
This is done using the "!" Operator.
This command can be used to locate buttons in graphical environments, where we can not use any other commands to locate them.
Important: Color-Operations are often troublesome because colors may not match exactly. Therefore this command provides you with a "Color Tolerance" Option.
Also you have the choice of using a "negative version" which will just check that colors do NOT match a given color/tolerance. And you can combine all this, with the resolution independent SPR 3.6 Using Quadrant-Coordinates to make your Scripts run as compatible as possible.
Hint:
When Designing Pixel-Operations, use the "Catseye-Analyzer".
It will show you Color-Values and other needed Information.
The "Catseye-Analyzer" is located in the Installation Folder.
The four parameters are line-coordinates, Color, Color-Tolerance and Hit-Counter.
Parameter 1 - Line-Coordinates:
The Line is defined by a Start- and and Endpoint. Using the following Format:
ILC.x1,y1,x2,y2
As always, if you omit y2 then y2 is assumed to be equal to y1.
If you omit the coordinates, the last located window or other object-rectangle is been taken, and the line goes from the upper-left to the lower-right corner.
Instead of using Pixel-Coordinates, you can use 3.6 Using Quadrant-Coordinates to make your Scripts run as compatible as possible.
Example:
ILC.{A1,A2}
Now writing this will use the Screen-Quadrant A1, which is most often not what we want. So we add an letter in front:
ILC.w{A1,A2}
This will tell the command that we want to use the Quadrant in the last located window (child- or Topwindow).
You can use:
"w" - Any window (Top- or Child-Window) that was last located
"t" - last located Top-Window
"c" - use Client-Coordinates of tzhe specified window. If no window is specified "w" is used as default.
"o" - use the last defined Object-Coordinates (window, Accessible Object or graphical Object).
You can combine the letters as far as it makes sense:
"wc" - use last windows Client-Coordinates
"tc" - use last Top-windows Client-Coordinates
at this place you can add 2 Special Characters:
"@" - Enable Debug Option. Using this special Character will open a Window that shows the part of the Screen that is used for the Command. Be careful, when using WRC. with this Option, as it will of course run in a Loop.
"#" - this Option will reduce the Border of the Target Area by 2 Pixels in all directions.
"##" - using multiple "#" will reduce the Border of the Target Area by 2 Pixels times the number of "#" in all directions. If you use "##" it will decrease the target size by 4 Pixel.
"#8" - using "#" followed by a numeric value, the border of the Target Rectangle will be decreased by the given Amount of Pixels. In this case the border would be decreased by 8 Pixels, from any direction.
You can omit the Quadrant coordinates and just write (using any of the letters from above):
ILC.w
Then internally the command will complete the target with
ILC.w{A1,D4}
General Usage is as simple as:
' Using ILC. with a Edit-Box from TestApp
'
STW.ct|PBWindowClass:0|TestApp
SCW.nict|1|1023|Edit|{&NOTEXT:}
' Clear Edit-Box
SDT.
ILC.
VAR.$$LAA=1
ELS.
VAR.$$LAA=0
EIF.
MBX.Result is $$LAA
' Now we write into the Edit-Box
SDT.Hallo
ILC.
VAR.$$LAA=1
ELS.
VAR.$$LAA=0
EIF.
MBX.Result is $$LAA
ENR.
STW.ct|MyClassName|Sample Application
'SCW.nct|1|Edit|{&NOTEXT:}
:again
PAU..1
ILC.|&HFF0000|0|4
DMP.6
MBX.!
ELS.
GTO.again
EIF.
:over
ENR.
Using local (window-) coordinates:
If you prefix the coordinates with a "w" then they will be interpreted as local window coordinates. Like in this example:
STW.ct|MyClassName|Sample Application
SCW.nct|1|Edit|{&NOTEXT:}
MMV.
:again
PAU..1
ILC.w1,1,10,10|!&HFFFFFF|0|3
GTO.over
ELS.
DMP.6
GTO.again
EIF.
:over
DMP.6
MBX.Ready
ENR.
Using SPR 3.6 Quadrant-Coordinates
' Looks like this
ILC.{D3}|$$COL|$$TOL
DBP. 1
ELS.
DBP. 0
EIF.
Parameter 2 - Color:
If this color is found along the defined Line then the decision will switch to "true".
Colors can most easily be described as a HEX-Number, like this example:
&HFFEE22
&HRRGGBB
If you prefix the color-parameter with a "!" (NOT Operator) then the command will count all Pixels that do NOT have that defined color and tolerance.
Please note that this is different from the NLC.-command, which gives you additional options.
Parameter 3 - Color Tolerance:
If there are different graphic cards used, the pixels may not become rendered always in the exactly same way. Therefore the color tolerance gives you the chance to tell the robot "How sensitive" he should be when deciding if a pixel is different or not.
To make this decision, the robot will take the color of both pixels and calculate their "Color distance", that is "How similar the colors are". As a result he will get a number that can vary from 0 to 441673. Next Smart Package Robot will get your tolerance value and check if the calculated color distance is inside the chosen tolerance or not. Alternatively you can use a percentage value, if you add a %-sign after the number.
Parameter 4 - Hits-Counter:
Imagine a Textbox like this:
You want to wait until there is a text inside, but the blinking cursor should not make your Script react. Now what you tell Smart Package Robot is a "Hit Count" of lets say 12 Pixels.
This Script will switch, after you really typed "88888888" into the first, left textbox.
STW.ct|MyClassName|Sample Application
SCW.nct|1|Edit|{&NOTEXT:}
:again
PAU..1
ILC.|0|0|12
GTO.over
ELS.
GTO.again
EIF.
:over
ENR.
This makes Smart Package Robot count the changed pixels, and only if she gets more then "Hit Count" she will switch. Otherwise the condition will not become true, even if there are changed pixels (but less).
The "negative Mode" using the "!" NOT Operator
Instead of counting the Pixels that do have a defined color, you can also do the opposite.
You can count the Pixel that do NOT have that defined color.
This is done, by prefixing the "Color-Parameter" with a !.
Like in this example.
STW.ct|MyClassName|Sample Application
SCW.nct|1|Edit|{&NOTEXT:}
:again
PAU..1
ILC.|!&HFFFFFF|0|12
GTO.over
ELS.
DMP.6
GTO.again
EIF.
:over
ENR.
The Stack when using ILC.
In case of success, ILC. will leave four values on the stack. As you can see below, these are:
TOS: X-Position of first found Hit
001: Y-Position of first found Hit
002: Color of first found Hit
003: Number of found Pixel meeting the condition
Here is another example.
The color is in hexadezimal in RRGGBB.
And there is NLC.
NLC. is the negative version "If Not Line Color".
Syntax
ILC.[w/t/c/o][P1][|P2][|P3]… ELS. … EIF.
Parameter Explanation
P1 - (optional) Start and End-Points of the Line. There are different possible Formats for these Coordinates. For details see description above. You can use:
"w" - Any window (Top- or Child-Window) that was last located
"t" - last located Top-Window
"c" - use Client-Coordinates of tzhe specified window. If no window is specified "w" is used as default.
"o" - use the last defined Object-Coordinates (window, Accessible Object or graphical Object).
You can combine the letters as far as it makes sense:
"wc" - use last windows Client-Coordinates
"tc" - use last Top-windows Client-Coordinates
at this place you can add 2 Special Characters:
"@" - Enable Debug Option. Using this special Character will open a Window that shows the part of the Screen that is used for the Command. Be careful, when using WRC. with this Option, as it will of course run in a Loop.
"#" - this Option will reduce the Border of the Target Area by 2 Pixels in all directions.
"##" - using multiple "#" will reduce the Border of the Target Area by 2 Pixels times the number of "#" in all directions. If you use "##" it will decrease the target size by 4 Pixel.
"#8" - using "#" followed by a numeric value, the border of the Target Rectangle will be decreased by the given Amount of Pixels. In this case the border would be decreased by 8 Pixels, from any direction.
With out the leading "w", any coordinates are Screen-Coordinates. Its best practice, to prefer Child-Window-relative coordinates:
ILC.w18,56,153,57|$$COL|$$TOL
You can simply specify the start and end-point. In this format:
ILC.x1,y1,x2,y2
a real example would be:
ILC.10,15,100,200
Or you can specify a Rectangle, using only 3 Numbers like:
ILC.10,15,100
then y2 is assumed to be the same as y1.
You can also use 3.6 Using Quadrant-Coordinates.
In this case the Line will be drawn from the upper-left corner straight to the lower right corner.
ILC.{D1,D2}|$$COL|$$TOL
ILC.{B1}|$$COL|$$TOL
If P1 is omitted the Rectangle from the last localized Object or window is taken, same as "w".
P2 - (optional) numeric/variable contains the color value to scan for.
P3 - (optional) numeric/variable contains the Tolerance to be used when checking if a color is different. You can specify the color tolerance as a numeric value from 0 - 441673, or you can specify a percentage from 0% to 100%. If you specify a percentage, just add the % Sign after the number. The color tolerance is the maximum allowed Color-Distance between two colors. The maximum color distance is 441673 that is the distance between black and white. If you omit this parameter, the system will use a zero Tolerance. In this case the colors are just "equal or not equal".
P4 - (optional) numeric/variable contains the minimum number of "Hits" that are pixels that have to be different to make the decision to become "true".
ILC.'s can be nested to unlimited Depth, and they can also enclose Sub-Program Calls or FEX. (Enumerations) to unlimited Depth.
Example
'***********************************
' ILC.-Sample, using Quadrant Coords
'***********************************
$$COL=!&HFFFFFF
$$TOL=100
STW.ct|Chrome_WidgetWin_1|- Google Chrome
SCW.c|renderwi
ILC.w{A1,B1}|$$COL|$$TOL
STS.DUMP
$$XPA=$$000
$$YPA=$$000
MMV.w|$$XPA,$$YPA
ELS.
DBP.$time$
EIF.
:outA
MBX.!
'***********************************
' ILC.-Sample 2
' using window-local Coordinates
'***********************************
$$COL=!&HFFFFFF
$$TOL=100
STW.ct|Chrome_WidgetWin_1|- Google Chrome
SCW.c|renderwi
ILC.w18,56,153,57|$$COL|$$TOL
'ILC.{D1}|$$COL|$$TOL
STS.DUMP
$$XPA=$$000
$$YPA=$$000
MMV.$$XPA,$$YPA
ELS.
DBP.$time$
EIF.
:outA
MBX.!
ENR.
'***********************************
' ILC.-Sample
' using a Diagonal Line from Top-left to lower right
' of the actual window(child-window
'***********************************
$$COL=!&HFFFFFF
$$TOL=100
STW.ct|Chrome_WidgetWin_1|- Google Chrome
SCW.c|renderwi
ILC.t|$$COL|$$TOL
STS.DUMP
$$XPA=$$000
$$YPA=$$000
MMV.$$XPA,$$YPA
ELS.
DBP.$time$
EIF.
:outA
MBX.!
ENR.
'***********************************
' ILC.-Sample
'***********************************
' Use "Sample Application"
' Click into the left Edit-Field to end the Loop
STW.ct|MyClassName|Sample Application
SCW.nct|1|Edit|{&NOTEXT:}
:again
PAU..1
' Coordinates omitted - he'll take the last window-Rect
ILC.|&H0|0|4
DMP.6
MBX.!
ELS.
GTO.again
EIF.
:over
ENR.
'***********************************
' ILC.-Sample 2
'***********************************
' Search for any "Non-white" color
$$COL=!&HFFFFFF
' with a color Tolerance of 100
$$TOL=100
' left X-Position in window-Coordinates
$$XPO=303
' upper Y-Position in window-Coordinates
$$YPO=203
' lower Y-Position
$$YMX=365
' vertical Size is calculated
CAL.$$YSZ=$$YMX-$$YPO
' Locate Target window
STW.ct|Chrome_WidgetWin_1|- Google Chrome
' Do it again ...
:again
ILC.w$$XPO,$$YPO,($$XPO+20),($$YPO+$$YSZ)|$$COL|$$TOL
' This will show the results from ILC. in a Debug-COnsole
STS.DUMP
' When we take the first Coordinate from stack
' its automatically removed, so the next coordinate
$$XPA=$$000
' is also on Top of stack
$$YPA=$$000
' Here we click the button
' note the () for the inline-calculation
MLI.$$XPA,($$YPA+1)
' 70 is expected y-size of a button
' we increment and look for the next button
CAL.$$YPO=$$YPO+70
' if we exceed the lower maximum coordinate, we jump out
JIV.$$YPO>$$YMX|out
' else we do it again
GTO.again
ELS.
DBP.$time$
EIF.
:out
MBX.!
'-----------------------------------------------------------
ENR.
' This the situation i have used for testing.
ILC.-Example 2 was used to click several Buttons that could not be located (graphical buttons) in a Browser-Window.
Remarks
-
Limitations:
-
See also:
• ! Smart Package Robot 's Pixel-Operations
• 3.6 Using Quadrant-Coordinates
• RRA. - Remember Rectangular Area
• IRA. / NRA. - If Rect altered
• WRA. - Wait Rect-Area Altered
• 1.8.1 The "Client" and the "Non-Client" Parts of a window
• IPC. / NPC. - If-Pixel-Colour