Escolar Documentos
Profissional Documentos
Cultura Documentos
MineSight® Grail
Annual Data Access and Embedded Scripts
Seminar Introduction
MineSight® Grail is a flexible and powerful scripting library for customizing MineSight®
for site implementation engineers and end users. In addition, MineSight® Grail is a
replacement for MINTEC’s traditional MineSight® Compass™ procedure language.
It exploits the richness of Python as a scripting interface and provides a flexible GUI
layout tool. MineSight® Grail procedures can be run inside of MineSight® Compass™,
use MineSight® Compass™ Multi-Run, run inside MineSight® 3-D, as well as executed in
standalone mode from a desktop shortcut or from a command window.
There are many instances when working with a MineSight® project that a user is
required to customize and automate a number of processes. The current customization
method is to use MineSight® Compass™ procedures, which are based on a proprietary
language developed by MINTEC over a number of years. While this has served our clients
well, extending the traditional MineSight® Compass™ procedure language is not a trivial
undertaking. Since we already have developed Python scripting experience in providing
user customizable reserve calculations in MineSight® Interactive Planner, it was decided to
extend the use of Python into a more general scripting interface into the system.
It is important to note that MineSight® Grail is not just a replacement for MineSight®
Compass™ procedures, but is a glue interface that lets us bind processes together in an
easy way, and provide a rich interface toolkit that can be embedded in or run independent
of MineSight® 3-D or MineSight® Compass™.
This paper will explore two major concepts that MineSight® Grail brings to MineSight®.
They are:
1. Open data access
The data that MineSight® programs and procedures store are now accessible via
MineSight® Grail. This paper will concentrate on working with Model, Geometry
MSR, and Drillhole data files.
2. MineSight® Grail Embedded
This is the phrase we use to refer to running Python scripts and using the MineSight®
Grail library to help automate tasks within MineSight® 3-D. In addition, this will also
allow on-site engineers to customize functions in MineSight® 3-D to help meet their
unique circumstances.
How Python Integrates with MineSight® 3-D
The popular scripting language, Python, integrates with MineSight® 3-D via the
MineSight® Grail library.
The MineSight® Grail library provides python modules that allow,
• Direct access to MineSight data files.
• Python script execution within a Multi-run context.
• Work with MineSight Interactive Planner.
• Access to the internal operations in MineSight-3D.
• The ability to build graphical user interfaces using Python.
The above can be summarized in a table as,
Table 1 Decribes what style of MineSight® Grail scripts can be used in what context.
In this table a Basic script refers to any Python script that imports a component of the
MineSight® Grail library—such as access to drillhole files—but does not require an instance
of MineSight® Compass™ or MineSight® 3-D to be active in order to run.
We are going to traverse the model and use the model items CU, MOLY, and EQ.
Assume that the samp10.dat and samp15.dat files have the above dimensions and
items. You can always use the grail.data.pcf module to query the PCF file and
determine how the model file is formed. Now, set up the looping calculation.
# model access “grain” is row by row
for row in xrange(rowmin, rowmax+1):
# define and retrieve a “slab”
m = model.Model(“samp10.dat”, “samp15.dat”,
def readfile(pointfile,coords):
for i in fileinput.input(pointfile):
line = string.split(i)
x1 = string.atof(line[0])
y1 = string.atof(line[1])
z1 = string.atof(line[2])
CentList = [(x1,y1,z1),(x1,y1-1,z1),(x1-1,y1,z1)]
coords.append(CentList)
return coords
def markerdisplay(msrpath,coords):
msr = geometry.Geometry(msrpath)
for i in range(len(coords)):
msr.addsemitlabel([“Truck 1”],coords[i])
print coords[i]
msr.storeresource()
time.sleep(5) # time it waits before reading next point
msr.deletesemitlabelat(0)
msr.free() # Clean up pythons internal structure
def main():
coords = []
try:
# attempt to read the paths from the command line.
msrpath = sys.argv[1]
pointfile = sys.argv[2]
except IndexError, e:
print “error: require msrpath and pointfile path.”
if isgeometryfile(msrpath):
readfile(pointfile,coords)
markerdisplay(msrpath,coords)
if __name__==”__main__”:
main()
In this script, the user will enter a msrpath and a pointfile path when you start the script.
The script should be executed on a timer (using a Microsoft® Window’s task manager). The
script will go through the following steps,
• Read the point file to determine the trucks current location.
• Open the geometry file.
• Remove the old truck location, if one exists.
• Write the new truck location based on the point file.
Now, when Minesight® 3-D refreshes the Datamanager the new label location for the
Page 4 MineSight Grail—Data Access and Embedded Scripts
®
22nd truck will have changed. Using this script to retrieve truck location data from a database
would in effect show your truck positions live in a Minesight® 3-D project.
Annual Drillholes
Starting in Minesight® Grail v3.40-00, the library will provide the ability to extract,
manipulate, and modify data in your drillhole and blasthole files. For simplicity, we will
Seminar refer to drillholes sets, but the concepts also extend to blasthole sets.
A drillhole set is analogous to a drillhole view in Minesight® 3-D.
The drillhole set is composed of three components,
1. drillhole or blasthole files: a pcf, an assay or composite file, and possibly a survey file.
2. a method of naming the drillholes or blastholes.
3. a method of defining the drillhole or blasthole geometry.
All three of the above components must be specified when defining a drillhole set.
Methods are provided for defining (opening) a drillhole set, querying each of its
attributes, and reading and writing data to the drillhole files.
The following script illustrates looping across all drillholes in a sample drillhole set. For
each assay interval it will add the values for the items TOTCU and MOLY and store the
result in the XTRA1 item.
from grail.data import dh
# define a dhset
dhset = dh.opentypicaldhset(“samp10.dat”, “samp11.dat”, “samp12.dat”)
dh = “sm-021”
totcu = dhset.dhintervaldataat(dh, 6, “totcu”)
moly = dhset.dhintervaldataat(dh, 6, “moly”)
xtra1 = dhset.dhintervaldataat(dh, 6, “xtra1”)
def areareport():
elements = selectionbuffer.getelements()
if elements == []:
mssys.stdout.write(“There where no elements selected.”)
else:
reportareas(elements)
def reportareas(elements):
print “Element Name, Area”
cnt = 0
def getprojectdim():
if project.getunittype()==project.METRIC:
return “m”
else:
return “ft”
Early on in the script, we inform python that it will use mssys.stdout for all its print
statements. Using mssys.stdout will ensure that all print statements are displayed in the
Minesight® 3-D Message window.
The elements are retrieved in the selectionbuffer.getelements() statement, and a loop
across all the elements is performed with the area calculated for all elements that can have
an area.
The area is then reported to the message window via the print statement.
Manipulating the Datamanager
With Minesight® Grail Embedded you will also be able to manipulate objects within the
Datamanager. These objects are commonly referred to as Minesight® Objects (MOBs).
Currently, you can create a new MOB of type geometry and populate it with geometry
objects. This technique will be used for the automated triangulation and contouring
examples also described in this paper.
However, as a simple example of creating a Datamanager object and inserting a
polylines consider the following script:
import sys
from grail import gsys
from grail import messages
from grail.ms3d import element
from grail.ms3d import mssys
from grail.ms3d import datamanager
def drawpolylines():
# create our polygon elements to store in the
# geometry object.
numpolylines = 10
polylines = [None]*numpolylines
print “creating polylines...”,
for idx in range(numpolylines):
points = [[-10., -10., float(idx*10)],
[0., 0., float(idx*10)],
[10., 10., float(idx*10)]]
Annual if datamanager.isobject(“\\newobject”):
print “removing \\newobject...”,
datamanager.remove(“\\newobject”)
This script generates 10 polylines, a new Minesight® object within the Datamanager, and
stores those polylines within that Datamanager object.
Automating Triangulations
Running triangulates can be a time-consuming and repetitive task. Now with Minesight®
Grail v1.2 and Embedded Grail within Minesight® 3-D v3.4 you will be able to run a
triangulation routine on any Element that you extract from either the selection buffer or
from a Datamanager Minesight® Object (MOB).
The follow small script illustrates the triangulation of all data stored in MOBs within the
data folder in the Datamanager.
import sys
import os
import time
def ispolyline(el):
“””Indicates if a given element is a polyline or not.”””
return el.gettype() in [element.PolylineType, element.PolygonType]
def run():
print “-”*50+”\nstarting triangulation (%s) ... “ % (sys.argv[0])
for item in datamanager.listfolder(“\\data”):
srcpath = os.path.join(datamanager.ROOT, “data”, item)
dstpath = os.path.join(datamanager.ROOT, “data”, “tri_”+item)
The above script works with the Datamanager to find polylines within the data folder to
triangulate. The triangulation in this case is a simple triangulation operation, but the effect
is a surface. Each surface is stored as “tri_xxx” where “xxx” is the original name of the
Datamanager object that contained the polylines.
One can easily combine the triangulation operation shown above with the contouring
operation shown below. With these two steps one can take a series of polylines, generate a
surface, and then generate a contour interval to their specifications.
Automating Contouring
With the Minesight® Grail Embedded you will be capable of generating contours for a
given surface.
The contour operation is the basic creation of a polylines for a given elevation on a
surface. A smoothing operation is left as another operation to be executed on the resultant
contour polylines.
The following script will open every Minesight® geometry object in the \data directory
of the Datamanager. It will look for surfaces and generate contours for that surface. Those
contours will be stored back into a file prefixed with “cont”. Generally you would have
some specific set of regular and index contours you wish to generate for your surfaces,
but for purposes of illustration, this script will just apply a percent of contours base on the
elevation difference for a particular surface.
The contour.py script is as follows:
def issurface(el):
return el.gettype() == element.ShellType
contours = []
for surface in surfaces:
min, max = ag.pointlistboundingvolume(surface.getpointlist())
minz, maxz = min[2], max[2]
diff = maxz-minz # only need to examine “Z”
step = diff/(diff*CONTOUR_PERCENT)
print “ contouring with: [%f, %f) and steps of %f” %\
(minz, maxz, step)
Summary
Using Python with Minesight® Grail allows you to accomplish a multitude of tasks for
your business needs. The Minesight® Grail library will provide you with the ability to
access Minesight® data in any way that you see fit. In the future, Minesight® Grail will be
used to help automate and customize your Minesight® 3-D experience.