Intro to Python Scripting: 14 Not So Simple Recursion

Video Duration: 
12 minutes
Zach Downey

In this tutorial we cover another Recursion example. This one is a bit more complicated than the last one. This one uses a reallycool trick in python to manipulate all values in a list by a number. Check the code below, but the syntax in this example is  scaleVect = [ x - sc for x in scaleVect] Very cool. 

import rhinoscriptsyntax as rs
def RecursiveScale(objID,scalePt,scaleFact, scaleVect, num):
    if num == 0:
        return 0
        sc = (1.0 / scaleFact)
        scaleVect = [x - sc for x in scaleVect]
        rs.ScaleObject(objID, scalePt, scaleVect, True)
        return RecursiveScale(objID, scalePt, scaleFact, scaleVect, num-1)
objID = rs.GetObject()
scalePt = rs.GetPoint("Pick Scale Center")
scaleFact = rs.GetReal("Enter a scale Factor", 10, 0)
scaleVect = [1.0, 1.0, 1.0]
num = rs.GetInteger("Enter a the number of iterations", 10, 1)
RecursiveScale(objID, scalePt, scaleFact, scaleVect, num)


Please rate this tutorial below. Thanks.

Average: 5 (14 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.