This shows you the differences between two versions of the page.
fr:rhino:basicmacros [2020/08/14] 127.0.0.1 external edit |
fr:rhino:basicmacros [2023/10/27] noemi |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== | + | ======Creating Macros====== |
- | ======Introduction====== | + | >A basic tutorial on creating macros (scripting together Rhino commands) |
- | Scripting | + | You can create **macros** in Rhino to automate many tasks, customize your commands, and improve your workflow. |
- | There may be some confusion about the term “scripting” | + | There may be some confusion about the use of the term “scripting”. It has been used to describe both the process of writing macros |
- | 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 two things are actually very different.// Writing functions in RhinoScript, |
+ | 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 | ||
- | The Rhino Help file - lists all Rhino commands and their sub-options, this is your most important reference. | + | =====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)// | ||
- | The Rhino V4 or V3 SR4+ Bonus tool **MacroEditor**, | + | {{: |
- | =====You' | + | It just calls the **ExtrudeCrv** |
- | 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 | + | |
- | {{: | + | This is an example of the simplest |
- | This an example of the simplest | + | |
- | 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. | + | 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 |
- | 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 | + | 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 |
- | > **Note:** //Why the _Underscores? | + | > **Note:** //Why the _Underscores? |
- | ======Getting | + | ======Getting |
- | 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 | + | Say you have to place a series of 10x10x10 |
- | 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. | + | 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**, type this in: | + | Open the **MacroEditor** |
- | ! //Box // | + | ! _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. | All entries (command words and numerical inputs) need to be separated by a single space. | ||
- | Now, we need to specify the center point. | + | Now, we need to specify the center point. |
- | ! //Box // | + | ! _Box _Center |
- | Once the data has been entered, | + | |
+ | Once the data has been entered, | ||
- | ! //Box // | + | ! _Box _Center |
- | (Why the “r”? | + | |
+ | (Why the "r”? | ||
- | At this point we can put in the height, which in this case is relative to the original starting point | + | At this point you can put in the height, which in this case is relative to the original starting point. |
- | ! //Box // | + | ! _Box _Center |
+ | | ||
Since there is no further input necessary nor options possible, the macro completes and our box is there. | Since there is no further input necessary nor options possible, the macro completes and our box is there. | ||
- | ! //Box //Center // | + | ! _Box _Center _Pause |
- | Now that the macro is running | + | Now that the macro is running, [[rhino: |
- | ======OK, let’s get a bit more complicated…====== | + | > //Note on the Pause command:// |
- | Some commands invoke dialog boxes with many options. | + | For example |
- | =====Loft two open curves===== | + | ! _Polyline _Pause _SelLast |
- | Let’s say you would like to repetitively **Loft** two //OPEN// curves together to form a surface. | + | |
- | {@ | + | will work fine to make the polyline, but it will not be selected at the end. Why? Because the single Pause is ' |
- | ====== _-Loft====== | + | |
- | _Pause | + | |
- | //Type=//Normal | + | |
- | // | + | However, the following macro |
- | //Closed=//No | + | ! _Polyline _Multipause _SelLast |
+ | |||
+ | works including selecting the polyline at the end because the Multipause includes | ||
- | _Enter | + | =====OK, let’s get a bit more complicated…===== |
- | }@ | + | |
- | 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===== | + | Some commands invoke dialog boxes with many options. |
- | 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 two open curves===== |
- | {@ | + | Let’s say you would like to repetitively **Loft** two //OPEN// curves together to form a surface. |
- | ====== | + | |
+ | < | ||
+ | _-Loft | ||
_Pause | _Pause | ||
- | _Pause | + | _Type=_Normal |
- | //Type=//Normal | + | _Simplify=_None |
+ | _Closed=_No | ||
+ | _Enter | ||
+ | </code> | ||
+ | |||
+ | 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 | _Enter | ||
- | }@ | + | </ |
- | Adding an Enter instead of the Pause tells Rhino you don’t care, just leave the seam the way it is by default. | + | |
- | {@ | + | 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 | _Pause | ||
_Enter | _Enter | ||
- | //Type=//Normal | + | _Type=_Normal |
- | + | _Simplify=_None | |
- | //Simplify=//None | + | _Closed=_No |
- | + | ||
- | //Closed=//No | + | |
_Enter | _Enter | ||
- | }@ | + | </ |
Or, you can specify another Loft seam option by stepping down into the seam sub-option level: | Or, you can specify another Loft seam option by stepping down into the seam sub-option level: | ||
- | {@ | + | < |
- | ====== | + | _-Loft |
_Pause | _Pause | ||
_Natural | _Natural | ||
_Enter | _Enter | ||
- | //Type=//Normal | + | _Type=_Normal |
- | + | _Simplify=_None | |
- | //Simplify=//None | + | _Closed=_No |
- | + | ||
- | //Closed=//No | + | |
_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> | + | (The Enter after Natural is necessary to exit the “seam” option |
+ | // | ||
- | ======Using Macros to set your interface options quickly====== | ||
- | Macros can also be used to set various GUI and Document Properties | + | ======Using macros |
- | {@ | + | Macros can also be used to set various GUI and Document Properties options automatically without having to go wading into the Options dialog. |
+ | |||
+ | < | ||
-_DocumentProperties | -_DocumentProperties | ||
- | //Mesh //Custom | + | _Mesh _Custom |
+ | _MaxAngle=0 _AspectRatio=0 | ||
+ | _MinEdgeLength=0 _MaxEdgeLength=0 | ||
+ | _MaxEdgeSrf=0.01 _GridQuads=16 | ||
+ | _Refine=Yes _JaggedSeams=No | ||
+ | _SimplePlanes=No | ||
+ | _Enter | ||
+ | _Enter | ||
+ | </code> | ||
- | // | + | 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 | ||
+ | </code> | ||
+ | Notice the reference to each individual command option name. Specifying them inside the script is like clicking on them with the mouse. | ||
- | _SimplePlanes=No | + | **EnterEnd** is a good way to 'back out' of a command without |
- | _Enter | + | |
- | _Enter | + | |
- | }@ | + | |
- | Why two Enters at the end? | + | |
- | Well you went down two levels in -_DocumentProperties, | + | < |
+ | | ||
+ | </ | ||
- | To script Crosshairs | + | 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. |
- | -//Options // | + | 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: |
- | 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 | + | |
Always ON version: | Always ON version: | ||
- | + | < | |
- | -//Options // | + | -_Options _Appearance _Visibility |
+ | _Crosshairs=_Show ! | ||
+ | </ | ||
Always OFF version: | Always OFF version: | ||
- | + | < | |
- | -//Options // | + | -_Options _Appearance _Visibility |
- | Note the use of the '!' | + | _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) | (Thanks, Jeff) | ||
Line 172: | Line 198: | ||
======Other useful macro writing tools and commands====== | ======Other useful macro writing tools and commands====== | ||
- | There are some handy tricks for doing more complex macros. | + | There are some handy tricks for doing more complex macros. |
- | {@ | + | < |
Select | Select | ||
- | |||
SelLast | SelLast | ||
- | |||
SelPrev | SelPrev | ||
- | |||
SelNone | SelNone | ||
- | |||
SetObjectName | SetObjectName | ||
- | |||
SetGroupName | SetGroupName | ||
- | |||
SelGroup | SelGroup | ||
- | |||
SelName | SelName | ||
- | |||
Group | Group | ||
- | |||
Ungroup | Ungroup | ||
- | + | </ | |
- | }@ | + | |
To set a single object name (this in itself is a macro!): | To set a single object name (this in itself is a macro!): | ||
- | + | < | |
- | | + | _Properties _Pause _Object _Name |
+ | [put your object name here] _Enter _Enter | ||
+ | </code> | ||
To cancel a single object name (without deleting the object) | 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===== | =====Examples using the above tools===== | ||
- | Have a look at the following macro: | ||
- | {@ | + | Look at the following macro: |
- | ====== Select Pause _Setredrawoff====== | + | |
- | // | + | |
- | //Selnone | + | < |
+ | _Select _Pause _Setredrawoff | ||
+ | _BoundingBox _World _Enter | ||
+ | _Selnone _Sellast | ||
+ | _OffsetSrf _Solid _Pause | ||
+ | _Delete _Sellast | ||
+ | _BoundingBox _World _Enter | ||
+ | _Delete _Setredrawon | ||
+ | </code> | ||
+ | It creates an offset bounding box around an object. The offset is input by the user. See if you can follow the logical sequence. | ||
- | //OffsetSrf | + | **//As a final example,//** the following macro creates a point centered on a 2D planar or text object and grouped with it. It assumes that you're in the same view the text was created in, and that the object is really 2D and planar. (Otherwise it will likely fail.) |
- | //Delete //Sellast | + | Note the use of a named group and various selection commands. |
- | // | + | < |
+ | _Select _Pause _Noecho _Setredrawoff | ||
+ | _Group | ||
+ | _BoundingBox _CPlane _Enter | ||
+ | _SelNone _SelLast _PlanarSrf | ||
+ | _SelPrev _Delete _SelLast | ||
+ | _AreaCentroid _Delete | ||
+ | _Sellast _SelGroup TexTemp | ||
+ | _Ungroup _Group _Setredrawon | ||
- | //Delete // | + | </code> |
- | }@ | + | //last edited: 28.08.19/msh// |
- | 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,// | + | **Please feel free to add to or edit this tutorial!** |
- | + | ||
- | 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... | This is a work in progress... | ||
- | |||
- | |||