"""Demonstrates HowTo: Use Embedded Contouring. DEPENDENCIES Python: 2.2.[3-*] MineSight 3D: 3.50.* MineSight Grail: 3.50.* REVISION HISTORY None. LICENSE AGREEMENT The Original Code is "contour-selected.py". The Initial Developer of the Original Code is Leica Geosystems. Portions created by Leica Geosystems are Copyright (C) 2014 year. Leica Geosystems. All Rights Reserved. """ import sys import os import string from grail.ms3d import mssys from grail import gsys from grail import messages # Add required imports from grail.ms3d import selectionbuffer from grail.ms3d import element from grail.ms3d import elementop from grail.ms3d import datamanager # Re-direct print statements to the MS-3D Message Window # sys.stdout = mssys.stdout def gmain(msg, data): """Main entry point.""" if msg == messages.gPRE_RUN: pass # do any pre-processing prior to running a script. elif msg == messages.gRUN: run_code() # run your script. elif msg == messages.gPOST_RUN: pass # do any post processing on your script. else: return gsys.grailmain(msg, data) def is_surface(el): return el.get_type() == element.ShellType def run_code(): """Sample 'function' in embedded script. This function will write some text out the message window, but you can have it do anything you like. """ # (1) Get what the user has selected. selected = selectionbuffer.get_elements() # (2) Filter so we only have surfaces surfaces = filter(is_surface, selected) if not surfaces: mssys.stderr.write("No surfaces selected.") return # exit our script # (3) For each surface, start contouring. start = 0 end = 2000 minor_elevation = 10 major_elevation = 50 print "contouring...", for surface in surfaces: print ".", minor = elementop.contour(surface, start, end, minor_elevation) major = elementop.contour(surface, start, end, major_elevation) # (4) Store them into a MineSight Object; if one already exists, # then remove it prior to adding new contours. if datamanager.is_object("\\contours"): datamanager.remove("\\contours") g = datamanager.create_geometry("\\contours", "\\materials\\geometry") g.add_elements(minor) g.add_elements(major) print "OK."