This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Last revision Both sides next revision | ||
fr:rhino:basicmacros [2015/09/14] |
fr:rhino:basicmacros [2020/08/14] 127.0.0.1 external edit |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== A basic tutorial on creating macros (scripting with Rhino commands) ====== | ||
+ | |||
+ | ======Introduction====== | ||
+ | |||
+ | Scripting macros in Rhino is a way to automate many tasks, customize your commands and improve your workflow. | ||
+ | |||
+ | There may be some confusion about the term “scripting” as it used rather loosely to describe both the process of writing macros (what this section is all about), as well as writing more sophisticated “scripts” in either [[developer: | ||
+ | |||
+ | I will 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 | ||
+ | |||
+ | The Rhino Help file - lists all Rhino commands and their sub-options, | ||
+ | |||
+ | The Rhino V4 or V3 SR4+ Bonus tool **MacroEditor**, | ||
+ | |||
+ | =====You' | ||
+ | First, if you are a user of Rhino, you are already a user of macros 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. | ||
+ | |||
+ | {{: | ||
+ | This an example of the simplest type of macro, which simply sets a series of options within a single command so that you don’t have to specify each one every time you use it. **ExtrudeCrv** has several buttons with pre-set options, // | ||
+ | |||
+ | 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 you would have 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, resulting in an automated sequence of “events” for manipulating or creating objects. | ||
+ | |||
+ | > **Note:** //Why the _Underscores? | ||
+ | |||
+ | ======Getting Started====== | ||
+ | |||
+ | Let’s say you have to place a series of 10 x 10 x 10 boxes with the center of the bottom face landing at the desired point, that point to be specified by either by a mouse click at the desired location or by keyboard entering the coordinates. | ||
+ | |||
+ | One 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**, | ||
+ | |||
+ | ! //Box // | ||
+ | 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, we can specify the size of the box directly in the command. | ||
+ | |||
+ | ! //Box //Center _Pause r5,5 | ||
+ | (Why the “r”? | ||
+ | |||
+ | At this point we 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 and you are satisfied, [[rhino: | ||
+ | |||
+ | ======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 | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | _Enter | ||
+ | }@ | ||
+ | Note that the command is invoked, and then immediately after the pause which allows you to pick your curves. | ||
+ | |||
+ | =====Modifying it for use with closed curves===== | ||
+ | Now, try it with two closed curves. | ||
+ | |||
+ | Adding a pause in the right place will allow you to check and adjust the seam on screen: | ||
+ | |||
+ | {@ | ||
+ | ====== _-Loft====== | ||
+ | _Pause | ||
+ | _Pause | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | _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 | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | _Enter | ||
+ | }@ | ||
+ | Or, you can specify another Loft seam option by stepping down into the seam sub-option level: | ||
+ | |||
+ | {@ | ||
+ | ====== _-Loft====== | ||
+ | _Pause | ||
+ | _Natural | ||
+ | _Enter | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | _Enter | ||
+ | }@ | ||
+ | (the Enter after Natural is necessary to exit the “seam” option level and get back up to the Loft options level) | ||
+ | |||
+ | <color darkslateblue> | ||
+ | |||
+ | |||
+ | ======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 | ||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | // | ||
+ | |||
+ | _SimplePlanes=No | ||
+ | _Enter | ||
+ | _Enter | ||
+ | }@ | ||
+ | Why two Enters at the end? | ||
+ | |||
+ | Well you went down two levels in -_DocumentProperties, | ||
+ | |||
+ | To script Crosshairs | ||
+ | |||
+ | -//Options // | ||
+ | Notice the reference to each individual command option name. Specifying them inside the script is like clicking on them with the mouse. | ||
+ | |||
+ | OR, if you just use an exclamation point ' | ||
+ | |||
+ | The script above simply toggles the crosshairs ON and OFF, but let's say you wanted a script that always turned them ON and another that always turned them OFF...here' | ||
+ | |||
+ | Always ON version: | ||
+ | |||
+ | -//Options // | ||
+ | Always OFF version: | ||
+ | |||
+ | -//Options // | ||
+ | Note the use of 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!): | ||
+ | |||
+ | // | ||
+ | To cancel a single object name (without deleting the object) | ||
+ | |||
+ | // | ||
+ | =====Examples using the above tools===== | ||
+ | Have a look at the following macro: | ||
+ | |||
+ | {@ | ||
+ | ====== Select Pause _Setredrawoff====== | ||
+ | // | ||
+ | |||
+ | //Selnone //Sellast | ||
+ | |||
+ | //OffsetSrf //Solid _Pause | ||
+ | |||
+ | //Delete //Sellast | ||
+ | |||
+ | // | ||
+ | |||
+ | //Delete // | ||
+ | |||
+ | }@ | ||
+ | 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 | ||
+ | |||
+ | // | ||
+ | |||
+ | //SelNone //SelLast //PlanarSrf //SelPrev //Delete //SelLast | ||
+ | |||
+ | // | ||
+ | |||
+ | //Ungroup //Group _Setredrawon | ||
+ | |||
+ | }@ | ||
+ | ==Please feel free to add to or edit this tutorial!== | ||
+ | This is a work in progress... | ||
+ | |||
+ | |||