Quick Start¶
This guide gets you productive with numpy-stl in under 5 minutes.
Loading an STL File¶
from stl import mesh
your_mesh = mesh.Mesh.from_file('model.stl')
print(f'{len(your_mesh)} triangles')
Format detection (ASCII vs binary) is automatic.
Creating a Mesh from Scratch¶
import numpy as np
from stl import mesh
# Create a single triangle
data = np.zeros(1, dtype=mesh.Mesh.dtype)
data['vectors'][0] = [[0, 0, 0], [1, 0, 0], [0, 1, 0]]
triangle = mesh.Mesh(data)
triangle.save('triangle.stl')
Inspecting Properties¶
from stl import mesh
m = mesh.Mesh.from_file('model.stl')
# Vertex data
print('First vertex of each triangle:', m.v0[:3])
print('Bounding box:', m.min_, m.max_)
print('Surface areas:', m.areas[:3])
Basic Transformations¶
import math
from stl import mesh
m = mesh.Mesh.from_file('model.stl')
# Rotate 90 degrees around the Z axis
m.rotate([0, 0, 1], math.radians(90))
# Translate by [10, 0, 0]
m.translate([10, 0, 0])
m.save('transformed.stl')
Saving in Different Formats¶
import stl
from stl import mesh
m = mesh.Mesh.from_file('model.stl')
# Save as binary (default, smaller file)
m.save('output.stl')
# Save as ASCII (human-readable)
m.save('output.stl', mode=stl.Mode.ASCII)
Next Steps¶
Reading and Writing STL Files – Full I/O documentation
Mesh Operations – Rotations, translations, combining meshes
Mesh Properties – Mass properties, convexity, surface area
Command-Line Tools – Command-line tools