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
From the course: Grasshopper and Rhino: Python Scripting
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Variables6m 23s
-
(Locked)
Numbers7m 36s
-
(Locked)
Strings9m 16s
-
(Locked)
Lists and tuples9m 25s
-
(Locked)
Comparing with operators6m 23s
-
(Locked)
Making decisions with conditionals7m 48s
-
(Locked)
Comparing Booleans8m 42s
-
(Locked)
For loop7m 52s
-
(Locked)
While loop8m 43s
-
(Locked)
Nested loops5m 38s
-
(Locked)
Defining custom functions9m 45s
-
-
-
-