> ## Documentation Index
> Fetch the complete documentation index at: https://docs.abbyy.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Blocks

> FlexiLayout blocks map document fields for data capture: review Text, Barcode, Table, and group block types, their properties, and region expressions.

FlexiLayout blocks correspond to fields on the documents from which data must be captured. A block specifies the type of data that the field can contain and the coordinates of the image area where the field is likely to be found.

The blocks branch is marked with <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_tree.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=deeed524eb72bc9b5af0c1fff61eabb1" alt="Tree block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_tree.gif" /> in the FlexiLayout tree.

## FlexiLayout block types

ABBYY FlexiLayout Studio supports the following block types:

| Block type          | Icon                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    | Description                                                                                                                               |
| ------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
| **Text**            | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_text.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=2f5f93810c1a248df472ba326e53399e" alt="Text block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_text.gif" />                                                                                                            | Extracts text data.                                                                                                                       |
| **Barcode**         | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_barcode.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=ebe7e02bd4b709748972b2296c85373b" alt="Barcode block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_barcode.gif" />                                                                                 | Reads barcodes.                                                                                                                           |
| **Checkmark**       | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_checkmark.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=31c276522c85377d8fab2bd8bf20a188" alt="Checkmark block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_checkmark.gif" />                                                               | Recognizes checkmarks.                                                                                                                    |
| **Picture**         | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_picture.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=5ef20c6bac449b68023e5bc9430320ee" alt="Picture block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_picture.gif" />                                                                                 | Processes objects that were not identified as text during pre-recognition.                                                                |
| **Table**           | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/Table_Block.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=b587cb447531d0883066fce4033ae88e" alt="Table block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/Table_Block.gif" />                                                                                                   | Extracts data from tables.                                                                                                                |
| **Group**           | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_group.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=e765a304f828526d23c03274b2dc059c" alt="Group block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_group.gif" />                                                                                                   | Logically groups blocks.                                                                                                                  |
| **Checkmark Group** | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_checkmark_group.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=a1edbbbc4034740745e9706929c4b9d9" alt="Checkmark group block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_checkmark_group.gif" />         | Creates checkmark groups. Only checkmark blocks can be added to this type of group. You cannot create or move blocks of other types here. |
| **Repeating Group** | <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_repeatable_group.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=3dd356ce8d79245d7f86431f6053598a" alt="Repeating Group block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/block_repeatable_group.gif" /> | Creates a repeating group of blocks.                                                                                                      |
| **Non-Recognized**  | <img src="https://mintcdn.com/abbyy/fmgRWFNHKYN2MLSg/images/flexi-capture/fls/Block_Unrecognizable.gif?fit=max&auto=format&n=fmgRWFNHKYN2MLSg&q=85&s=059acd0b3370c31b337a74ca89a51a70" alt="Unrecognizable block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="15" height="15" data-path="images/flexi-capture/fls/Block_Unrecognizable.gif" />                  | Excludes an area from recognition.                                                                                                        |

Expanding the regions of text blocks can improve recognition quality. To expand a region, double-click the **Blocks** element to open its **Properties** dialog box, and then specify the vertical and horizontal values for the **Blocks result region inflate** property.

Blocks for which no image area is specified in at least one layout alternative have an empty square in the top right corner of the icon: <img src="https://mintcdn.com/abbyy/lqYknuOmCa79141v/images/flexi-capture/fls/block_undef.gif?fit=max&auto=format&n=lqYknuOmCa79141v&q=85&s=f7294febb9ed17bdeb883bf35bc71976" alt="Undefined block icon" style={{display:"inline-block",verticalAlign:"middle",margin:0}} width="16" height="15" data-path="images/flexi-capture/fls/block_undef.gif" />.

If only one FlexiLayout is selected (via the **Select Layout** item on the element's shortcut menu, via the same item in the **FlexiLayout** section, or via the **Select Alternative Layout** item on the FlexiLayout's shortcut menu), the program checks for the image area only in this FlexiLayout.

<Note>
  Data from the blocks are extracted in a data capture application such as ABBYY FlexiCapture.
</Note>

## Block properties

A block has the following properties:

| Property                    | Description                                                                                                                                                                                                                                           |
| --------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **Name**                    | The name of the block. It can contain letters (Roman characters, Roman characters with diacritics, Cyrillic characters), digits, and underscores. It must start with a letter or an underscore, and must not contain blank spaces or special symbols. |
| **Type**                    | The type of the block, selected upon creation. It must correspond to the type of object(s) located in the area enclosed by the block.                                                                                                                 |
| **Comment**                 | An optional comment provided by the user.                                                                                                                                                                                                             |
| **Has repeating instances** | Shows that the block consists of several instances. Select this property if, for example, all the instances of a [Repeating Group](/flexi-capture/fls/template/repeatable-group) element are used as the block region.                                |
| **Instance sort order**     | Sets the order in which group instances are united into a block. Available only when **Has repeating instances** is selected.                                                                                                                         |

