Hey everyone,
Today's bite size piece of code is all about determining whether points fall inside a boundary or not. Why you might ask? Well sometimes you just need to modify a selection of points in a layer and a boundary string is a great way to do this.
This code snippet assumes you have point data and a boundary string in the current active layer.
set status [SclSelectPoint bdyPnt "Select Boundary" layer strNum segNum pntNum x y z desc]
if {\\\$status != \\\$SCL_OK} {;#Cancel the macro if user presses escape
puts "Macro Cancelled
return
}
\\\$bdyPnt SclGetParent bdySeg;#Get a handle to the boundary segment
SclGetActiveViewport ViewportHandle;#Get a handle to the viewport
\\\$ViewportHandle SclGetActiveLayer SwaHandle;#Get a handle to the layer
set layerName [\\\$SwaHandle SclGetId];#Store the layer name in layerName variable
\\\$SwaHandle SclGetStrings StringsHandle;#Get a handle to the strings in the layer
\\\$StringsHandle SclIterateFirst StringsIterator;#Setup an iterator to iterate over all strings in the layer
while {[\\\$StringsIterator SclIterateNext StringHandle] == \\\$SCL_TRUE} {
\\\$StringHandle SclIterateFirst StringIterator;#Setup an iterator to iterate over all segments in each string
while {[\\\$StringIterator SclIterateNext SegmentHandle] == \\\$SCL_TRUE} {
if {\\\$SegmentHandle == \\\$bdySeg} {;#If the current segment is the boundary segment then "continue" to the next segment
continue
}
\\\$SegmentHandle SclIterateFirst SegmentIterator
while {[\\\$SegmentIterator SclIterateNext PointHandle] == \\\$SCL_TRUE} {
set x [\\\$PointHandle SclGetValueByName x];#Store the x,y and z value of the current point
set y [\\\$PointHandle SclGetValueByName y]
set z [\\\$PointHandle SclGetValueByName z]
set inside [\\\$bdySeg SclInside \\\$x \\\$y];#Check to see if the current point is inside the boundary
if {\\\$inside == 1} {;#If point is inside boundary do whatever is in between these brackets
puts "Point Found inside the boundary"
\\\$PointHandle SclSetValueByName d1 1;#This macro is just storing "1" in the d1 field of any point inside the boundary
} elseif {\\\$inside == 0 } {
#puts "Point is outside the boundary"
\\\$PointHandle SclSetValueByName d1 0;#If point is not inside boundary, put a 0 in the d1 field.
} elseif {\\\$inside == -1} {
#puts "Point is exactly on the boundary"
\\\$PointHandle SclSetValueByName d1 2;#If point is on the boundary, put a 2 in the d1 field.
}
}
}
}
\\\$SwaHandle SclDraw;#Update the layer
set status [ SclFunction "DRAW DESC" {;#Draw the d1 field to show either 1,2 or 0
frm00089={
{
range1=""
range2=""
range3=""
ifld_num="D1"
textalignment="<"
position="All points"
layer_name="\\\$layerName"
display_object_number=""
display_trisolation_number=""
}
}
}]The final result will be something like below. Hopefully this sparks your imagination for other things you can do with this code. If you need a hand implementing it or have any questions, please leave a comment below.
