From the course: Grasshopper and Rhino: Python Scripting

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Defining custom functions

Defining custom functions

From the course: Grasshopper and Rhino: Python Scripting

Start my 1-month free trial

Defining custom functions

- [Instructor] In an earlier class, we learned how to create a list of numbers using the range function. This built-in function takes a number as a parameter and generates a list of sequential numbers based on that parameter. We can also create our own functions if we find we are reusing the same piece of script over and over. Functions are simply chunks of code that perform a specific task that have been wrapped up and named, so we don't need to rewrite the task it performs, we can simply call it by its name. This is how components work in Grasshopper. Each component performs a specific task which can be called and reused. So let's go ahead and create our own functions in Python. Using the random components, I've simply created 100 different random numbers to drive the X and Z coordinates of a point component, creating 100 random points. Let's go ahead and we'll place a new Python component and we'll remove the Y input and change X to points which are a list and type of Point3d. Then…

Contents