You’ve just opened the first edition of the Rhino Python primer. This guide was originally written by David Rutten for Rhino 4 and VBscript and has now been translated to encompass Python for Rhino 6. As always, this primer is intended to teach programming to absolute beginners, people who have tinkered with programming a bit or expert programmers looking for a quick introduction to the methods in Rhino. Rhinoscript (VBscript) has been supported for many years, with a large user group and extensive support material. As well as giving a basic introduction, this primer looks to easily transition those familiar with VBscript into the world of Rhino Python. For this reason, David Rutten’s original primer has been used extensively as the underlying framework for this Python Primer. Python offers exciting new potentials for programming in Rhino with Object-Oriented functionality, simple syntax, access to the .NET framework and a vast number of user-built libraries to extend Rhino’s functionality. The same powerful methods that were previously in VBscript are still available, as well as a ton of other exciting methods and features available natively with Python.
Similar to the previous primers, we have the advantage of using geometric and visual examples to help teach programming. In many traditional scenarios, programming is taught with non-visual examples and difficult to understand engineering problems. For this reason, as well as Python’s easy-to-read syntax, we should hopefully be able to bring everyone to understand and write simple programs to help automate and design within Rhino.
Programming offers users the powerful ability to automate tasks, make decisions, perform powerful calculations and geometric manipulations, thus, essentially acting as a designer’s side kick. This can allow thousands of computations to occur based on dynamic conditions, something that would take a human far too long to process. As a tool for iteration, generation, analysis and design evolution, programming is limitless! Programming also offers a new language to communicate with the world because almost every discipline, from the Sciences, Engineering to Art, utilize code as a progressive new medium - and this primer should hopefully give you an easy introduction into this powerful language for communicating with the world. (With that example, it should be noted that programming may be looked at as any other human language in the sense that it truly takes many hours of practice to become fluent. So don’t get discouraged if you aren’t an expert in one day!)
I hope we have convinced you of the powerful and exciting potential for this new opportunity of Python in Rhino. Without further ado, lets dive in!
Good luck!
Robert McNeel & Associates
A special thanks to David Rutten for the inspiration and invaluable work, pioneering the original RhinoScript 101 Primer. Also many thanks to Bob McNeel and everyone at Robert McNeel & Associates for their generous support!
Download the Rhino.Python 101 Primer as a single PDF
Table of Contents
1. What’s it all about?
1.1 Macros
1.2 Scripts
1.3 Running Scripts
2. Python Essentials
2.1 Language Origin
2.2 Flow Control
2.3 Variable Data
2.3.1 Integers and Doubles
2.3.2 Booleans
2.3.3 Strings
2.3.4 None Variable
2.3.5 Using Variables
3. Script Anatomy
3.1 Programming in Rhino
3.2 The Bones
3.3 The Buts
3.4 The Skin
3.5 The Debugger
4. Operators and Functions
4.1 What on Earth are they and why should I care?
4.2 Careful…
4.3 Logical Operators
4.4 Functions and Procedures
4.4.1 A Simple Function Example
4.4.2 Advanced Function Syntax
4.5 Mutability
5. Conditional Execution
5.1 What if?
5.2 Looping
5.3 Conditional Loops
5.4 Incremental Loops
6. Tuples, Lists, and Dictionaries
6.1 Tuples
6.2 Lists
6.2.1 List Comprehensions
6.3 Dictionaries
6.4 Points and Vectors
6.5 An AddVector() Example
6.6 Nested Lists
7. Classes
7.1 Class Syntax
8. Geometry
8.1 The openNURBS™ Kernel
8.2 Objects in Rhino
8.3 Points and Pointclouds
8.4 Lines and Polylines
8.5 Planes
8.6 Circles, Ellipses, and Arcs
8.6.1 Ellipses
8.6.2 Arcs
8.7 NURBS Curves
8.7.1 Control-Point Curves
8.7.2 Interpolated Curves
8.7.3 Geometric Curve Properties
8.8 Meshes
8.8.1 Geometry vs. Topology
8.8.1 Shape vs. Image
8.9 Surfaces
8.9.1 NURBS Surfaces
8.9.2 Surface Curvature
8.9.3 Vector And Tensor Spaces