You are now going to create an action that uses the reusable function. This action automatically scans the current shape for geometrical sets. Each geometrical set will be processed if it contains three points: If the three points are not aligned, a triangle will be drawn on these points. If the points are aligned, they will be colored red.
Click Play to watch the video:
In the Engineering Rules Capture section, click
Action
.
Create the script.
Use the Include keyword to call the library and declare the
variables you want to use in the script.
Include "GeometricalLib" // For the AreAligned function
let allSets(List)
let currentSet(OpenBodyFeature)
let pointsInSet(List)
let p1,p2,p3(Point)
let currentLine(Line)
let linesGeoSet(OpenBodyFeature)
let i(Integer)
allSets = `TrianglesShape ---.000` ->Query("OpenBodyFeature","")
for currentSet inside allSets
{
// In each Geometrical Set, we search for points
pointsInSet = currentSet->Query("Point","")
if pointsInSet.Size() == 3
{
Call the reusable function if there are three points in the geometrical set. If the
points are aligned, they are colored red, if not, a triangle is created.
// If there are three points
p1 = pointsInSet[1]
p2 = pointsInSet[2]
p3 = pointsInSet[3]
// Use of a reusable function to check if the points are aligned
if GeometricalLib::AreAligned(p1,p2,p3) == TRUE
{
// They are not, we color them in red
p1.Color = "Red"
p2.Color = "Red"
p3.Color = "Red"
}
else
{
// They are, we build lines between them
currentLine = new("Line","LineA"+i,linesGeoSet)
currentLine = line(p1,p2)
currentLine = new("Line","LineB"+i,linesGeoSet)
currentLine = line(p1,p3)
currentLine = new("Line","LineC"+i,linesGeoSet)
currentLine = line(p2,p3)
i = i + 1
}
}
}