Starting Guide for Mnova scripts

0

The availability to script in Mnova provides various opportunities and benefits both for those skilled at NMR and casual, non-expert users. Let's see how to get started with Mnova’s scripting ability.

Loading a script in Mnova.

Several sample scripts can be found under the 'Scripts' Menu.

 

You can also load new scripts by invoking the Scripts/Run Script.. menu. To make your own scripts appear in this menu, please refer to the 'Where should my custom scripts be saved' tutorial.

Creating your first script: Hello World

The "hello world" program has long been the ‘traditional’ first test program that various books have used to introduce a programming language. We will similarly use this as a crib sheet for you to refer to until you familiarize yourself more with the language. The point of this application, however, is to merely to familiarize you with all the most commonly used elements of the Mnova script language and include them in a script in a single place so that you can refer to it later. We will start by demonstrating the basic elements of an Mnova script, from which point you can add more advanced methods yourself. Mnova scripts can be created with any text editor, although Mnova includes a specialized script editor with syntax highlighting and debugging output capabilities that is recommended for use. This text editor can be opened by selecting the 'Scripts/Edit Script' menu command. Issue this command, and type in the following text:

 //<GUI menuname="HelloWorld" shortcut="Ctrl+1" tooltip="Hello World"/>
function helloWorld() { MessageBox.information("Hello World"); }

 

In this example we have defined the function we’re calling helloWorld(), which will simply display a message box containing the text ‘Hello World’. Note that the MessageBox function is highlighted in bold, which indicates that the Mnova script editor recognizes helloWorld() as a valid function. Next, go to the edit control at the top of the script editor and type:

helloWorld()

 

Don’t forget the brackets here as they are required by the scripting framework in order to properly interpret the function. Once you have entered the above, click on the green arrow on the right-hand side of the edit control. A pop-up message box should appear. Please note that you will be able to load/save any script by using the load and save buttons. The play button can be used to run a script by typing the function on the edit box, whilst the stop button will break into and stop a running script. Clicking on the Help button or pressing F1 will show you the 'Scripting help' window.

Guide to build your advanced scripts

You can find here a comprehensive guide to build your own advanced scripts.

Where to find out more

You can find more information in the Mnova manual, or otherwise accessed through the 'Help/Contents" menu in MestReNova, has a chapter devoted to scripts and scripting. You can also contact us if you would like our team to develop any scripts for you or if you need customized, in-house/web training.

Share.

About Author

Comments are closed.