# Write the Script to Access the Data

With the References added, you are ready to write the code that will access the data in the ViDi Tool Block. This topic contains sample code that stores the center of the first defect region in the $result.X1 and $result.Y1 tags.

    var view = ViDiSubTask_Analyze_Marking.Views[0];
    {
        $result.Count = view.Regions.Count;

        if ($result.Count >= 1)
        {
            var region = view.Regions[0];
            var centerPoint = view.Pose.Transform(region.Center);
            var x = centerPoint.X;
            var y = centerPoint.Y;
            var Area1 = region.Area;

            $result.X1 = x;
            $result.Y1 = y;
            $result.Area1 = region.Area;
        }
    }

In this script, the following explains the calls of the specific information that the script is accessing:

- Returning the number of markings:

      $result.Count = view.Regions.Count;

- Choosing the region:

      var region = view.Regions[0];

- Return the center-point (X, Y) of the region:

      var centerPoint = view.Pose.Transform(region.Center);
      var x = centerPoint.X;
      var y = centerPoint.Y;

- Return the area of the region:

      var Area1 = region.Area;

- Write the variables to the tags:

      $result.X1 =x;
      $result.Y1 =y;
      $result.Area1 = region.Area;

Note: This script references the IRegion Interface API. For additional information about the IRegion Interface API, refer to the Cognex ViDi Suite .NET Library help documentation.