# Create Loops in Spreadsheet

For certain applications, it can be necessary to repeat the actions of some functions several times during a single acquisition and job execution. To achieve this, you can construct jobs using a loop of cells.

You can use the following Clocked Data Storage functions to create cell loops and manage their output:

- Repeat

- RepeatUntil

- StoreData

- PlotData

The Repeat and RepeatUntil functions specify the range of cells in the loop and the number of repetitions. The RepeatUntil function also allows you to specify an exit condition for the loop to end before the specified maximum number of repetitions.

The StoreData function allows you to collect the data for each repetition in the loop. The PlotData function plots the graphics for each stored Data structure.

## Example

In this example, the task is to inspect pin connections for the proper height tolerance. The job contains functions that locate the position of the pins and count the number of pin connectors. Each pin connector needs to be measured to verify that it is within the specified tolerance. Instead of creating individual functions for measuring each pin connector, you can create a loop of cells to simplify the Spreadsheet job.

1. Set up image acquisition or load your existing set of images into the Filmstrip.

2. Add an FindBlobs function to your job to locate the pin connectors. Fine-tune the function parameters until you get accurate results.

3. Add a SortBlobs function to your job referencing the Blobs data structure in the output of your FindBlobs function. The SortBlobs function allows you to define a fixture, and sorts the blobs that are found by the FindBlobs function based on their distance from the defined fixture.

4. Add a Caliper function to your job to measure the height of the pin connectors.

   1. Set the Fixture as a cell reference to the SortBlobs function output for the pixel coordinates of the pin connector.

   2. Set the Edge Mode parameter to Edge Pair, with the first edge being the top side of the pin connector, and the second edge being the bottom side of the pin connector, and set the Edge Distance to the maximum allowable height.

5. Construct the logic for determining whether the pin connector is within the height tolerances.

   1. Add an EditInt control to define the minimum and maximum acceptable height values.

   2. Add a GetEdgeDistance function for the Caliper function to extract the distance between the found edges. For more information about GetEdgeDistance, see Edges Vision Data Access functions.

   3. Add an InRange function for the GetEdgeDistance function to determine whether or not the distance between the edges is within the range defined by the EditInt function. For more information about InRange, see Logic.

   4. Add a PlotLine function for the Caliper function to draw the found edges.

6. Construct the repeating loop to automate the inspection process for every pin connector.

   1. Add a StoreData function for the PlotLine function to collect the outputs for each pin connector.
      Set the Number of Steps parameter as a cell reference to the GetNFound output cell of the FindBlobs function.

   2. Add a Repeat function to set up the loop of cells to execute.
      Set the Event parameter to the Image data structure in cell to trigger the Repeat function on every acquisition.
      Set the Iterations to Repeat parameter as a cell reference to the GetNFound output cell of the FindBlobs function.

   3. Specify the cells you want to include in the loop with the Cells to Repeat parameter. Make sure to include the cells containing the Caliper, GetEdgeDistance, InRange, PlotLine, and StoreData functions in the specified range of cells.

   4. Add a GetLoopCount function to keep count of the number of repetitions and determine which indexed pin connector is being inspected. For more information on GetLoopCount, see Clocked Data Storage Vision Data Access functions.

   5. Edit the Caliper function you added in step 4, and modify the Fixture parameter to reference both the cell containing the SortBlobs pixel coordinates output, and the cell containing the GetLoopCount function.

7. Add a PlotData function for the StoreData function to draw graphics for each stored Data structure.

As a result of the above steps, your job can now inspect every pin connector, and produce graphics and tolerance metrics for each result. You can configure an EasyView or a Custom View for your WebHMI to display the InRange for determining whether a result is within the defined tolerance, and show PlotLine graphics for the found edges.