Site Tools


Monkey™(Rhino4用)

Summary: Rhinoスクリプトエディタ

Contents

Monkeyとは?

Monkey is a new scripting environment within Rhino4 which can be used to edit, run and debug scripts. It contains all the standard programmer editor features such as Find/Replace (with regular expressions), multi-document interface, code trees and integrated helpfiles. For a complete list of features please see the bottom of this page. Monkey also comes with a separate application called the Monkey Script Compiler. This is a standalone exe which turns .rvb scripts into .rhp plugins. More information on the script compiler can be found here .

Monkey is a DotNET plugin meaning you need the Microsoft DotNET Framework 2.0 installed on your machine. Note that many computers already are DotNET compliant, so you only need to download and install this if Monkey doesn't run (you'll get an error message telling you when this happens).





最新バージョンのダウンロード

Usage and features

After you have installed Monkey, there should be a new menu in Rhino which gives you access to the script editor, the script runner and the script compiler. The script compiler is an external tool which means you can run it outside of Rhino, though you do need to have Rhino4 installed.





Using the script compiler

This wizard allows you to compile any number of RhinoScript files into a DotNET plugin which can be run on all similar versions Rhino's worldwide. The immediate benefits of this approach are:

  • Script code is encapsulated (made unreadable)
  • Scripts become linked to custom commands
  • You can add menus which run your scripts
  • Distribution is easier
  • You can package large script library files


Disadvantages of compiling your scripts are:

  • Scripts become unreadable and can thus no longer be changed on site. They have to be recompiled.
  • The plugin might not load on other versions of Rhino, even though the script itself might have worked.


The compiler is a typical wizard application which guides you through 4 required and one optional* stage:

  1. Define plugin attributes
  2. Add anddDefine script command attributes
  3. Define compilation settings
  4. Define licensing settings*
  5. Compile



Plugin attribute page:

You must supply a valid name for the plugin(no weird characters, no spaces). Apart from the plugin name, all other fields in the plugin attributes are optional. It is considered good practise though to assign a proper version code (this can be any string literal) and correct contact details. If you plan to License protect this plugin, you should also enter a correct Update URL or Website address since this link will be added to the Registration dialog.


Command list page:

Every plugin must have at east one command, but there is no upper limit. Like the plugin name, all commands must have valid names (no weird characters, no spaces). If you pick conflicting names (for example if you add a command called “Circle”) the plugin will compile but it will not load. If you attempt to load a plugin which shadows an existing command name Rhino will refuse to register the new command.

When you add a script you'll see a popup dialog which allows you to alter the script command attributes:



You can specify a custom command name and set a bunch of custom attributes:

  1. Hide command (this will prevent the command from appearing in the autocompletion list)
  2. Disable undo (undo recording will be turned off while this script is running)
  3. Echo script (script will be displayed in the command history prior to running)
  4. Add to plugin menu (Script command name will be added to the plugin menu, provided there is a plugin menu)
  5. Procedure library (Indicates this script is a procedure library, I.e. it will not recieve a command name but it will be loaded before any other plugin command is run)


Compiler settings page:

After you have added all scripts to the plugin, the [Next] button will take you to the compiler settings page. At this point you can save the Compiler project by pressing the button with the unfolded box. This allows you to quickly restore a project if you need to recompile it (for example when a new version of Rhino has been released or when you have made changed to the scripts).

The available settings are:

  1. *Encrypt source (This option will encrypt the contents of the plugin .rhp file to prevent code extraction. Note that encrypted plugins will have a delay before commands are run since the script source has to be decrypted. You can reduce loading times by putting generic functions into library scripts which are only loaded once)
  2. Licensed plugin (This will enable license protection for your plugin. Further information can be found here )
  3. Create plugin menu (Enables menu creation for this plugin. All commands that have the menu flag set will be included in the plugin menu. Note that the menu will only be visible after the plugin loads, thus if you want to have your menu on startup, you must enable Load on startup)
  4. Load plugin on Rhino start (If this option is disabled, the plugin will not be loaded until it is needed. This is the default behaviour in Rhino. If, for some reason, you want your plugin to load at startup, you must enable this option)
  5. Load message (This message will be displayed in the Rhino command line when your plugin loads)


When you press the *[Compile] button the wizard will create a new Rhino plugin (.rhp) in the specified location (the desktop by default). You can load this plugin by dragging it into Rhino4 or by loading it via the PluginManager






The Monkey editor

The Monkey script editor is a real Rhino plugin, not a standalone application meaning it can only be run inside of Rhino4. You can either run the _Monkey command or open the editor via the Monkey menu. After a short delay (yes, yes, I know. We're working hard to get it to load faster) you'll see the editor in all its glory:



The large tree on the left lists all RhinoScript methods which you can use. This tree can be extended easily to cater for other plugins (such as ArchCut ) which also support scripting access. If you double click an item in the method-tree you will be taken to the appropriate page in the appropriate helpfile. You can also drag and drop these methods into the code editor. You can search the method-tree using the textfield at the top, or click on the search button to open the advanced search dialog. Advanced search allows you to specify multiple search terms (space separated) and it displays all the matching items, instead of just the first one.

Most features of the Monkey editor are available via the main menu and a large majority of these are standard coding environment tools so I will only highlight the special ones:

• File » Recent Files » Erase MRU record Monkey keeps track of hundreds of MRU (most recently used) files. You can wipe the record clean with this menu option. It will not delete the files of course, it will only make Monkey forget that it ever opened them.
• Edit » Selection » (Un)Indent Block Adds or removes a leading tab for every selected line.
• Edit » Selection » (Un)Comment Adds or removes a leading apostrophe for every selected line.
• Edit » Selection » To Pascal Case Changes the casing of the selection to Pascal case (all words start with a single uppercase character).
• Edit » Autoformat Automatically reformats the document whenever you add/chage code.
• Edit » Snippets Displays a grouped list of example code which can be used to quickly create typical structures.
• Edit » Find in Files Displays a dialog that allows you to search all loaded documents for a specific string.
• Edit » Outlining » Toggle Outlining Inverts collapsed/expanded states for outline blocks.
• Edit » Outlining » Stop Outlining Expands all code blocks.
• Edit » Outlining » Collapse to Definitions Collapses all code blocks.
• View » Link To Rhino Toggles the Monkey window to be either a free-floating window or a Rhino child window.
• View » Hide during Execution Hide the Monkey window while a script is running.
• View » Code Blocks Show collapsable frames around procedure and class structures.
• View » Clear All Markers Remove all tags that have been added by a Mark All operation in the Find window.
• Source » Run Run the currently active script.
• Source » Debug Run the currently active script and stop at all breakpoint lines.
• Tools » Option Display the Monkey options dialog.
• Tools » ASCII Table Display the Monkey ASCII table dialog.
• Tools » Constant Browser Display a list of constant defined in the vbScript language.
• Help » Search Rhino Help… Searches the Rhino helpfile for a specific command name.
• Help » vbScript Online… Diplays the MSDN main page for the vbScript language.





Script debugging

Monkey adds a debugging feature to Rhino. If you add breakpoints on certain lines in the script (you can toggle breakpoints by clicking in the gutter) and then run it using the Debug mode, execution of the script will halt whenever a breakpoint line is encountered. At this point a dialog will be displayed which lists the values of all currently available variables. If no variables are currently on scope the breakpoint will not be triggered. The script below has breakpoints on lines 10 and 12.



Breakpoints are also an experimental feature, so beware when using it.

ja/developer/monkeyforrhino4.txt · Last modified: 2015/09/14 (external edit)