Chapter 2 Command Scripting

Writing Scripts That Build Models

One of the ultimate goals of Commandscripting is the creation of a complete model from a script. Besides the benefit of creating a model at the click of a mouse button, scripts that build models can also function as a parametric command history. This makes it easy to change dimensions in your script and see the changes reflect in your model. Although it is not true parametric modeling it gives a certain amount of parametric control that is now missing in Rhino.

By now you have a command over how to perform basic modeling functions in Rhino. You know the proper syntax of the scripting language. You have customized your workspace. You understand the 3 ways to run a command script and their differences. Below are outlined the basic steps to go from a concept model to a working and reliable commandscript.

The general steps for taking a concept model to a working commandscript.

1. Gather the information the dimensions and plans for the model you are building.
2. Build the model in Rhino.
3. Analyze and break the modeling process you used down into its basic components and steps it took to build the model.
4. Write a commandscript based on that analysis in notepad or any text editor making sure to save your script as a text file. For these tutorials I only used notepad since it takes up little resources to run, automatically saves files as text files and more importantly you only need Rhino and windows to write commandscripts.
5. Using commandpaste in Rhino run your commandscript to see how it runs. If it doesn't work use commandhistory to find out why it didn't.
6. Save your error free and working commandscript in a common folder where you place your scripts. You may also want to assign it to an icon or hotkey if it is an often-used script.
7. If you created new custom icons with commandscripts assigned to them. Save your workspace by typing savews at the Rhino command prompt. This way you won't loose your last created icons if you crash your computer.

In order for you to grasp a hold of the process I will take you through a simplified case study of writing a commandscript that creates a model of a very simple Block manifold. I explain how to apply the general steps of going from concept model to a working commandscript, the syntax of the commandscript line by line, how to use the command script as a lowly form of parametric commandhistory and as a record to track changes.

Creating a manifold block: A simplified case study
Writing the Script
Creating the Circle Cutout
Selecting and moving the Circle
Extruding the Profile Curves
Test the Commandscript
Editing the Commandscript