Module 05 - Macros 1 Rev 03
Module 05 - Macros 1 Rev 03
Module 05 - Macros 1 Rev 03
Notes:
Macros
Duration: 45 minutes
This module will teach you how to write, test, and run a macro. You can use
macros to automate a variety of MICROMINE tasks, including the Plot Editor.
Introducing Macros
Macros are an important part of MICROMINE, since they allow you to automate
MICROMINE processes. A macro is simply a file containing a list of instructions
that allow MICROMINE to perform a sequence of commands without further
input. Once a macro is set up, you can run it repeatedly without intervention.
You can include any function that appears on the MICROMINE menu as a
macro instruction.
Why Write Macros?
There are numerous reasons for writing macros, but they usually belong to one
of two primary tasks:
• Repetition. Macros allow you to perform the same operation many times
without having to sit at your computer. A classic geological example
involves plotting many cross sections at the conclusion of a drilling
programme. In this case the macro would repeat the same drillhole
function as many times as there were cross sections.
You can combine both primary tasks using advanced macro writing techniques.
You can also increase the flexibility of your macro by prompting the user for
values during execution. You’ll learn to write these advanced macros in the
Macros 2 module, which is part of the Advanced MICROMINE course.
Notes:
Creating a Macro
Writing and using macros is a three step process:
1. Create, test, and save all form sets that will be accessed by the macro;
2. Write the macro file, referencing the previously saved form sets;
Creating Form Sets
The easiest way to create form sets for a macro is to use MICROMINE in the
normal way. In other words, you simply choose a menu option, fill out the
dialog, and if possible run the function with some trial data. You should
continue to test the dialog until you’re satisfied with the result.
Once you’ve prepared the dialog, consider which responses on that dialog will
change each time it’s run from a macro. For example, if you were plotting cross
sections, the Section number would probably change each time that function
was run.
After you’ve identified the responses whose values will change, substitute the
trial data values with Replaceable Parameters. These parameters are identified
by a % (percent) symbol followed by a number, for example %3, and will be
replaced with actual values when the dialog is run from the macro. You can
define replaceable parameters %1 through %15.
Exercise 1.1: Set up form sets for a macro Notes:
Setup the Vizex display
To set up a saved view in Vizex for use in a Macro:
2. Click on the [+] button next to the Drillhole Trace Object on the Forms Set
Pane to expand the Drillhole trace Forms.
3. Open the your assay display formset you created in Module 2 by double
clicking on it.
4. Click on the [+] button next to the Drillhole Value Object on the Forms Set
Pane to expand the Drillhole Events Value Forms.
5. Open the Assay Labels form set by double clicking on each of these forms.
6. Click on the [+] button next to the Drillhole Hatch Object on the Forms
Set Pane to expand the Drillhole Hatch Forms.
8. Click on the [+] button next to the Wireframes Object on the Forms Set
Pane to expand the Wireframes Forms.
10. Once you have loaded all the objects into the display, open the Display
Limits window by clicking on the Display Limits Button.
11. Set the View to LOOKING NORTH and select an appropriate Section and
select OK.
You’ve now produced a simple drillhole cross section. We want to save this as
a saved view so it can be re-used in a macro.
12. Select File | Save from the main menu or select the Save Icon from the
main toolbar.
13. Ensure you are not saving over a previously saved view by selecting the
New button if it is highlighted.
14. Set the Title to Simple Cross-Section for Macro. Click OK to save the
Saved View.
Define Replaceable Parameters
It’s now time to consider which responses will change each time this dialog is
run from a macro. Given the macro’s intended function, the Section number, or
northing, is obviously going to change from time to time. Inspection of the data Notes:
reveals that the drillhole line spacing varies somewhat, so the Window towards
and Window away responses must also change.
1. Open the Display Limits window by clicking on the Display Limits Button.
3. Replace the Window away value with %2, and Window towards with
%3.
These replaceable parameters serve as placeholders for real data. When the
macro is run, MICROMINE will search the macro file for data values matching
the various %-values and place them into the dialog.
Save the form set
Now we need to save the dialog as a form set so that it can be referenced from
the macro.
2. On the Forms dialog, click Save As and set the Title to Cross section
setup - macro. Click OK to save the form set.
Editing a Macro File
Once you’ve defined the form sets that make up your macro, it’s time to write
the macro file itself. To create a new macro file, you either choose File | New
and set the Type to MACRO, or choose Tools | Macros | New. The macro
structure is well defined, so there’s no need to use a template in either case.
Macro files are ordinary MICROMINE files, so you can use all of the standard
data entry shortcuts like Ctrl+A (add) or Ctrl+R (replicate). Additionally, the
Process and Form fields in the macro file have permanently attached lookup
tables to simplify the macro writing procedure. The Process lookup table simply
reproduces the main MICROMINE menu, and the Form lookup table lists the
saved form sets corresponding to the chosen process.
When you’re writing a macro, each line represents a single step or “process”,
which usually requires you to specify three pieces of information:
1. The Process, which corresponds to the menu item you’d have chosen if
you were performing the same task manually;
2. The Form, which allows you to choose the appropriate form set;
Most Process settings correspond to main menu options, but there are a few
special commands that apply only to macros, the most common of which are:
• ABORT: Type YES into the Form field to make the macro terminate if an
error occurs;
• COMMENT: Forces the macro to ignore all subsequent text on that line.
You can use this to label the fields in your macro file.
Finally, if you’re writing a macro that involves creating plot files, you must type
the name of the output plot file into the Plot File field.
The Plot File field serves only one purpose: to reproduce the
Generate Plot File dialog that pops up whenever you manually
create a plot file from a graphic display.
Notes:
Exercise 1.2: Write a macro file
Now it’s time to write the macro itself:
2. When the New Macro File dialog appears, type in the Name
DH_SECTION and click OK. You’ll see a blank macro file appear in the File
Editor. Observe how the Process and Form fields have lookup table
buttons.
3. Click the Process lookup table button and note how the popup menu
reproduces the main MICROMINE menu. Select Display | Vizex | Saved
View from this menu.
4. Click the Form lookup table button and select your saved form set from
the list.
Once it’s chosen, you can edit the form set by right clicking in the
Form field. You can also create form sets for simple dialogs (for
example, File | New) without leaving the File Editor. Simply choose
the required Process and right click the Form field to display the
appropriate dialog.
6. Click the Process lookup table button, and select Display | Vizex |
Display Limits from this menu.
7. Click the Form lookup table button and select your saved display limits
form set from the list.
If you remember the Display Limits dialog from the previous exercise, Section
corresponded to %1, Window towards was %2 and Window away was %3.
Knowing this, we’re now ready to place actual data values into the matching
fields of the macro.
8. Type the value 6945200 into the %1 field, and 50 into both %2 and %3.
9. Finally, type the name 6945200mN into the Plot File field.
At this point it’s worth exploring the similarities between this macro and
performing the same task manually.
• You select The Saved view from your Form Sets Tab in Vizex to load your Notes:
required data.
• You select the Display Limits process from the toolbar This is exactly like
making the same selection from the main menu. In other words, choosing
a process within a macro is the same as making a menu selection during a
manual run.
• You chose a saved form set. This is just like choosing Forms and then
clicking Open after you’ve opened the desired dialog or selecting a from
from the Form Sets Tab.
• You typed values into the %-fields. This is equivalent to typing those
values directly into the dialog. In comparison, when you run the macro,
MICROMINE sees the %-values in the dialog and searches the matching
%-fields in the macro for actual data values.
• Finally, you typed a Plot File name. This corresponds to the name you’d
type into the Generate Plot File dialog after clicking the Plot toolbar
button.
1. Select Records | Increment from the File Editor menu and type a value
of 100 into the Increment Value dialog.
2. Highlight the 15760 value in the %1 field and press Ctrl+A five(5) times.
There should now be nine lines in the macro and the last %1 value should
read 16000.
3. Highlight the 6945700mN value in the Plot File field and press
Shift+Ctrl+A. Click OK on the Increment Many dialog to update the
values.
4. For each of the fields Process, Form, %2, and %3, highlight the first
value and press Ctrl+Shift+R. Your macro file should now look like this:
5. Save the macro and close the editor. You’ve now written a macro that will
automatically make nine plot files.
Running Macros Notes:
Running a macro means executing the commands stored in the macro file. You
don’t run the macro file itself, but call the file from the Run Macro dialog.
You can include up to 42 macro files in the one run. This allows you to create
smaller files, which are easier to test, and then combine them to create
complex operations.
To run a macro, select Tools | Macros | Run from the menu. You can enter
the names of all the macro files you want to execute into the Run Macro
dialog. They’ll be processed in the order you enter them. If you’d like to start
with an intermediate macro, simply select the Start At button next to the file
where you’d like to begin. The files before it will be ignored.
You must also enter a compulsory report file name. It’s essential that you check
this file after the macro has run, since any popup messages that would have
been displayed during a manual run will be written to this file. At the very least
you should scan the report for errors, which will always be highlighted with
blocks of hash ‘#’ symbols, like this:
Time: 08:48:48
#### ERROR IN COPY STRUCTURE ####
----------------------------
Exercise 1.3: Run a macro
Now you can check the result of your efforts:
2. On the Run Macro dialog, double-click the Macro Name at row number
1 and choose DH_SECTION from the list.
If you give the report file the same name as the macro, you’ll be
able to track which reports correspond to which macros.
5. If you watch carefully, you’ll be able to see %1 being replaced with actual
values on the Normal Sections dialog. You’ll also be able to see the
sections changing in the graphic display.
6. Once the macro is finished, right-click the report file name and view the
contents. Any error messages will be reproduced here. Close the report file
once you’re satisfied.
Notes:
Toolbox
MICROMINE Toolbox is a project which is attached to MICROMINE
when you run an installation. It is essentially a group of Macros
available to use with your own data.
The MICROMINE Toolbox provides a way to run processes that are not
available as a single function. The Toolbox project contains a set of
macros that can be used to manipulate data in any of your working
projects. You invoke a Toolbox process by opening the Toolbox project
and then running the appropriate macro.
Notes:
Lesson Summary
This lesson has introduced the concepts of macro writing. The topics that we’ve
covered so far are:
Run it!
To set up a form set:
The replaceable parameter values (i.e. what you’d have manually typed
into the dialog).
Good Practice
Keep your macros short and restrict them to achieving a single outcome
whenever possible. Short macros are much easier to maintain. If required, you
can string together simple macros in the Run Macro dialog to perform a more
complex task.
Giving report files the same names as the macros will allow you to track the
relationship between them.
Help Topics
For information on: See:
Notes: