Intro to Python Scripting: 06 Nested For Loops and Functions

Software: 
Tag: 
Video Duration: 
9 minutes
Author: 
Zach Downey

In this tutorial we look at nested loops and create our own function to create a point with color. We have three different nested loops that we iterate over and add color points to our Rhino document. We also use the EnableRedraw() and Redraw() functions to disable the view regeneration, which speeds up the the script quite a bit.

#Nested For Loops
#color points
import rhinoscriptsyntax as rs
 
 
def createColoredPoint(x,y,z,r,g,b):
    currentColor = [r,g,b]
    pt = rs.AddPoint(x,y,z)
    rs.ObjectColor(pt, currentColor)
 
 
rs.EnableRedraw(False)
step = 10
 
for x in range(0,256, step):
    for y in range(0,256, step):
        for z in range(0,256,step):
            createColoredPoint(x,y,z,x,y,z)
rs.Redraw()

Rating

Please rate this tutorial below. Thanks.

5
Average: 4.9 (7 votes)

Want to Contribute?

Want to be an author? Drop us a line here we'd love to have you.

Already have a video you'd like to post? Send us a link and we'll get you going.

:)