# Script Block Examples – Red Analyze

With the References added, you are ready to write the code that will access the data in the 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;

Here is the another sample script for Red Analysis.

var redMarkings = $Tasks.Task.DeepLearningRuntimeBlock.Sample.Markings["Analyze"] as IRedMarking;

var score = redMarkings.Views.First().Score;

var threshold = redMarkings.Views.First().Threshold.Lower;

var passBit = 0;

if (score < threshold)

{

passBit = 1;

}

return passBit;

- Convert Runtime Block's Sample object to an IRedMarking.
var redMarkings = $Tasks.Task.DeepLearningRuntimeBlock.Sample.Markings["Analyze"] as IRedMarking;
- Get the score for the current image.
var score = redMarkings.Views.First().Score;
- Get the Threshold from the Runtime Tool.
var threshold = redMarkings.Views.First().Threshold.Lower;
- Intialize a passBit and set it 0.
var passBit = 0;
- If the score of the current image is below the threshold, set pass bit to 1.
if (score < threshold)
{
passBit = 1;
}
- Return the passBit to the Task Level.
return passBit;