In today's bite sized code snippet, I'm taking another look at nested for loops. I'll use a few SCL commands to create points at x and y values that will be determined by the nested for loop.
These types of loops have many applications so this code should serve as a good basis for any other scripts you might want to create. As always, the macro (and styles file) are zipped up and available to download at the bottom of the post.
My notes are Bold and Italicized in the script, and if you have any questions, please comment below.
#Procedure to create a point proc newPoint {segmentHandle x y z} { \$segmentHandle SclCreatePoint pointHandle [\$segmentHandle SclCountItems] \$pointHandle SclSetValueByName X \$x \$pointHandle SclSetValueByName Y \$y \$pointHandle SclSetValueByName Z \$z return \$pointHandle } #Procedure to load a styles file for viewing the created data proc loadStyles {} { set status [ SclFunction "STYLES LOAD" { frm00192={ { style_file="forloop.ssi" } } }] } #A couple of variables to dictate the x and y grid size. Experiment by changing the values. set xUpper 30 set yUpper 10 #Code to create a new layer "Nested for loops" and make it visible to the user. SclGetActiveViewport ViewportHandle SclCreateSwa SwaHandle "Nested for loops" sclGraphicsLayers SclAdd \$SwaHandle \$ViewportHandle \$ViewportHandle SclSetActiveLayer \$SwaHandle loadStyles;# Run the load styles procedure set strNum 1;# Variable to change the string number for every point for {set x 0} {\$x < \$xUpper} {incr x} {;# for loop to create the x value, starting at 0 SclPause 0.1 \$SwaHandle SclDraw set status [ SclFunction "ZOOM ALL" {} ] for {set y 0} {\$y < \$yUpper} {incr y} {;# for loop to create the y value for every x value. (Nested for loop) \$SwaHandle SclCreateString stringH \$strNum;# Create the new string \$stringH SclCreateSegment segmentH [\$stringH SclCountItems];# Create the new segment for the new string newPoint \$segmentH "\$x" "\$y" "0";# Run the newPoint procedure to create the point at the x, y and z value listed incr strNum;# Increment the string number } } #Draw all the points and zoom all to see everything \$SwaHandle SclDraw set status [ SclFunction "ZOOM ALL" {} ] puts "Macro to demonstrate nested for loops is complete."