grail.ms3d.progressmeter Module

Version: 16.2

Table of Contents

Overview

This module provides you with ability to control the MineSight® 3D progress meter. This is useful for giving the user an indication that a long process may active within your script.

Usage

The progress meter module defines a ProgressMeter object that controls access to the MineSight® 3D progress meter. The progress meter generally follows these three steps.

  1. Start the progress meter with your number of updates.
  2. Update the progress meter to a new percentage completed.
  3. Stop the progress meter to notify MineSight® 3D to clean up the and stop displaying the progress meter.

As an example, consider incrementing the progress meter as you calculate the area of all polygons selected by the user (see the %MEDEXE%/scripts/samples/grail.ms3d.elementop/em-calculate-area.py script for details).

def compute_area(el):
        
"""Helper function computes areas."""
        
if el.get_type() == element.PolygonType:
            
return elementop.calc_area(el)
        
else:
            
return 0.0

def areas():
    
"""Example of using the progressmeter."""
    
if not selectionbuffer.is_selection():
        
mssys.stderr.write("No selection!\n")
        
return # quit

    
elementList = selectionbuffer.get_elements()
    
numElements = len(elementList)

    
# Start up the progress meter...
    
pm = progressmeter.ProgressMeter()
    
pm.start(numElements)

    
for elementIdx in xrange(numElements):
        
el = elementList[elementIdx]
        
area = compute_area(el)
        
mssys.stdout.write("%d: %.2f\n" % (elementIdx+1, area))

        
# In this case we just indicate the new incremental value.
        
pm.increment(elementIdx)

        
# In this case we have to specify the percentage in the range
        
# 0.0 to 1.0 .
        
# percent = float(elementIdx)/float(numElements)
        
# pm.percent(percent)

    
pm.stop()

In this case we use the increment method, and supply the progressmeter with the next index (i.e. the next iteration). We could have just as easily computed the percentage completed, and supplied that value via the percent method.

If another process is holding onto the progress meter, the start() call will return 0.

ProgressMeter Class

class ProgressMeter()

Defines an object that provides access to the MineSight® 3D progress meter.

start(count):
Starts the progress meter with the given count. This call will return 0 if the progress meter object can not start because another process is holding onto it.
increment(step):

Increments the progress meter to the new step value.

For example if your progress meter was specified with 10 iterations, and you set the step to 1, the progress meter in MineSight® 3D would display 10%.

This method is useful when you are iterating through a set of objects.

percent(fractionalPercent):

Takes a fractionalPercent ranging from 0 to 1.0 and displays it as an integer percent ranging from 0% to 100% on the MineSight® 3D progress meter.

In this case you have to compute the percentage value that you want displayed in the MineSight® 3D progress meter bar.

update(percent):

Update the progress meter with the new integer percent value. You need to compute the new percentage value, and it must be between 0 and 100%.

Warning

DEPRECATED (as of MineSight® Grail v3.50-05)

Prefer to use either the percent or increment function calls instead. There was a lot of misunderstanding on how to use this method in the past. This function call is equivalent to calling the percent method and dividing your value by 100.0.

stop():
Stops the progress meter.