Example Scripts

Creating a marker

Marker objects are complex 3D representations of mining assets. They are regularly used to represent spatial points of interest, or can be used to model equipment as part of mine planning and scheduling.

Marker objects can have associated attributes and per-facet colouring to further enhance their representation in the view.

The following example will create a marker in the view. The Extend Python Script is set up so you can customise the marker text and container location as inputs.

To create this example.

  1. Make sure you have met all the pre-workflow requirements here.

  2. Download the script here.

  3. Open the Workflow Editor.

  4. Drag and drop the script into the Editing Area of the Workflow Editor.

  5. Add a View Selection component by navigating to PointStudio > Home > View Selection. Add the View Selection component to the workflow after the Extend Python Script component. The workflow should look like this:

  6. Run the workflow.

Cloning Objects

The following script makes use of an input connector of type WorkflowSelection to receive a selection of objects from another component. It then creates a copy of all of the objects in the selection. You will need to add this component to a workflow using the Workflow Editor.

from mapteksdk.workflows import WorkflowArgumentParser, WorkflowSelection
from mapteksdk.project import Project

parser = WorkflowArgumentParser(description="Copy objects")

# Declaring an input connector will make it appear when a script
# is dragged and dropped onto a workflow.
parser.declare_input_connector("selection", WorkflowSelection,
                               connector_name="Selection",
                               description="Objects to duplicate")
 
parser.declare_output_connector("output", WorkflowSelection,
                                connector_name="Output",
                                description="Duplicated Objects")
 
parser.parse_arguments()
 
# IMPORTANT: Project() should always be called after parse_arguments().
project = Project()
 
duplicates = []
# Iterate over the objects in the selection.
for oid in parser["selection"]:
  # Extract the name of the object from the path.
  # ie: If "cad/line 7" then name would be set to: "line 7"
  name = oid.path.split("/")[-1]
  number = 0
  found = False
  # Find a unique name for the new object.
  while found is not None:
    copy_path = f"duplicate {number} of {name}"
    found = project.find_object(copy_path)
    number += 1
 
  # Duplicate the object.
  duplicate = project.copy_object(oid, copy_path)
  # Add the duplicated object to the list.
  duplicates.append(duplicate)
 
# Call set_output to send the value to the output connector.
parser.set_output("output", duplicates)

To run the above script in the Workflow Editor:

  1. Copy the above script into an empty file and save it.

  2. Drag and drop the script into the Workflow Editor.

  3. Add a Get Active Selection component by navigating to PointStudio > Context Menu > Get Active Selection. Add the component before theExtend Python Script component.

  4. Your workflow should look like this:

  5. Make a selection in the Data Explorer and then run the workflow.