Creating Macros

来源:互联网 发布:迪克斯特拉算法 编辑:程序博客网 时间:2024/05/17 03:19

The tools you need

  1. Your brain.

  2. The Rhino Help file - lists all Rhino commands and their sub-options. This is your most important reference.

  3. The Rhino MacroEditor, to easily run and debug your macros.在
    rhino中输入指令 MacroEditor 打开宏指令编辑器(巨集编辑器)
    宏指令编辑器

You’ve already used a macro or two…

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. To see, Shift+right-click on the button Extrude Surface:

按钮编辑器
也可以自定义按钮,输入自定义的命令,方便重复调用。
这里写图片描述
Note: Why the _Underscores ? These tell Rhino that the command which follows is in English (no matter what the language you are running Rhino in), which will make your macro universal. If you are running in English and don’t care, you can eliminate the underscores in your macros if you wish. It will not affect anything else. Also, why the exclamation point (!)? This cancels any previous command that might be running, for safety’s sake.
下划线_告诉犀牛之后的命令是英文(不写一般也可以);感叹号!是用来取消之前可能正在运行的命令

Getting started

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. This is in reality just the Box command with the center option, so you will have to activate it in your macro.

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. To do this, you need to tell Rhino to stop processing the command temporarily and wait for an input in the form of a click or a keyboard entry. Do this by inserting the command Pause.(_Pause 是让Rhino暂时先不执行之前输入的宏命令)

 ! _Box _Center _Pause

Once the data has been entered, you can specify the box size directly in the command. Since the Center option in Box wants a corner of the box as a second input, you can specify its X,Y coordinates:

 ! _Box _Center _Pause r5,5

(Why the r? We want this coordinate to be relative to the last picked point, that is to say, the box bottom center. Otherwise the corner will always land at X5, Y5.)(‘r’表明后续的数字为相对坐标)

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. Note that since we wanted a height equal to the width, another possibility would just to have been to use Enter instead of 10 for the last entry.

 ! _Box _Center _Pause r5,5 _Enter

Examples

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. The Setredrawoff/on stop/restart the screen refresh, eliminates the display flickering as all is executed and speeds up the process. Beware, if you terminate the command before Setredrawon, you will think Rhino is dead, as the screen no longer updates. If this happens, don’t panic, typing the command Setredrawon will restore the display refresh.

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.)

Note the use of a named group and various selection commands. The NoEcho command temporarily stops the reporting of information to the command line, which, combined with Setredrawoff/on makes the macro run without flashing and without too much info reported to command history. It will run without those as well, though.

_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

本文根据Rhino官网的指导文档中的相关内容,结合Rhino 5 实际使用情况写成。

原创粉丝点击