Skip to content

STEP (.step, .stp) ​

ISO 10303-21, read through OpenCASCADE (the meshioplusplus-occt add-on wheel, pip install "meshioplusplus[occt]", and the release binaries) and written without it. The writer is a hand-off of a closed surface to CAD: a B-rep solid in the AP214 (AUTOMOTIVE_DESIGN) schema that FreeCAD, OpenCASCADE-based tools and commercial CAD systems open as a solid body. By default each flat region is one planar face with its holes as inner loops, and, on a skin segment and fit_primitives annotated, each fitted cylinder, cone, sphere and torus is one analytic face — the clean body a CAD user can select, measure, section and boolean against, where an STL import gives only an unconnected triangle soup. No CAD kernel is involved. It is the CAD end of the skin-to-CAD workflow.

Format namestep
Extensions.step, .stp
Read / Write✓ (with OpenCASCADE) / ✓
Extra dependenciesreading: OpenCASCADE 7.6 or later (the meshioplusplus-occt wheel and the release binaries; on by default from source)

Reading ​

Reading STEP means evaluating its curves and surfaces, which is a CAD kernel's job: the reader runs on the OpenCASCADE backend that fit_cad introduced (LGPL-2.1 with the OCCT exception, included in the PyPI wheels and the release CLI binaries, on by default and auto-detected in a build from source, absent from the lean WASM build; see getting OpenCASCADE and the OpenCASCADE decision). The full WASM artifact (v17.2.0) links it, so STEP and IGES read in the browser and in Node there, readMeshSelective(path, {info: true}) returning the B-rep as CAD JSON's shape. Without it, reading raises NotImplementedError (C++ Unsupported) naming the flag, and the round trip on the conformance page is checked only in a build with it. IGES is read the same way.

python
import meshioplusplus as mp

