Command-Line Export
This page shows how to run a create_mesh script from the command line so you
can pass parameters, build the mesh, and export it with Trimesh. This is useful
for batch runs and for stepping through mesh creation in a debugger.
Pattern: keep create_mesh UI-friendly
To keep the SCADview UI working, make sure create_mesh takes no required
parameters. You can still accept CLI arguments by adding a separate main().
import argparse
from trimesh.creation import cylinder
def create_mesh(radius: float = 10.0, height: float = 20.0):
return cylinder(radius=radius, height=height)
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("--radius", type=float, default=10.0)
parser.add_argument("--height", type=float, default=20.0)
parser.add_argument("--out", required=True, help="Output file, e.g. model.stl")
args = parser.parse_args()
mesh = create_mesh(radius=args.radius, height=args.height)
mesh.export(args.out)
if __name__ == "__main__":
main()
Run it from the command line:
python path/to/your_script.py --radius 12 --height 30 --out ./build/cyl.stl
Using Manifold or generators
- If
create_meshreturns aManifold, convert it before exporting:
from scadview import manifold_to_trimesh
mesh = manifold_to_trimesh(create_mesh(...))
mesh.export(args.out)
- If
create_meshyields intermediate meshes, export only the final one:
latest = None
for step in create_mesh(...):
latest = step
if latest is not None:
latest.export(args.out)
Debugging from the command line
Running from the CLI makes it easy to step through create_mesh with a
standard debugger:
python -m pdb path/to/your_script.py --radius 12 --height 30 --out ./build/cyl.stl
This lets you inspect variables, pause between boolean operations, and verify dimensions without launching the UI.
Debugging in VS Code
If you prefer VS Code, create or update .vscode/launch.json with a launch
profile that passes the same args:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run create_mesh script",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/path/to/your_script.py",
"args": [
"--radius",
"12",
"--height",
"30",
"--out",
"${workspaceFolder}/build/cyl.stl"
],
"console": "integratedTerminal"
}
]
}
Set a breakpoint inside create_mesh, then run the configuration from the
Run and Debug panel to step through the mesh creation.