Updated 10 Aug 2003

Latest Updates

Face Tool and Scripting

Latest Tutorial

Rhino has a handy feature called ‘Scripting’ where a series of commands can be saved and run. This is ideal for repetitive sequences or special purpose functions. Rhino has some powerful mesh tools, but as a NURBS modeller these are secondary to the main curve, surface and solid tools. We are using a NURBS model to generate the mesh models we need for our digital model. This could be done entirely using the various ‘mesh from model’ tools already in the Rhino toolbox, but some fine control over polygon formation would be useful. We will now script such a tool, then make a new button on the Rhino workspace and apply the script.

1.   Start Rhino using the feet and inches template we made in the Rhino Set-up tutorial. Look above the main toolbar and you will see the Command Line interface. The upper section echos the commands and inputs, while the lower single line is where prompts and requests for input are displayed. Click on any button and you will see the script command for that button appear in the upper section.

We want to create polygons for our meshes using our Rhino model as a guide. Rhino has a polygon tool ( called 3-D Face in Rhino)  and it is in the Mesh tool fly-out. We could use this tool in combination with the On Surface snap command, but this would have to be selected for every point for every polygon. The sequence would be something like:-

3-D Face command, On Surface Snap command, Select surface, select point, On Surface Snap command, Select surface, select point, On Surface Snap command, Select surface, select point, On Surface Snap command, Select surface, select point, enter

If you had to do that sequence as a series of mouse clicks, it would become very tedious indeed!

Rhino Polygon creation tool on the mesh tools fly-out.

2.   Have a look at ‘Scripting’ in the Rhino help files. We can save just this sequence as a script. However, at the stages where we selected the surface and points in the sequence above, we need to interrupt the script so that we can select the surface and location of the point we want. The script command for this interruption is ‘Pause’. We also need to know what the script commands are for 3-D Face and On Surface snap. We can either look them up ( or some of them, not all seem to be listed!) in the Help/Command List, or simply click on the appropriate button or menu item and watch the Command line where it will be echoed.

View of Command line area after 3-D Face button has been clicked.

3.   The image on the left shows the 3-D Face button has been clicked, the command ‘3DFace’ (note this is not case-sensitive) is in the command line, and the Prompt for the first corner of the polygon is already in the prompt line. Before I select the first point, I select On Surface from the Tools/Object Snap menu, and the command line looks like this one on the right....

View of Command line area after Snap On Surface command has been clicked.

4.   So we can see the script command for the On Surface snap is ‘OnSrf’ .  From the Help files we find out that the script equivilent of hitting enter, to finish a command, is simply ‘Enter’, and that ‘!’ at the beginning of a script cancels any current, unfinished command. We have enough for a script!

! 3DFace OnSrf      Pause      Pause      OnSrf      Pause      Pause      OnSrf      Pause      Pause      OnSrf      Pause      Pause     

5.   This script will cancel the previous command, start the 3-D Face command, switch on the snap to surface command, then pause to allow you to select the surface on which you wish to select your first point. Then it pauses again to select the actual point. This is repeated for the 2nd, 3rd and 4th points . This immediately finishes the 3-D Face command as it was expecting  4 points, and creates the 4-sided polygon. No need for an ‘Enter’ to finish the command, in other words!

6.   The script on the right will do a very similar job, but you can see it only has 3 cycles selecting surfaces and points, then the ‘Enter’ command finishes it at that point. This script will therefore produce a triangle rather than a 4-sided polygon.

! 3DFace OnSrf      Pause      Pause      OnSrf      Pause      Pause      OnSrf      Pause      Pause      Enter

7.   We could run these scripts from the script plug-in, or even pasteing them into the command line, but that is almost as clumsy as the original sequence of commands selected from the menus. Rhino has a much neater way of implimenting special commands such as this, and that is to make a new button and attach our scripts to it.

8.   Open the Toolbars Layout... dialog box from the Tools menu (outlined in red), scroll down and highlight the Main toolbar listing. It should be checked already.This is the toolbar usually down the left side of the Rhino workspace; you might have moved it elsewhere of course! From the Toolbar menu click on Add Button... and when you let go your mouse button a new, blank button will appear at the bottom of the toolbar.

9.   Shift-RIGHT-click on your new button and the Edit Toolbar Button dialog box will appear. Here  we can enter the script commands by just typing them in as in the image. You can see there are seperate script boxes for the left and right mouse buttons, so we can put our 4-sided polygon script under one button, 3-sided one under the other. The Tooltip box provides the text for the hint that appears if you place the cursor over the button for a few seconds. You can make your button part of a linked toolbar by selecting from the drop-down menu, and finally you can edit the 24x24 bitmap that gives the button its image. Here is one I prepared earlier.... Download and import into the Button Bitmap Editor if you wish.

Edit Toolbar Button dialog box showing script text entered (partially) under left and right mouse button areas.
Toolbar dialog box showing Add Button.... command highlighted,  and location of the new button created.

10. Finally, test your button! Create a surface in Rhino. Click on your new button and look at the command line. It will be asking you to click near the surface. Click. Click again to mark the first point. Click again to select the same surface, click again for the second point, and so on until the fourth point is clicked, and Bingo! a polygon with all its vertices exactly on your NURBS  surface. You will quickly learn to click the button, double-click, double-click, double-click, double-click, done!

A big thank you to the guys on the Rhino Users Newsgroup, in particular Mitch, who helped us greatly with this tool. If you have any questions about Rhino, this newsgroup would be an excellent place to ask them. Click here to find them.