This series of guides and exercises introduce the programming language Python and demonstrate how it can be used within the Grasshopper environment.
Grasshopper, despite being a great platform for algorithmic design, can also be limiting when trying to incorporate more complex programming elements. On the other hand, programming directly with computer code in a programming language like Python gives us much more control over our algorithms and allows us to develop more complex and interesting solutions but has a much higher learning curve and can be quite intimidating when first starting out.
So how do we choose one over the other? Luckily we don’t have to! In fact we can easily extend the basic functionality of Grasshopper with Python code by embedding it directly into special
Python components that can then interact with other components in our definition. This allows us to rely mostly on Grasshopper for basic elements, and use code only when necessary for more complex functionality.
Python is only one of many languages around today — so why should we choose to work with Python?
On its own merit, Python has many benefits: it is a general-purpose high-level programming language with many features such as object-oriented programming which you would expect from a modern programming language. Although Python has been around for a while, in recent years it has become extremely popular in a variety of fields outside of computer programming such as science, medicine, statistics, math, and machine learning. This popularity can be attributed to Python's:
- Relatively simple syntax, with a focus on simplicity, clarity, and readability which makes it less complicated to learn and write
- Extensibility through a large collection of external libraries
- A huge support community of active users
Unlike more complex languages such as C++ or Java, Python is not often used for full software development. Because of it's emphasis on ease of use, it also tends to be less efficient and somewhat slower than these languages, but this is usually not an issue for applications outside of software development.
Lately, many different design software have begun adopting Python as a scripting language. This includes ArcGIS, QGIS, Rhino, Solidworks, and Autodesk Fusion, and is a big change from earlier years when every design tool had it's own proprietary scripting language (Rhinoscript for Rhino, EKL for Catia, Actionscript for Illustrator), so you had to learn a whole new language each time you used a new tool. Integrating Python as a standard scripting language allows designers to learn a single language and use it to control a variety of design software. So if you are not a programmer but want to learn one programming language that will give you the most use in your design career, there is a strong argument that the language should be Python.
¶What Will You Learn?
In this introductory guide, you'll get your first hands-on experience with the programming language Python and learn:
- Running Python: How to access Python from within the Rhino/Grasshopper environment.
- Working with data: The core data structures used in Python.
- Working with geometry: How to access the Rhino API's through a set of libraries which expose Rhino's underlying geometric classes and functionalities.
- Learn by doing: Work through a set of exerices to test your knowledge of basic Python concepts.
¶Upcoming tutorials in this series
This series will teach you Python starting with the basics and assuming no prior experience. Being one of the most popular programming languages in use today, Python is used in different ways across different industries. In these tutorials we focus on the use of Python as a sripting language to automate geometric operations within Grasshopper using Rhino's underlying geometry API's. By the end of this series you will have a solid grounding in Python and be ready to start learning the Python fundamentals in later tutorials.
|Getting started with Python|
|1||Intro to Python|
|2||Exercise: Working with the Rhino API|
|3||Working with data in Python|
Note: This series is focused on using Python within the Grasshopper environment. If you are running Python in a different context but would still like to go through the basics, you should skip ahead to the last guide of this series which will cover variables, lists, and dictionary data structures, and then proceed to the next series on Imperative programming in Python.