This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Previous revision Next revision Both sides next revision | ||
rhino:basicmacros [2019/08/28] |
rhino:basicmacros [2021/05/06] mitch_heynick [Getting started] |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Creating Macros====== | ||
+ | |||
+ | >A basic tutorial on creating macros (scripting together Rhino commands) | ||
+ | |||
+ | You can create **macros** in Rhino to automate many tasks, customize your commands, and improve your workflow. | ||
+ | |||
+ | There may be some confusion about the use of the term “scripting”. | ||
+ | |||
+ | //The two things are actually very different.// | ||
+ | |||
+ | I use the term “Macro” here exclusively to describe the putting together of strings of ordinary Rhino commands and their options to create an automated function. | ||
+ | |||
+ | |||
+ | =====The tools you need===== | ||
+ | * Your brain :-P | ||
+ | * The **Rhino Help file** - lists all Rhino commands and their sub-options. This is your most important reference. | ||
+ | * The Rhino **MacroEditor**, | ||
+ | * An understanding of how to add your macros to your workflow in the form of aliases or toolbar buttons (explained [[developer: | ||
+ | =====You' | ||
+ | First, if you are a user of Rhino, you are already a macro user even though you may not know it. Many of the commands in Rhino are already “macroed” for you. When you click a toolbar button or call a command from the menu, it is often a preset macro. | ||
+ | //(shown: V6 for Windows)// | ||
+ | |||
+ | {{: | ||
+ | |||
+ | It just calls the **ExtrudeCrv** command and sets it to make a closed solid. | ||
+ | |||
+ | This is an example of the simplest kind of macro, which just sets a series of options within a single command so that you don’t have to specify them time you use it. **ExtrudeCrv** has several buttons with preset options, **Tapered, AlongCurve, ToPoint, Solid=Yes** (or No) etc. Check out the macros under all the **ExtrudeCrv** buttons to see how they are laid out. | ||
+ | |||
+ | In a sense, you’re doing the same thing as if you clicked or typed the options one at a time at the command line. In fact, that’s all macros really are -- just a set of instructions to repeat a sequence of commands that you would otherwise input manually one at a time. | ||
+ | |||
+ | This scripting of options for a single command can also be combined with data entry (i.e. coordinates or other numerical data). It is also possible to string together several commands in a row, for an automated sequence of events to manipulate or create objects. | ||
+ | |||
+ | > **Note:** //Why the _Underscores? | ||
+ | |||
+ | ======Getting started====== | ||
+ | |||
+ | Say you have to place a series of 10x10x10 boxes with the center of the bottom face landing at the desired point, with that point to be specified by either by a mouse click at the desired location or by entering the coordinates by the keyboard. | ||
+ | |||
+ | You could use the standard Box (**Corner to Corner + Height**) command, but by default this will place the insertion point at the first corner of the box. To have the insertion point where we want, it is easier to use the Box, Center command. | ||
+ | |||
+ | Open the **MacroEditor** and type this in: | ||
+ | |||
+ | ! _Box _Center | ||
+ | //(This is actually the macro under the Box, Center button if you check.)// | ||
+ | All entries (command words and numerical inputs) need to be separated by a single space. | ||
+ | |||
+ | Now, we need to specify the center point. | ||
+ | |||
+ | ! _Box _Center _Pause | ||
+ | | ||
+ | Once the data has been entered, you can specify the box size directly in the command. | ||
+ | |||
+ | ! _Box _Center _Pause r5,5 | ||
+ | | ||
+ | (Why the " | ||
+ | |||
+ | At this point you can put in the height, which in this case is relative to the original starting point. | ||
+ | |||
+ | ! _Box _Center _Pause r5,5 10 | ||
+ | | ||
+ | Since there is no further input necessary nor options possible, the macro completes and our box is there. | ||
+ | |||
+ | ! _Box _Center _Pause r5,5 _Enter | ||
+ | Now that the macro is running, [[rhino: | ||
+ | |||
+ | > //Note on the Pause command:// | ||
+ | |||
+ | For example the macro below | ||
+ | |||
+ | ! _Polyline Pause_SelLast | ||
+ | |||
+ | will work fine to make the polyline, but it will not be selected at the end. Why? Because the single Pause is ' | ||
+ | |||
+ | However, the following macro | ||
+ | |||
+ | ! _Polyline Multipause_SelLast | ||
+ | | ||
+ | works including selecting the polyline at the end because the Multipause includes //all// the picks for the polyline, allowing the SelLast to be executed and work at the end. | ||
+ | |||
+ | =====OK, let’s get a bit more complicated…===== | ||
+ | |||
+ | Some commands invoke dialog boxes with many options. | ||
+ | |||
+ | =====Loft two open curves===== | ||
+ | |||
+ | Let’s say you would like to repetitively **Loft** two //OPEN// curves together to form a surface. | ||
+ | |||
+ | < | ||
+ | _-Loft | ||
+ | _Pause | ||
+ | _Type=_Normal | ||
+ | _Simplify=_None | ||
+ | _Closed=_No | ||
+ | _Enter | ||
+ | </ | ||
+ | |||
+ | Note that when you invoke the command, immediately a pause lets you pick your curves. | ||
+ | |||
+ | =====Modifying it to use with closed curves===== | ||
+ | |||
+ | Now, try it with two closed curves. | ||
+ | |||
+ | Adding a pause in the right place lets you check and adjust the seam on screen: | ||
+ | |||
+ | < | ||
+ | _-Loft | ||
+ | _Pause | ||
+ | _Pause | ||
+ | _Type=_Normal | ||
+ | _Simplify=_None | ||
+ | _Closed=_No | ||
+ | _Enter | ||
+ | </ | ||
+ | |||
+ | Adding an Enter instead of the Pause tells Rhino you don’t care. Just leave the seam the way it is by default. | ||
+ | |||
+ | < | ||
+ | _-Loft | ||
+ | _Pause | ||
+ | _Enter | ||
+ | _Type=_Normal | ||
+ | _Simplify=_None | ||
+ | _Closed=_No | ||
+ | _Enter | ||
+ | </ | ||
+ | |||
+ | Or, you can specify another Loft seam option by stepping down into the seam sub-option level: | ||
+ | |||
+ | < | ||
+ | _-Loft | ||
+ | _Pause | ||
+ | _Natural | ||
+ | _Enter | ||
+ | _Type=_Normal | ||
+ | _Simplify=_None | ||
+ | _Closed=_No | ||
+ | _Enter | ||
+ | </ | ||
+ | |||
+ | (The Enter after Natural is necessary to exit the “seam” option level and get back up to the Loft options level.) | ||
+ | |||
+ | // | ||
+ | |||
+ | |||
+ | ======Using macros to set your interface options quickly====== | ||
+ | |||
+ | Macros can also be used to set various GUI and Document Properties options automatically without having to go wading into the Options dialog. | ||
+ | |||
+ | < | ||
+ | -_DocumentProperties | ||
+ | _Mesh _Custom | ||
+ | _MaxAngle=0 _AspectRatio=0 | ||
+ | _MinEdgeLength=0 _MaxEdgeLength=0 | ||
+ | _MaxEdgeSrf=0.01 _GridQuads=16 | ||
+ | _Refine=Yes _JaggedSeams=No | ||
+ | _SimplePlanes=No | ||
+ | _Enter | ||
+ | _Enter | ||
+ | </ | ||
+ | |||
+ | Why are there two Enters at the end? | ||
+ | |||
+ | You went down two levels in -_DocumentProperties, | ||
+ | |||
+ | The following is from Jeff LaSor, for turning on or off the crosshair cursor: | ||
+ | |||
+ | To script Crosshairs | ||
+ | < | ||
+ | -_Options _Appearance _Visibility | ||
+ | _Crosshairs _Enter _Enter _Enter | ||
+ | </ | ||
+ | Notice the reference to each individual command option name. Specifying them inside the script is like clicking on them with the mouse. | ||
+ | |||
+ | **EnterEnd** is a good way to 'back out' of a command without the need to keep track of how many levels deep you've gone - | ||
+ | |||
+ | < | ||
+ | -_Options _Appearance _Visibility _Crosshairs _EnterEnd | ||
+ | </ | ||
+ | |||
+ | Or, if you just use an exclamation point **!** at the end (which in a script means “end now!”), it takes you all the way out regardless of how many sub-levels you're in. Note, if you want to continue your macro with something else, do not use !, use the Enters instead, otherwise your macro will always stop at the ! and terminate. | ||
+ | |||
+ | The script simply toggles the crosshairs ON and OFF. But if you wanted a script that always turned them ON and another that always turned them OFF, here's what they would look like: | ||
+ | |||
+ | Always ON version: | ||
+ | < | ||
+ | -_Options _Appearance _Visibility | ||
+ | _Crosshairs=_Show ! | ||
+ | </ | ||
+ | Always OFF version: | ||
+ | < | ||
+ | -_Options _Appearance _Visibility | ||
+ | _Crosshairs=_Hide ! | ||
+ | </ | ||
+ | Note the use of the **!** here. Also, note you can assign directly the values options can take on to that option using the ' | ||
+ | |||
+ | (Thanks, Jeff) | ||
+ | |||
+ | ======Other useful macro writing tools and commands====== | ||
+ | |||
+ | There are some handy tricks for doing more complex macros. | ||
+ | |||
+ | < | ||
+ | Select | ||
+ | SelLast | ||
+ | SelPrev | ||
+ | SelNone | ||
+ | SetObjectName | ||
+ | SetGroupName | ||
+ | SelGroup | ||
+ | SelName | ||
+ | Group | ||
+ | Ungroup | ||
+ | </ | ||
+ | To set a single object name (this in itself is a macro!): | ||
+ | < | ||
+ | _Properties _Pause _Object _Name | ||
+ | [put your object name here] _Enter _Enter | ||
+ | </ | ||
+ | To cancel a single object name (without deleting the object) | ||
+ | < | ||
+ | _Properties _Pause _Object _Name | ||
+ | “ “ _Enter _Enter (quote space quote for the name) | ||
+ | </ | ||
+ | |||
+ | =====Examples using the above tools===== | ||
+ | |||
+ | Look at the following macro: | ||
+ | |||
+ | < | ||
+ | _Select _Pause _Setredrawoff | ||
+ | _BoundingBox _World _Enter | ||
+ | _Selnone _Sellast | ||
+ | _OffsetSrf _Solid _Pause | ||
+ | _Delete _Sellast | ||
+ | _BoundingBox _World _Enter | ||
+ | _Delete _Setredrawon | ||
+ | </ | ||
+ | It creates an offset bounding box around an object. The offset is input by the user. See if you can follow the logical sequence. | ||
+ | |||
+ | **//As a final example,// | ||
+ | |||
+ | Note the use of a named group and various selection commands. | ||
+ | |||
+ | < | ||
+ | _Select _Pause _Noecho _Setredrawoff | ||
+ | _Group _Enter _SetGroupName TexTemp | ||
+ | _BoundingBox _CPlane _Enter | ||
+ | _SelNone _SelLast _PlanarSrf | ||
+ | _SelPrev _Delete _SelLast | ||
+ | _AreaCentroid _Delete | ||
+ | _Sellast _SelGroup TexTemp | ||
+ | _Ungroup _Group _Setredrawon | ||
+ | |||
+ | </ | ||
+ | |||
+ | //last edited: 28.08.19/ | ||
+ | |||
+ | **Please feel free to add to or edit this tutorial!** | ||
+ | This is a work in progress... | ||