The **Instance sort order** property has the following values:

| Sort order              | Behavior                                                                                                                                   |
| ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------ |
| **Top to bottom**       | Unites the instances into a block according to their location on the image, top to bottom.                                                 |
| **Left to right**       | Unites the instances into a block according to their location on the image, left to right.                                                 |
| **Right to left**       | Unites the instances into a block according to their location on the image, right to left.                                                 |
| **In order of finding** | Unites the instances into a block in the order in which hypotheses are generated. Hypotheses are generated in order of decreasing quality. |

With **In order of finding**, if you specify additional conditions for instances, hypotheses are generated in the user-defined order. If you need an order different from the standard order used by the program, you can specify it by means of additional conditions.

The following properties specify the area on the image from which data must be extracted.

### For Layout

Selects the layout alternative where the search area is specified.

### Source element

Specifies an area on the image that is identical to the region of the element used to find the block on the image. When the FlexiLayout is applied to the image, the program searches for the object (or objects) described by the element. The data is captured from these objects.

For a repeating group, you can select either one of the instances or use all the instances (`AllInstances`). For more information, see [Use instances of a Repeating Group as reference, excluded, or source elements](/flexi-capture/fls/template/select-repeatable-group).

### Expression

Sets an area on the image that does not coincide with any of the element regions.

For example, you can merge the regions of some elements and the space among them into one block, expand the region of an element by a certain value, or specify the coordinates of the block without relying on any elements. In this case, the region of the block can be described in the [FlexiLayout language](/flexi-capture/fls/code/general-code).

<Note>
  The region of a block is continuous. This means that if you create a region from rectangles that stand apart, the spaces between them are filled by thin additional rectangles to make the region continuous.
</Note>

However, a block can consist of multiple regions if all the instances of a repeating group are used as a reference element. The region of a group block is calculated based on the regions of the child blocks, just like the region of hypotheses. The resulting region is slightly expanded for better viewing.

### Parameters of group and repeating group blocks

A checkmark group and a common group of blocks have no parameters other than **Name** and **Comment**.

The parameters of a repeating group of blocks are the same as those of non-group blocks. The **Has repeating instances** option is always enabled for them.

Child blocks can either have the **Has repeating instances** option or not, but an `OutputInstances` variable is always created for them. If a block inside a repeating group of blocks has the **Has repeating instances** option, this means that it can repeat inside each instance of the parent block.

### Specify a block region using instances of a repeating group

If a block is defined using several instances, the block region consists of several separate regions. If you use a particular instance of a repeating group (for example, `LastFound`), the block region is defined just like for any other element.

However, you can use all the detected instances (`AllInstances`). To use multiple instances, select the **Has repeating instances** option.

You can also write code for the block using the predefined `OutputInstances` variable. For example:

```text theme={null}
OutputInstances = SearchElements.PageHeader.AllInstances.UnionRect;
```

ABBYY FlexiCapture processes blocks with the **Has repeating instances** option enabled as follows:

* For non-table blocks, the specified instances are the instances of the corresponding field.
* For a table block, the specified instances are treated as one instance of the field. That is, ABBYY FlexiCapture processes such a block as a field of type **Table** with a discontinuous region.

### Rules for creating references to elements for repeating groups of blocks

A repeating group of blocks refers to a [repeating element](/flexi-capture/fls/template/repeatable-group). To create instances of a repeating group of blocks, you need several element instances. Therefore, one of the IDs must be `AllInstances`.

Since the elements nested under the element with `AllInstances` cannot have other IDs, this condition also means that the lowermost repeating element has `AllInstances`.

Child blocks of a repeating group of blocks refer to child elements of the repeating group of elements to which the parent block refers. The reference must have the same ID for instances.

For example, if a repeating group block has the reference `SearchElements..RepGr1.Instance(1).RepGr2.AllInstances`, its child blocks can refer to the element `RepGr1..RepGr2.Element` only as follows:

```text theme={null}
SearchElements.RepGr1.Instance(1).RepGr2.AllInstances.Element
```

If there is no `HasRepeatingInstances` attribute, you can only refer to subelements of the basic group that have no repeats inside it, and vice versa.

If there is a `HasRepeatingInstances` attribute, you can refer to elements that have repeats inside the basic group (and you can only refer to all the instances at once).

