Nothing Special   »   [go: up one dir, main page]

Module 05 - Macros 1 Rev 03

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14
At a glance
Powered by AI
The key takeaways are that macros allow automating repetitive tasks and performing complex tasks by stringing together simple commands.

The primary reasons for writing macros are for repetition and to perform complex tasks.

The three steps involved in creating a macro are: 1) Create and test form sets, 2) Write the macro file, 3) Run the macro.

MICROMINE Training v9.

2 Module 05– Macros 1 (Rev 02)

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.

After this lesson you’ll be able to:

• Define replaceable parameters on dialogs;

• Save dialogs as form sets in preparation for macro execution;

• Write a macro file;

• Run a macro file.

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.

• Perform Complex Tasks. It’s possible to perform a complex task with a


macro by stringing together a chain of simple commands. For example,
you might regularly extract assay files from a database, perform a
significant intersections grade calculation, and report the results. These
three simple tasks could be combined into a single macro that would
automate this repetitive task.

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.

Copyright © Micromine 2003 Page 1


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

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;

3. Run the macro and check the result.


The following topics describe these steps in detail.

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.

Copyright © Micromine 2003 Page 2


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

Exercise 1.1: Set up form sets for a macro  Notes:

In this exercise you’re going to set up a very simple drillhole cross-section


display in preparation for automatically plotting multiple sections. You’ll be
setting up a section display in Vizex, and use the Display Limits to set up
each section display in the macro.

Setup the Vizex display 
To set up a saved view in Vizex for use in a Macro:

1. Open the formsets pane.

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.

7. Open the Drillhole Lithology formset you created in Module 2 by double


clicking on it.

8. Click on the [+] button next to the Wireframes Object on the Forms Set
Pane to expand the Wireframes Forms.

9. Open the DTM – 2D Slice Mode formset by double clicking on it.

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.

To save as a Saved View:

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

Copyright © Micromine 2003 Page 3


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

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.

Now let’s set up the replaceable parameters:

1. Open the Display Limits window by clicking on the Display Limits Button.

2. Replace the Northing/Section with %1 using the settings shown in the


following diagram.

3. Replace the Window away value with %2, and Window towards with
%3.

Once a dialog has been set up using replaceable parameters, it


won’t run from the menu. If you need to further test this dialog,
you’ll have to substitute the replaceable parameters with real
values before you can proceed.

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.

1. Click on the Forms button.

2. On the Forms dialog, click Save As and set the Title to Cross section
setup - macro. Click OK to save the form set.

Copyright © Micromine 2003 Page 4


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

3. Close the Display Limits dialog. Notes:


4. Select Edit | Remove All from the main menu to clear the Vizex Screen.

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;

Copyright © Micromine 2003 Page 5


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

3. The values of any replaceable parameters (%1 to %15). These Notes:


represent the values you’d have typed into the dialog if you were
performing the task manually.

During Normal (non-macro) use, when


you type a value directly into a dialog,
Micromine just uses that value.

During a Macro, Micromine searches the


dialog for replacable parameters. Values
for these are extracted from the matching
%-fields in the macro file.

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.

In addition, some functions, such as File | Modify, can’t be saved as form


sets in the normal way. However, you can still use these in macros by selecting
them from the Tools | Macro Functions menu.

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.

Copyright © Micromine 2003 Page 6


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

Notes:

Exercise 1.2: Write a macro file 
Now it’s time to write the macro itself:

1. Select Tools | Macros | New from the main menu.

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.

5. Press Enter to select the second line in the macro.

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.

Copyright © Micromine 2003 Page 7


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

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

Let’s finish the macro:

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.

In reality, your Window towards (%2) and Window away (%3)


values would probably vary slightly from section to section. For this
lesson we’ve saved time by assuming they’re all the same value.

Copyright © Micromine 2003 Page 8


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

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:

1. Select Tools | Macros | Run from the menu.

2. On the Run Macro dialog, double-click the Macro Name at row number
1 and choose DH_SECTION from the list.

3. Type the name DH_SECTION into the Report File response.

If you give the report file the same name as the macro, you’ll be
able to track which reports correspond to which macros.

4. Click the Run button and observe the result.

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.

7. Finally, close the Run Macro dialog.

Copyright © Micromine 2003 Page 9


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

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.

Copyright © Micromine 2003 Page 10


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

Notes:
Lesson Summary 
This lesson has introduced the concepts of macro writing. The topics that we’ve
covered so far are:

Writing a macro involves three steps:

Create the form sets, with replaceable parameters;

Write the file;

Run it!
To set up a form set:

Use MICROMINE as normal, then

Define the replaceable parameters, and

Save the form set.


For each process in a macro file, you must generally provide three items of
information:

The Process (i.e. what menu you’d have manually chosen);

The Form (i.e. which form you’d have manually loaded);

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.

Always view the report file after running a macro.

Giving report files the same names as the macros will allow you to track the
relationship between them.

MICROMINE Toolbox is a project attached with installation. This project allows


you to carry out processes not available within MICROMINE

Help Topics 
For information on: See:

Macros Macros: Overview (or, choose from many topics)

Toolbox Toolbox Help

Copyright © Micromine 2003 Page 11


MICROMINE Training v9.2 Module 05– Macros 1 (Rev 02)

Notes:

Copyright © Micromine 2003 Page 12


MODULE 5 TABLE OF CONTENTS 
MACROS ................................................................................................................................................................................1
INTRODUCING MACROS .........................................................................................................................................................1
WHY WRITE MACROS? .........................................................................................................................................................1
CREATING A MACRO .............................................................................................................................................................2
Creating Form Sets...........................................................................................................................................................2
Editing a Macro File ........................................................................................................................................................5
Running Macros................................................................................................................................................................9
TOOLBOX ............................................................................................................................................................................10

You might also like