Drawing Shapes Using Code

2m 31s

In this course, David Tracy will teach you how to use the Python programming language with Rhino to automate tasks, create complex forms, and simulate physical phenomena. This course will serve as a gentle introduction to programming to unlock capabilities for generative computational design with Rhino, Python, and Grasshopper.

First, you will be introduced to the core concepts of using Python in Rhino, such as drawing shapes with code, transformation, and variables. Then you will learn how to use classes and object oriented programming. Finally, you will learn how to integrate Grasshopper into your Python and Rhino workflow.

When we’re done, you will understand the core concepts of programming with Python, be able to author your own scripts, and create custom components in Grasshopper.

Those were a couple of quick ways to get curves and lines drawn. Let's un-comment this. So, I'm just going to add a line, a comment here, this creates a line. This prompts a user for points and generates a curve. Okay, so we created a line, we created a curve and you saw in the last example, you can create primitive shapes in a very similar way.

So, if we wanted to create a circle, we do R S add circle and it asks us for the plane at the center point of the circle, so we'll hard code the coordinate in there and we'll specify a radius of 25. So when we run this, our code is executed from top to bottom.

So, the first thing it did was it added that line. It prompted me for some points to pass as an argument for add curve and then it ran this, add circle function with a base point at the origin and a radius of 25. So, just like with the circle function in Rhino, there are multiple ways to draw a circle. You can have a radius based approach, you can also use a three point approach, but we can create other shapes too, like a rectangle.

Add rectangle and this is again this is going to prompt us for a plane, a width and a height and then it will create a rectangle for us. So, the first thing we're going to do is, we're going to set the base plane, we're going to set the width and we're going to set the height.

And then we'll just run this thing. Okay, so what that did was it ran through all of our methods, so it added the line, it added the curve, it added the circle and then it created our rectangle at this base plane, zero, zero, zero with a width of 25 and a height of 50.

Log in to access files

From the course:
Introduction To Python In Rhino

Level 1

Duration: 3h 23m

Author: David Tracy