Advanced Automation with MeshInspector and MeshLib

The Python API is designed not only for one-off scripting but also for connecting MeshInspector to larger 3D data pipelines, batch processes, and MeshLib SDK automation.
Updated over 2 weeks ago

Overview

Once you know how to control MeshInspector’s UI and work with meshes programmatically, you can begin building automated workflows.
The Python API is designed not only for one-off scripting but also for connecting MeshInspector to larger 3D data pipelines, batch processes, and MeshLib SDK automation.

This final article in the series explains:

  • How to combine UI and geometry commands into reusable scripts

  • How to automate multi-step operations such as repair and export

  • How to connect with the MeshLib SDK for advanced geometry processing

  • Where to find official API documentation and examples

Chaining Commands into Workflows

Automation in MeshInspector often involves chaining multiple API actions:

  1. Load geometry

  2. Add it to the scene

  3. Open the relevant tab or tool

  4. Adjust parameters

  5. Run the operation

  6. Export the results

Below is an example of a complete automated repair pipeline.

from meshlib import mrmeshpy as mm
from meshlib import mrviewerpy as mv
import time

def wait_progress_bar():
mv.Viewer().skipFrames(2)
while any(elem.name == "ProgressBar" for elem in mv.uiListEntries([])):
time.sleep(0.2)

def automated_repair(input_path, output_path, mesh_name="Mesh"):
# Load and display the mesh
mesh = mm.loadMesh(input_path)
mv.addMeshToScene(mesh, mesh_name)
mv.Viewer().preciseFitDataViewport()
mv.selectByName(mesh_name)

# Open the Mesh Healer tool
mv.uiPressButton(['RibbonTabs', 'Mesh Repair'])
mv.Viewer().skipFrames(1)
mv.uiPressButton(['Ribbon', 'Mesh Healer'])
wait_progress_bar()
mv.Viewer().skipFrames(1)

# Execute the repair
mv.uiPressButton(['Mesh Healer', 'Repair Selected'])
wait_progress_bar()
mv.Viewer().skipFrames(1)

# Export the repaired mesh
selected = mv.getSelectedMeshes()
mm.saveMesh(selected[0], output_path)
print(f"Repaired mesh saved to: {output_path}")

# Example usage
automated_repair(
input_path="C:/Data/Dolphin_original.stl",
output_path="C:/Data/Dolphin_original.obj",
mesh_name="Dolphin"
)

This script performs a complete load–repair–export cycle automatically, suitable for processing multiple files or datasets.

Batch Processing Multiple Files

You can use Python’s file system utilities to process many meshes in sequence.

import os
from meshlib import mrmeshpy as mm
from meshlib import mrviewerpy as mv

input_folder = "C:/Data/Models/Input"
output_folder = "C:/Data/Models/Output"

for filename in os.listdir(input_folder):
if filename.endswith(".stl"):
name = os.path.splitext(filename)[0]
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, name + "_healed.obj")

mesh = mm.loadMesh(input_path)
mv.addMeshToScene(mesh, name)
mv.selectByName(name)

mv.uiPressButton(['RibbonTabs', 'Mesh Repair'])
mv.Viewer().skipFrames(1)
mv.uiPressButton(['Ribbon', 'Mesh Healer'])
wait_progress_bar()
mv.Viewer().skipFrames(1)
mv.uiPressButton(['Mesh Healer', 'Repair Selected'])
wait_progress_bar()
mv.Viewer().skipFrames(1)

selected = mv.getSelectedMeshes()
mm.saveMesh(selected[0], output_path)
print(f"Processed: {name}")

Tip:
For large batches, it’s recommended to periodically clear the scene or restart the viewer to manage memory usage.

Integrating with MeshLib SDK

MeshInspector is powered by MeshLib, which provides the same geometric operations as a standalone C++ and Python SDK.
Using MeshLib directly allows deeper access to algorithms for repair, remeshing, simplification, and more — beyond what’s exposed in the Ribbon UI.

The SDK provides both low-level geometry manipulation and high-level helpers that can be combined with the viewer commands.

Example: Simplify a Mesh Using MeshLib

from meshlib import mrmeshpy as mm

# Load mesh directly through MeshLib
mesh = mm.loadMesh("C:/Data/Dolphin_original.stl")

# Apply simplification
settings = mm.DecimateSettings()
settings.maxError = 0.05
mm.decimateMesh(mesh, settings)

# Save the result
mm.saveMesh(mesh, "C:/Data/Dolphin_simplified.obj")

This example uses the same mrmeshpy module as the viewer but bypasses the UI entirely, calling MeshLib’s computational API directly.

When to Use the SDK

Use the SDK when you need:

  • More precise control over algorithm parameters

  • Access to non-UI functions such as Boolean operations or curvature analysis

  • Integration into external applications or headless processing scripts

Documentation and Examples

For a full list of available functions and detailed examples, see the official MeshLib documentation:

These resources provide in-depth coverage of mesh manipulation, SDK-level geometry operations, and advanced scripting techniques.

Best Practices for Automation

  • Use clear naming for meshes and files to avoid overwriting results.

  • Validate file paths before loading or saving data.

  • Always call skipFrames(1) after pressing UI buttons to keep the viewer synchronized.

  • Combine UI and SDK calls for the best balance between interactive control and algorithmic power.

  • Test scripts interactively in the Python console before automating large batches.

Summary

You now know how to:

  • Build complete automated workflows combining MeshInspector’s UI and MeshLib geometry functions

  • Process multiple files in batch scripts

  • Extend automation with the MeshLib SDK

  • Access official API documentation and examples for deeper use

This concludes the MeshInspector Python API series.

With these concepts, you can now script any operation — from UI automation to mesh analysis — and integrate MeshInspector directly into your 3D data pipelines.

Table of Contents