Built-In Input/Output
Built-in input/output functionality has been included in the library for importing Maptek object files (.maptekobj) as well as Vulcan triangulation files (.00t) and Vulcan block model files (.bmf).
Note: For these examples you will need to download and extract Maptek_PythonSDK_Sample_IO_Files_20200108.zip into a folder.
Import functionality works to import data into the Project but doesn't assign it a path. When data is successfully imported it will be represented as an ObjectID. The Project.add_object() function is required to assign it to a path.
Importing a 00t file as a surface object
from mapteksdk.project import Project from mapteksdk.data import io, Surface from mapteksdk.data.units import DistanceUnit proj = Project() # Connect to default project # The file path you have exported the sample data to: file_path = "F:\Python SDK Help\data\phase_1_topo.00t" # Import the 00t: imported_surface = io.import_00t(file_path, DistanceUnit.meter) if imported_surface: # Successful imported, now assign a path # After add_object, set imported_surface as the new ObjectID: imported_surface = proj.add_object( full_path="import/phase_1_topo", new_object=imported_surface, overwrite=True) else: print("{} failed to import.".format(file_path))
Important: This function assumes import data is in metres.
Exporting a surface to a 00t file
This example will export the surface from the previous import example.
from mapteksdk.project import Project from mapteksdk.data import io, Surface from mapteksdk.data.units import DistanceUnit proj = Project() # Connect to default project # The file path to export the surface to: save_path = "F:\Python SDK Help\data\exported.00t" # Locate ObjectID of surface to export surface_to_export = proj.find_object("import/phase_1_topo") if surface_to_export: # Export to 00t: export_success = io.export_00t(surface_to_export, save_path, DistanceUnit.meter) if not export_success: print("Export failed") else: print("Could not find surface to export in project")
Importing a block model from a BMF file
from mapteksdk.project import Project from mapteksdk.data import io, DenseBlockModel from mapteksdk.data.units import DistanceUnit proj = Project() # Connect to default project # The file path you have exported the sample data to: file_path = "F:\Python SDK Help\data\shawmodel_reg.bmf" # Import the bmf: imported_blockmodel = io.import_bmf(file_path, DistanceUnit.meter) if imported_blockmodel: # Successful imported, now assign a path # After add_object, set imported_surface as the new ObjectID: imported_blockmodel = proj.add_object( "import/shawmodel", imported_blockmodel, overwrite=True) else: print("{} failed to import.".format(file_path))
Important: This function assumes import data is in metres.
Exporting a DenseBlockModel as a block model file
This will export the above imported block model back to a block model file (.bmf).
from mapteksdk.project import Project from mapteksdk.data import io, DenseBlockModel from mapteksdk.data.units import DistanceUnit proj = Project() # Connect to default project # The file path to export the block model to: save_path = "F:\Python SDK Help\data\exported.bmf" # Locate ObjectID of block model to export blockmodel_to_export = proj.find_object("import/shawmodel") if blockmodel_to_export: # Export to bmf: export_success = io.export_bmf(blockmodel_to_export, save_path, DistanceUnit.meter) if not export_success: print("Export failed") else: print("Could not find block model to export in project")
Importing a Maptek object file
A Maptek object file (.maptekobj) is a binary file that can store any number of project objects. In some Maptek applications such as Vulcan GeologyCore or PointStudio, you can open the Maptek object file as a secondary project. This gives you an explorer where you can browse the contents of the object file (which can have containers with more than one object inside).
Object files allow any objects in your project to be written out into a binary file or stream for archival or backup purposes, and to support sharing data between projects. This means it can be used for block models, markers, edge chains, edge loops, scans and much more. Theoretically anything that can be stored in a project can be exported to a Maptek object file.
It may have problems with objects that don't contain all their data, such as object types that reference external storage or data systems (outside of the project).
The receiving application may be able to import the data but may not know what do with it and different versions of it.
import os from mapteksdk.project import Project from mapteksdk.data import io proj = Project() # Connect to default project # Use the folder you have stored example maptekobj files in: maptekobj_path = "F:\\Python SDK Help\\data" maptekobj_files = ["single_object.maptekobj", "multiple_objects.maptekobj", "objects_in_container.maptekobj"] def assign_path(object_id, object_path): # Use the rename_object function to move it from nowhere into a path saved = proj.rename_object(object_id, object_path, overwrite=True) print("Stored: {}".format(object_path)) if saved else print("Failed to store: {}".format(object_path)) return object_path def store_maptekobj_objects(maptekobj_id, parent_path = "scrapbook"): if "\\" in maptekobj_id.name: # multiple objects were exported, but not stored within a VisualContainer for item in proj.get_children(maptekobj_id).ids(): assign_path(item, "{}/{}".format(parent_path, item.name)) else: # Single object exported, or VisualContainer with multiple objects assign_path(maptekobj_id, "{}/{}".format(parent_path, maptekobj_id.name)) if __name__ == "__main__": for file_name in maptekobj_files: file_name = os.path.join(maptekobj_path, file_name) # Import the maptekobj, providing an ObjectID as a result imported_data = io.import_maptekobj(file_name) if imported_data: store_maptekobj_objects(imported_data) else: print("Failed to import {}".format(file_name)) # Expected output: # >> Stored: scrapbook/single_object # >> Stored: scrapbook/multiple_objects(1st) # >> Stored: scrapbook/multiple_objects(2nd) # >> Stored: scrapbook/maptekobj_example
Exporting objects to a Maptek object file
Exporting data to a Maptek object file is similar to exporting a triangulation to a 00t file. However, if you need to export multiple objects into a single file, do this by first placing them in a VisualContainer.
from mapteksdk.project import Project from mapteksdk.data import io proj = Project() # Connect to default project save_path = "F:\\Python SDK Help\\data\\export.maptekobj" if __name__ == "__main__": scrapbook = proj.find_object("scrapbook") # Export the scrapbook container and any children within it export_success = io.export_maptekobj(scrapbook, save_path) if export_success: print("Exported {} to {}".format(scrapbook.path, save_path)) else: print("Failed to export {} to {}".format(scrapbook.path, save_path))