"""Demonstrates HowTo: Use Embedded Triangulation. DEPENDENCIES Python: 2.2.[3-*] MineSight 3D: 3.50.* MineSight Grail: 3.50.* REVISION HISTORY None. LICENSE AGREEMENT The Original Code is "triangulate-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 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_poly(el): return el.get_type() in [element.PolylineType, element.PolygonType] def run_code(): # (1) Get What the user has selected selected = selectionbuffer.get_elements() # (2) Filter so we only have polylines and polygons. polys = filter(is_poly, selected) if not polys: mssys.stderr.write("No polylines selected.") return # exit our script. # (3) Triangulate the polylines. surface = elementop.triangulate(polys) # (4) Store the surface into a geometry object. If the object # already exists remove it. if datamanager.is_object("\\triangulated"): datamanager.remove("\\triangulated") geomObj = datamanager.create_geometry("\\triangulated", "\\materials\\geometry") geomObj.add_elements([surface]) # (5) Update the display. datamanager.refresh("\\")