Automating Grasshopper Part 4

Course or Collection: 
Video Duration: 
14 minutes
Zach Downey

This tutorial is by request. We add some options to export our models each trip through the loop. We use Rhino's Command line to do the bulk of the work here and pass it parameter options to control the export settings. We export two versions of our file--a Rhino .3dm file and an IGES .igs file. All the source code is posted below. You will also need the Grasshopper definition from Part 3 in this series. Hopefully this workflow is helpful to others as well. We are always open to requests so please don't hesitate to add a comment or shoot us an email on the Contact page.  

#Automating A Tower Massing and Exporting it to separate files
import rhinoscriptsyntax as rs
import Rhino
#Load Grasshopper Plugin as gh
gh = Rhino.RhinoApp.GetPlugInObject("Grasshopper")
#set working directory
workingDir = rs.BrowseForFolder(None, "Pick a foler to save your files in")
#create variable for file naming
num = 0
for i in range(1,3,1):
    #BaseSize Slider
    for j in range(0,4,1):
        #Rotation Slider
        for k in range(3,5,1):
            #NumberOfSides Slider
            baked = gh.BakeDataInObject("72628cf1-020e-425d-9746-6f323f8882f8")
            transVect = (12*i, 12*j, 12*(k-2))
            #convert to string and add filename
            strNum = str(num)
            filename = "myFileTest" + strNum + ".igs"
            #call a bunch of rhino commands to do selection and export
            rs.Command("_SelNone", True)
            rs.Command("_SelLast", True)
            rs.Command("_-Export " + filename + " _Enter", True)
            rs.Command("_SelNone", True)
            #increment the filename
            num = num + 1


Please rate this tutorial below. Thanks.

Average: 5 (6 votes)


Hi, really great tutorial, thank you!! I was wondering if you could add something about baking with specific attributes, like on different layers or with different colors. Generally, how baking can be further customized. Thank you!

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.