MeshLib
 
Loading...
Searching...
No Matches
Python overview

Python is one of the most popular and widely used programming language in scientific researches, machine learning, data analysis and advanced testing.

Distribution Python version
Windows x64 3.10
Ubuntu 20 x64 3.8
Ubuntu 22 x64 3.10
Fedora 35 x64 3.11
pip install meshlib 3.8 - 3.12

MeshLib library allows you to call python scripts directly from the command line or use particular functions by from meshlib import mrmeshpy.

Usage

On Windows: path to the directory that contains MeshLib python modules (mrmeshpy.pyd, mrmeshnumpy.pyd ...) should be added to python before importing the modules

import sys
sys.path.append('path_to_modules_directory')

MeshLib provides several usage options

  1. Directly from system python
    from meshlib import mrmeshpy
    try:
    mesh = mrmeshpy.loadMesh("mesh.stl")
    except ValueError as e:
    print(e)
    # ...
    # some mesh modifications can be perform here
    # ...
    mrmeshpy.saveMesh(mesh, "mesh.ply")
  2. Run script from c++ code
    MR::runScript("script.py"); // or MR::runString( stringWithScript )

Exposing

You can expose your c++ functions and classes to python

#include "MRPython.h"
void pythonExample( float arg )
{
doSomething(arg);
}
//init sould be called only once for each module
MR_INIT_PYTHON_MODULE( moduleName )
MR_ADD_PYTHON_FUNCTION( moduleName, examplePythonFunc, pythonExample);
#define MR_ADD_PYTHON_FUNCTION(moduleName, name, func, description)
Definition MRPython.h:27
#define MR_INIT_PYTHON_MODULE(moduleName)
Definition MRPython.h:14

Functions MeshLib/python_scripts folder contain scripts which could be used as examples for developers or testers. Python library allows to list all mrmeshpy.* functions with standart print(dir(mrmeshpy)) call. You can list all available python functuins by running python MeshLib/python_scripts/functions_list.py

Note
Not all functions are available anytime, for example functions that triggers rendering are not available in direct python call, but available with executable run