Company Information

ID #1010

How do I program MacroWorks II Custom Commands?

Quick Answer:

MacroWorks II custom commands are programmed using AngelScript, and are saved as a .mwc file.

Further Details:

Programming a Custom Command:

Custom commands are scripted in a language called AngelScript. AngelScript uses C/C++ style syntax and can be learned from the manual at www.angelcode.com . If you are familiar with C/C++ syntax, you may be able to start without viewing the manual.
To make custom commands more powerful, you can also use a library of functions we created specifically for MacroWorks II (See "Custom Command Function Library" in the MacroWorks II Help File). Although this library is currently small, a future release will include a much larger library. Future additions will include message boxes and input requests to obtain variable values when running a macro.

Creating a New Custom Command File:

Creating a custom command file is easy. Simply create a new document in any text editor (such as Notepad, Microsoft Word, or even Microsoft Visual Studio). You can then use this new document to script your custom command.

Formatting a Custom Command File:

Every custom command file can have up to five different sections (each are optional). These sections include:

  • Shared Globals
  • Unique Globals
  • Shared Inits
  • Unique Inits
  • Custom Command
Shared Globals are global variables you want to declare that you would like to allow other custom commands to access as well.

Unique Globals are global variables you want to declare that only the code within this custom command should use. All unique variables must be designated by an underscore at the beginning of the variable name (e.g. _myVariable). MacroWorks II will then automatically rename your variable to create a new, unique name that won’t conflict with other variables, even if you use the same custom command twice.

The Shared Inits section is used to initialize any shared global variables before running the custom command.

The Unique Inits section is used to initialize any unique global variables before running the custom command. Remember to place the underscore before the variable name.

The Custom Command section is where you place your code. Local variables can be declared and used in this section. It is recommended you place an underscore at the beginning of local variable names as well. This keeps local variables from colliding with one another if the same custom command is used twice in one macro.



Each section should be declared before starting with the prefix “//MWII:”. For example, if you were to include each of these sections, your custom command file would look like this:
MWII custom script declarations
NOTE: It is important to make sure variable names in multiple custom commands do not overlap or this will corrupt your script file. This can happen in two ways.

First, if you use two different custom commands that each declare the same shared global; this will cause these global variables to be declared twice. If you wish to have two separate custom commands files use the same global variable, be sure to declare the variable in only one custom command file.

Second, unique global variables and local variables can collide even when playing the same custom command twice in the same macro if they do not begin with an underscore. Make sure to always include the underscore for unique, non-shared variables.

An Example:

The following two custom commands illustrate the use of the different types of variables in MacroWorks II custom commands:
Example custom command number one.
Example custom command number two.
If you were to play the first custom command and then the second, your output would be the following:
output one
However, if you played the second custom command and then the first, your output would change to the following:
output two

Notice in the last output that playing the second custom command first changed the output of the shared variable but not the unique variables.

Saving and Using a Custom Command File:

How and where you save a custom command file is important.

First, you must save your file within the custom command folder found in your MacroWorks II folder. If you installed MacroWorks II with the default path on your C:\ drive, the path to the custom command folder would be:
“C:\Program Files\PI Engineering\MacroWorks II\Custom Commands”.
Save you file here:

Second, you must save your file with the extension “.mwc”. To create a new extension, some text editors might require you to change the value in the “Save As Type” box to “All Files” before saving.
Save the file with a
Third, if MacroWorks II is already running, restart it.

If you saved your custom command file in the correct folder, it is now ready to be used in MacroWorks II. To use your command, choose a key to program, select “Insert” from the menu, and then select “Custom Command.” Your new function will be listed here and using the custom command on any key is as simple as selecting it from this menu.
Access your custom command through the MWII Insert > Custom Command menu.

You may have noticed from the Itunes and Winamp functions that custom commands can be organized into categories in the custom command menu. You can create a new category by placing a new folder in the custom command folder. MacroWorks II will use the name of this folder to automatically create a new category. Any custom command file you place in that folder will also automatically appear in the newly created category.

Tags: MacroWorks II

Related entries:

Last update: 2007-12-13 11:01
Author: Brandon
Revision: 1.0

Digg it! Print this record Send to a friend Show this as PDF file
Propose a translation for Propose a translation for
Please rate this entry:

Average rating: 0 out of 5 (0 Votes )

completely useless 1 2 3 4 5 most valuable

You cannot comment on this entry