In this session we get our first hands-on experience working with Python in Grasshopper
In this session we will get hands-on practice with Python in Grasshopper using the Python
component and the Rhino.Geometry
library.
Python bootcamp | |
---|---|
1 | Intro to Python |
2 | Elements of Python |
In this demo, we get our first hands-on experience working with Python in Grasshopper. As a starting point, we look at how to input data from Grasshopper into a Python script running within a Python
component, and how to handle geometric inputs. We also look at how to output data from Python back to the Grasshopper canvas.
In this lesson, we look at how we can create geometry in Python using the Rhino.Geometry library. We first import the library using an import
statement and then create a circle using a point input from Grasshopper as its center.
In this lesson, we extend our script to accommodate multiple points from Grasshopper. We look at how we can work with lists in Python, and how to iterate over the objects in a list using a loop.
In the final lesson of the session, we finish our script by adding the ability to control the radius of each circle in the grid based on the distance of each point to another point called the 'attractor'. We first calculate the radius directly from the distance and then use a set of conditional statements to set the radius directly based on the distance meeting certain criteria.
For more introductory text-based tutorials covering the basic functionalities of Python, make sure to check out the tutorials included in the https://medium.com/generative-design course on Medium:
If you are new to Python you should also check the Beginner's Guide on the Python webpage.
You can find full documentation of the RhinoCommon library (including the Geometry module we use in the class) in the documentation: https://developer.rhino3d.com/api/RhinoCommon