mesh = mp.read("part.step")                       # deflection 1e-3 of the bounding-box diagonal
mesh = mp.step.read("part.step", deflection=0.05, angular_deflection=0.3)
mesh = mp.step.read("part.step", heal=True)       # ShapeFix_Shape, then sewing
brep = mesh.info["brep"]                          # the faces, loops and edges as NURBS
mp.write("part.cad.json", mesh)                   # ... as Kratos CAD JSON
  • The shape. STEPControl_Reader transfers every root into one shape, which BRepBuilderAPI_NurbsConvert turns into NURBS throughout. Converting each face's surface on its own would reparametrise a cylinder or a sphere and leave its trimming curves in the old parameters; converting the whole shape keeps every parameter curve on its converted surface. Where that conversion fails, or leaves a face without a B-spline surface or with trims outside its parameter range (OpenCASCADE 7.9 does all three on some shapes), the shape is kept as it is and each surface and curve that is not a B-spline is approximated by one in its own parameters, within 1e-6 of the bounding-box diagonal; planes and lines stay exact.
  • The mesh. BRepMesh_IncrementalMesh triangulates it at deflection (a length; at most 0 takes 1e-3 of the bounding-box diagonal) and angular_deflection (radians, 0.5 by default) into one triangle block, points shared between faces welded where they coincide. Cell data: cad:kind (0), cad:index and cad:id (the face), cad:span (the knot span of the triangle's centre in the face's parameters) and cad:trimmed (0), as for CAD JSON.
  • The side channel. mesh.info["brep"] (C++ BrepInfo) holds every face's surface (degrees, knots, control net, weights; reversed faces flagged swapped_normal), its trimming loops (the outer one first, each trimming curve with its active range and direction, in the surface's own orientation) and every edge's 3-D curve and topology (the faces and trims it bounds). Faces have ids 1 .. F and edges F + 1 .. F + E, control points ids from 1, so the B-rep writes as Kratos CAD JSON that Kratos's CadIoModeler loads: a STEP model becomes Kratos IGA geometry with mp.write(...) or meshio++ convert part.step part.cad.json. Vertices are not carried. Since v17.20.0 each edge's extra holds OpenCASCADE's tolerances, {"tolerance": t, "end_tolerances": [t0, t1]} (the edge's own and its two vertices', the approximation tolerance added where the edge was approximated), which a CAD JSON write keeps and mesh_cad_surface accepts as the gaps the model allows there with model_tolerances (on by default since v19.0.0).
  • Healing. heal=True repairs the shape before it is extracted: ShapeFix_Shape (wires, faces, shells and solids), then BRepBuilderAPI_Sewing at sew_tolerance (a length; at most 0 takes 1e-5 of the bounding-box diagonal, raised to the shape's own largest tolerance but never past 1e-3 of the diagonal), which joins faces whose shared edge the file wrote twice, a little apart. A positive sew_tolerance sews without heal. What it did is the heal member of the B-rep's file-level JSON, json.loads(mesh.info["brep"]["extra"])["heal"]: healed (ShapeFix_Shape ran), fixed (it changed the shape), sew_tolerance, free_edges_before and free_edges_after (edges bounding one face, degenerate ones excluded), multiple_edges (edges sewing found shared by more than two faces) and degenerated (shapes sewing removed). Two faces whose shared edge is duplicated 1e-4 mm apart read with eight open edges and, healed, with the outer six. Healing happens at read time only; mesh_cad_surface still meshes around the defects of a model read without it.
  • Units. OpenCASCADE converts the file's length unit to millimetres (the provider pins xstep.cad.unit to MM), so the mesh is always in millimetres and states it: field_data["meshio:length_unit"] is 0.001 (length units). A part written in metres reads back a thousand times larger and in millimetres, the same physical size; transform(scale_units=0.001) takes it to metres.
  • Errors. A file OpenCASCADE cannot read, or one that transfers no shape, is a ReadError; a non-finite deflection, a non-positive angular deflection or a negative or non-finite sewing tolerance a ValueError.

C++: read_step(path) and read_step(path, info, options) (formats/step.hpp, CadReadOptions in brep.hpp, with mHeal and mSewTolerance, cad_read_has_occt()). The C API's mio_read_with_info returns a "step" handle with the mio_brep_info_* accessors, which mio_write_with_info writes as CAD JSON; mio_read_with_info2 takes a mio_cad_read_opts (deflection, angular deflection, heal, sew_tolerance), and the heal record is the MIO_BREP_FILE string. Fortran's read_with_info and Julia's and R's read_with_info take the same four options; WASM's readMeshSelective takes cadRead: {deflection, angularDeflection, heal, sewTolerance} (full artifact). Both CLIs' convert and mesh-cad-surface take --heal and --sew-tolerance T, and the MCP server's convert and mesh_cad_surface tools heal and sew_tolerance.

Writing ​

python
import numpy as np
import meshioplusplus as mp

mp.write("part.step", mp.read("part.stl"))       # one planar face per flat region
mp.write("block.stp", mp.read("block.msh"))       # a volume mesh: its skin is written

skin = mp.read("bracket.stl")
diag = np.linalg.norm(np.ptp(skin.points, axis=0))
seg = mp.segment(skin, method="primitive")        # tolerance 1e-3 of the diagonal
fit = mp.fit_primitives(seg, tolerance=1e-3 * diag, relative=False)
mp.write("bracket.step", fit)                     # planes, cylinders, cones ... as analytic faces
mp.write("bracket_facets.step", skin, faces="facet")

faces picks how facets become faces (C++ StepWriteOptions::mFaces, StepFaces):

facesFaces written
"auto" (default)"fitted" when the mesh carries segment:patch and the fit:patch_* table, else "planar".
"planar"Each edge-connected group of coplanar facets (to 1e-6 of the bounding-box diagonal) is one PLANE face; on a face with several boundary loops the one enclosing the largest area is the FACE_OUTER_BOUND and the others are holes.
"fitted"Each patch fit_primitives accepted becomes one face on its PLANE, CYLINDRICAL_SURFACE, CONICAL_SURFACE, SPHERICAL_SURFACE or TOROIDAL_SURFACE, with the parameters of the fit table; the rest of the skin as with "planar".
"facet"One PLANE face per facet, the layout of the writer before v17.9.0 (byte-identical to it).

tolerance ("fitted" only) is how far a patch's points may lie from its surface, as a length; at most 0, the default, takes three times the largest fit:patch_tolerance of an accepted patch, or 1e-3 of the bounding-box diagonal when there is none.

What is written ​

  • The surface. triangle, quad and polygon blocks (quadratic surface cells contribute their corners); when the mesh has volume cells, the skin of those, as the stl writer takes it. Lines and vertices beside them are dropped with a warning; a mesh of lines alone is written as curves.
  • Faces. Each face is an ADVANCED_FACE bounded by EDGE_LOOPs of ORIENTED_EDGEs between VERTEX_POINTs. An edge two faces share is one EDGE_CURVE, used once in each direction, so the shell is topologically closed and needs no sewing. With "facet", a facet of four or more corners that is not planar to 1e-9 of its size is fanned into triangles from its first corner, so every face lies exactly on its plane; a merged planar face takes the plane of its first facet. An analytic face's same_sense follows the facets' normals.
  • Edges. The mesh edges between two faces form chains from one corner (a point where three or more faces meet) to the next; a closed chain is split at its point farthest from its start. Between two planar faces a chain becomes the straight LINEs of its Douglas-Peucker corners, so the collinear points of the mesh disappear. Beside a curved analytic face a chain is a CIRCLE when it lies within the tolerance of one about the surface's axis (the rim of a bore, a cone's base), a LINE when it is straight (a cylinder's ruling), and otherwise a degree-1 B_SPLINE_CURVE_WITH_KNOTS through its points. A mesh point on analytic faces only is first moved onto them (alternating projections), when that moves it less than the tolerance.
  • Periodic faces. A cylinder, cone, sphere or torus face has one bound per boundary loop and no seam edge, as ISO 10303-42 allows; a reader adds its seams. A whole sphere or torus, with no boundary at all, is split in two faces by a plane through its centre.
  • Demotion. An accepted patch with a point further than the tolerance from its surface, or whose boundary does not close into loops, is written as planar faces instead and counted; nothing is silently wrong.
  • One solid per piece. Every edge-connected piece of the surface is a CLOSED_SHELL inside a MANIFOLD_SOLID_BREP; they are collected in one ADVANCED_BREP_SHAPE_REPRESENTATION under the usual product structure (PRODUCT, PRODUCT_DEFINITION, SHAPE_DEFINITION_REPRESENTATION). A piece wound inwards (negative signed volume) is written reversed, with a warning, so every solid has positive volume. A surface nested inside another (a void) becomes a second solid, not a cavity.
  • Units. The mesh's length unit, field_data["meshio:length_unit"]: metres, centimetres, millimetres, micrometres and kilometres as an SI_UNIT of the metre, any other unit as a CONVERSION_BASED_UNIT defined on the millimetre (named INCH, FOOT, or LENGTH UNIT). A mesh without the key is written in millimetres, as before. The length uncertainty is 1e-7 of that unit. Coordinates are written as they are: they are not converted.

The roadmap item that queued this writer described the faces as ADVANCED_FACEs with POLY_LOOP bounds. That combination is not valid AP214, since an ADVANCED_FACE must be bounded by EDGE_LOOPs; the writer emits the edge-loop form, which is also what lets the faces share edges.

Curves ​

A mesh whose cells are all lines (and vertices) is written as curves (roadmap 7.6.5): one GEOMETRIC_CURVE_SET in a GEOMETRICALLY_BOUNDED_WIREFRAME_SHAPE_REPRESENTATION, which CAD tools import as sketch geometry to build on.

  • A sketch. A mesh carrying a fit_curves sketch (the sketch:* field data) is written as its pieces, the set named sketch: a line as a TRIMMED_CURVE of a LINE (a unit direction, trimmed at 0 and its length), an arc as a TRIMMED_CURVE of a CIRCLE whose axis is the sketch plane's normal (reversed for a clockwise arc, so every trim runs counter-clockwise, in radians), and a full circle as a CIRCLE.
  • Any other line mesh (a chained section, a silhouette) is chained and each chain written as a POLYLINE, a closed one repeating its first point, the set named sections.

OpenCASCADE reads the sketch of a slot as two lines and two circular arcs, and a silhouette's circles as circles (tests/python/test_step_elements.py). The Python reference writes solids only; the curves are the C++ core's.

Elements ​

write_step_elements(path, mesh, patches=None, segments=64) writes the primitives fit_primitives fitted (a mesh carrying segment:patch and the fit:patch_* table) as geometry a CAD user can snap to, exact and with no CAD kernel (roadmap 7.6.5):

Fitted typeWritten as
planea PLANE face bounded by the convex hull of the patch's points in the plane, one SHELL_BASED_SURFACE_MODEL each
spherea ball: one SPHERICAL_SURFACE face bounded by a vertex loop at its south pole, the form OpenCASCADE writes
cylindera solid with flat lids over the patch points' extent along the axis: a CYLINDRICAL_SURFACE and two PLANE faces with CIRCLE rims
conethe frustum the points span (from the apex when they reach it), lidded the same way, on a CONICAL_SURFACE
torusthe whole torus on a TOROIDAL_SURFACE, split in two faces by the writer's seams

Cylinders, cones and tori go through the fitted B-rep writer above: a tessellation of segments facets around, whose faces it writes as the exact surfaces and whose rims it recognises as circles. A torus whose tube reaches its axis is skipped with a warning. Solids are MANIFOLD_SOLID_BREPs in an ADVANCED_BREP_SHAPE_REPRESENTATION; when planes are written too, both representations are tied to the product's SHAPE_REPRESENTATION by SHAPE_REPRESENTATION_RELATIONSHIPs. patches writes only the listed patch labels, and an unknown label is refused. The report gives num_planes, num_spheres, num_cylinders, num_cones, num_tori, num_skipped and warnings.

OpenCASCADE reads a fitted cylinder of radius 2 and length 5 as one valid solid of volume 20 pi to 1e-9, a fitted sphere as a ball of the exact volume, and a cone, torus and bounded plane as valid shapes (tests/python/test_step_elements.py, when OCP is importable). C++ core only. Surfaces: Python meshioplusplus.write_step_elements, both CLIs (step-elements IN OUT [--patches 1,2] [--segments N] [--json]), C mio_write_step_elements, Fortran, Julia, R, Octave/MATLAB, WASM writeStepElements and the MCP tool write_step_elements.

Refusals ​

The writer refuses, with a WriteError, anything that is not the boundary of a solid:

  • an open, non-manifold or inconsistently wound edge — the message gives the counts and names the first five as point-id pairs; run repair first;
  • a degenerate facet (zero area), or an edge between two coincident points (run clean first);
  • a non-finite coordinate, or a mesh with no surface facets and no lines.

C++ vs Python ​

The Python reference writes faces="facet" only: without the core, "auto" falls back to it with a warning and "planar" or "fitted" raise NotImplementedError. In that mode the C++ core and the Python reference write identical bytes: entity ids are sequential, every number is written with %.17g (with the decimal point STEP requires, 3. and 1.E-05), the header time stamp is fixed at 1970-01-01T00:00:00, and the provenance lines go in a /* ... */ comment after ISO-10303-21;. FILE_NAME and PRODUCT carry the file's basename.

Validation ​

Checked with OpenCASCADE 8.0.1 (the cadquery-ocp 8.0.1.1 wheels): STEPControl_Reader reads every file tests/python/test_step.py writes — a subdivided cube, an inward-wound cube, two disjoint cubes, a tetrahedron's skin, a box with one warped (fanned) quad, a polygon-block cube and a torus — as the expected number of solids, with faces="facet" and "planar" alike, BRepCheck_Analyzer finds each valid, and GProp gives the mesh's own volume to 1e-9. With "fitted", a CAD-style bracket reads back as one valid solid of twelve planes and four cylinders with its exact volume, and a filleted plate as eight faces. The test runs when OCP is importable (pip install cadquery-ocp) and skips otherwise. FreeCAD has not yet been checked directly; it reads STEP through the same OpenCASCADE reader. The reader is checked on the backend's own build (OpenCASCADE 7.6, the CI occt leg): a written box reads back as its faces, each trimmed by one loop and every edge bounding two of them, and its CAD JSON rewrite samples back onto the box (test_step.py, tests/cpp/test_cad_read.cpp).

Not supported ​

  • Reading without the OpenCASCADE backend (see above), and a reader's vertices (STEP's VERTEX_POINTs are carried as edge ends only).
  • Trimmed freeform, fillet and thread faces: what no plane, sphere, cylinder, cone or torus explains stays planar faces here. fit_cad builds B-spline, fillet and thread faces through OpenCASCADE, and its kernel-free backend="native" is this writer.
  • Colours, layers, assemblies, and AP242 product manufacturing information.

The NURBS B-rep a STEP file reads into mesh.info["brep"] can be refined, evaluated and sampled exactly with the isogeometric layer (iga_refine, iga_evaluate, iga_sample); STEP files themselves are not written from a refined B-rep, but mp.write("refined.cad.json", refined) is. mesh_cad_surface triangulates the same B-rep at a target edge size, conforming across faces, in place of BRepMesh's deflection-driven mesh.

Released under the MIT License.