```text With a HasRepeatingInstances attribute theme={null}
SearchElements.RepGr1.Instance(1).RepGr2.AllInstances.RepGr3.AllInstances.Element
SearchElements.RepGr1.Instance(1).RepGr2.AllInstances.RepGr3.AllInstances.RepGr4.AllInstances.Element
```

```text Without a HasRepeatingInstances attribute theme={null}
SearchElements.RepGr1.Instance(1).RepGr2.AllInstances.Gr3.SubElement(where Gr3 is a simple group)
SearchElements.RepGr1.Instance(1).RepGr2.AllInstances.SubElement
```

<Note>
  If references are created via **Source element**, the check is performed when the FlexiLayout is built. If references are created using Advanced code, an error is detected when matching the FlexiLayout.
</Note>

### Describe a block region with the FlexiLayout language

To specify the region of a block, use the **Expression** field.

The predefined variable used depends on the type of the block and whether the **Has repeating instances** option is selected for it:

| Variable          | Type                                                |
| ----------------- | --------------------------------------------------- |
| `OutputRegion`    | `Region`                                            |
| `OutputTable`     | `TableHypothesis`                                   |
| `OutputInstances` | `HypothesisInstances` or `TableHypothesisInstances` |

For more information about the predefined variables that can be used in the **Expression** field, see [Predefined variables](/flexi-capture/fls/language/predefined-variables).

| Task                                                                                                                                                   | Example code                                                                                                                                   |
| ------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| Get and expand the region of an element by 3 mm in width and 5 mm in length                                                                            | `OutputRegion = SomeElement.Rect;   OutputRegion.Inflate( 3*mm, 5*mm );`                                                                       |
| Merge the region rectangles of two elements and get the rectangle that circumscribes the merged rectangles                                             | `Rect outputRect;   outputRect = Element1.Rect Or Element2.Rect;   OutputRegion = outputRect;`                                                 |
| Merge the rectangles circumscribing the regions of two elements into one region                                                                        | `RectArray outputRects;   outputRects = RectArray( Element1.Rect );   outputRects.Add: Element2.Rect;   OutputRegion = Region( outputRects );` |
| Merge the regions of the objects corresponding to two different elements into one region                                                               | `RectArray outputRects;   outputRects = Element1.Rects;   outputRects.Add( Element2.Rects );   OutputRegion = outputRects.Region;`             |
| Merge the regions of the objects that belong to the region of `Element1` and remove the regions of the objects that belong to the region of `Element2` | `OutputRegion = FormRegion( Element1.Rects, Element2.Rects );`                                                                                 |
| Use a **Table** element to specify a **Table** block                                                                                                   | `OutputTable = SearchElements.TableElement;`                                                                                                   |
| Use instances of hypotheses for a certain element to specify a **Table** block                                                                         | `OutputInstances = SearchElements.RepeatingGroup.AllInstances.TemplateElement;`                                                                |

## Use the IsNull variable

You can also use a predefined `IsNull` variable to describe the region of a block. This variable signals whether the region of the block has been found when matching the FlexiLayout. The value `false` means the region has been found. The value `true` means it has not been found.

The `IsNull` variable is initialized with the value `false`, so the region of the block is considered to be found. However, sometimes you might need to check certain conditions before reaching a conclusion.

To tell the program to consider the region of the block found if the width of the region of the source element exceeds 50 dots, enter the following code in the **Region Expression** field:

```text theme={null}
if Element1.Width < 50dt then IsNull = true;
```

To tell the program to consider the region of the block found only if `Element1` has been found, enter the following code in the **Region Expression** field:

```text theme={null}
IsNull = Element1.IsNull
```

Suppose you need to use `Element1` and `Element2` to look for a block. If at least one of the elements has not been found, the block is considered not found:

```text theme={null}
Rect outputRect;
Let FieldLeft = Element1.Rect.Left;
Let FieldRight = Element2.Rect.Right;
Let FieldTop = Element1.Rect.Top;
Let FieldBottom = Element2.Rect.Bottom;
outputRect = Rect( FieldLeft, FieldTop, FieldRight, FieldBottom);
if ((Element1.IsNull == True) or (Element2.IsNull == True) ) then {IsNull = true;}
OutputRegion = outputRect;
```

<Note>
  This code works correctly only if the search area of `Element1` is above and to the left of the search area of `Element2`.

  In the preceding example, this condition is not checked, for the sake of simplicity. In actual code, this check is required, and the values of the `FieldLeft`, `FieldRight`, `FieldTop`, and `FieldBottom` variables must be adjusted. Otherwise, calling the `Rect` function returns an error.
</Note>
