Bounds Property

Applies to TestComplete 15.68, last modified on October 16, 2024

Description

The Bounds property returns an object that describes the bounds of a text block within an object or image, to which the text block belongs.

Declaration

OCRTextBlockObj.Bounds

Read-Only Property A Bounds object
OCRTextBlockObj An expression, variable or parameter that specifies a reference to an OCRTextBlock object

Applies To

The property is applied to the following object:

Property Value

A Bounds object that describes the rectangle containing the recognized portion of text.

Example

The following example shows how to use optical character recognition to recognize the text of the About dialog of Windows Notepad and get the rectangle that contains the About Notepad portion of text.

JavaScript, JScript

function GetTextBounds()
{
  var textToGet = "*About*Notepad*";

  var p = Sys.WaitProcess("notepad", 3000);
  if (p.Exists)
  {
    // Get the Notepad window
    var wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000);
    if (wndNotepad.Exists)
    {
      wndNotepad.MainMenu.Click("Help|About Notepad");
      // Get the About Notepad window
      var wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000);
      if (wndAbout.Exists)
      {
        // Recognize the text that the About Notepad window contains
        var recognizedText = OCR.Recognize(wndAbout);

        // Get the portion of the recognized text
        var textBlock = recognizedText.BlockByText(textToGet);
        if (textBlock != null)
        {
          // Get info on bounds of the recognized text portion
          var x = textBlock.Bounds.Left;
          var y = textBlock.Bounds.Top;
          var width = textBlock.Bounds.Width;
          var height = textBlock.Bounds.Height;

          // Post an image of the window area that contains the specified text
          Log.Picture(wndAbout.Picture(x, y, width, height), "View the image of the area containing text " + textToGet + " in the Picture panel.");
        }
      }
    }
  }
  else
  {
    Log.Warning("Notepad is not running.");
  }
}

Python

def GetTextBounds():

   textToGet = "*About*Notepad*"

   p = Sys.WaitProcess("notepad", 3000)
   if p.Exists:
     # Get the Notepad window
     wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000)
     if wndNotepad.Exists:
       wndNotepad.MainMenu.Click("Help|About Notepad")
       # Get the About Notepad window
       wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000)
       if wndAbout.Exists:
         # Recognize the text that the About Notepad window contains
         recognizedText = OCR.Recognize(wndAbout)

         # Get the portion of the recognized text
         textBlock = recognizedText.BlockByText(textToGet)
         if textBlock != None:
           # Get info on bounds of the recognized text portion
           x = textBlock.Bounds.Left
           y = textBlock.Bounds.Top
           width = textBlock.Bounds.Width
           height = textBlock.Bounds.Height

           # Post an image of the window area that contains the specified text
           Log.Picture(wndAbout.Picture(x, y, width, height), "View the image of the area containing text " + textToGet + " in the Picture panel.")
   else:
     Log.Warning("Notepad is not running.")

VBScript

Sub GetTextBounds

  textToGet = "*About*Notepad*"

  Set p = Sys.WaitProcess("notepad", 3000)
  If p.Exists Then
    ' Get the Notepad window
    Set wndNotepad = p.WaitWindow("Notepad", "*", 1, 3000)
    If wndNotepad.Exists Then
      wndNotepad.MainMenu.Click("Help|About Notepad")
      ' Get the About Notepad window
      Set wndAbout = p.WaitWindow("#32770", "About Notepad", 1, 3000)
      If wndAbout.Exists Then
        ' Recognize the text that the About Notepad window contains
        Set recognizedText = OCR.Recognize(wndAbout)

        ' Get the portion of the recognized text
        Set textBlock = recognizedText.BlockByText(textToGet)
        If Not textBlock Is Nothing Then
          ' Get info on bounds of the recognized text portion
          x = textBlock.Bounds.Left
          y = textBlock.Bounds.Top
          width = textBlock.Bounds.Width
          height = textBlock.Bounds.Height

          ' Post an image of the window area that contains the specified text
          Call Log.Picture(wndAbout.Picture(x, y, width, height), "View the image of the area containing text " & textToGet & " in the Picture panel.")
        End If
      End If
    End If
  Else
    Log.Warning("Notepad is not running.")
  End If
End Sub

DelphiScript

procedure GetTextBounds();
var textToGet, p, wndNotepad, wndAbout, recognizedText, textBlock, x, y, width, height;
begin

  textToGet := '*About*Notepad*';

  p := Sys.WaitProcess('notepad', 3000);
  if p.Exists then
  begin
    // Get the Notepad window
    wndNotepad := p.WaitWindow('Notepad', '*', 1, 3000);
    if wndNotepad.Exists then
    begin
      wndNotepad.MainMenu.Click('Help|About Notepad');
      // Get the About Notepad window
      wndAbout := p.WaitWindow('#32770', 'About Notepad', 1, 3000);
      if wndAbout.Exists then
      begin
        // Recognize the text that the About Notepad window contains
        recognizedText := OCR.Recognize(wndAbout);

        // Get the portion of the recognized text
        textBlock := recognizedText.BlockByText(textToGet);
        if textBlock <> nil then
        begin
          // Get info on bounds of the recognized text portion
          x := textBlock.Bounds.Left;
          y := textBlock.Bounds.Top;
          width := textBlock.Bounds.Width;
          height := textBlock.Bounds.Height;

          // Post an image of the window area that contains the specified text
          Log.Picture(wndAbout.Picture(x, y, width, height), 'View the image of the area containing text ' + textToGet + ' in the Picture panel.');
        end;
      end;
    end;
  end  else
    Log.Warning('Notepad is not running.');
end;

C++Script, C#Script

function GetTextBounds()
{
  var textToGet = "*About*Notepad*";

  var p = Sys["WaitProcess"]("notepad", 3000);
  if (p["Exists"])
  {
    // Get the Notepad window
    var wndNotepad = p["WaitWindow"]("Notepad", "*", 1, 3000);
    if (wndNotepad["Exists"])
    {
      wndNotepad["MainMenu"]["Click"]("Help|About Notepad");
      // Get the About Notepad window
      var wndAbout = p["WaitWindow"]("#32770", "About Notepad", 1, 3000);
      if (wndAbout["Exists"])
      {
        // Recognize the text that the About Notepad window contains
        var recognizedText = OCR["Recognize"](wndAbout);

        // Get the portion of the recognized text
        var textBlock = recognizedText["BlockByText"](textToGet);
        if (textBlock != null)
        {
          // Get info on bounds of the recognized text portion
          var x = textBlock["Bounds"]["Left"];
          var y = textBlock["Bounds"]["Top"];
          var width = textBlock["Bounds"]["Width"];
          var height = textBlock["Bounds"]["Height"];

          // Post an image of the window area that contains the specified text
          Log["Picture"](wndAbout["Picture"](x, y, width, height), "View the image of the area containing text " + textToGet + " in the Picture panel.");
        }
      }
    }
  }
  else
  {
    Log["Warning"]("Notepad is not running.");
  }
}

See Also

OCRTextBlock Object
Optical Character Recognition

Highlight search results