Interoperability · STEP AP242 domain-model XML
AP242 XML — the structure, without the geometry
AP242 has two implementation forms of one information model. The Part-21
file (.stp) is the one every CAD system opens; the domain-model XML
(ISO 10303-4442) is the one PLM and PDM systems exchange when the assembly
structure is the payload — product identity, versions, views, the usage graph and its
placements. NativeCAD writes both. This page is the XML form: one .xml plus one
Part-21 .stp per part, wired together by AP242's external element reference.
.stp beside it, reached through
an ExternalGeometricModel → DigitalFile → Uri chain. A
consumer that wants shapes follows the URIs; a PLM system that only wants the bill of structure
never parses a B-rep at all.Export — cad_export_body format:"ap242-xml"
One call writes the whole deliverable. The .xml goes to the path you name, and one
Part-21 .stp is written beside it for every part that owns geometry, named
<xml stem>_<part>.stp. Every file written is reported back on
partPaths, and every one of them is referenced by a Uri inside the XML —
the same idea as glTF's single binPath, for N files instead of one. The response also
carries products, instances, parts (those with a shape) and
the profile string, so a caller can assert on the structure it just wrote without
re-reading the file.
What the document emits is the MBx-IF assembly-structure profile's vocabulary
(rec_prac_ap242xml_assy_struct v3.2): Part / PartVersion /
PartView — the domain model's names for PRODUCT /
PRODUCT_DEFINITION_FORMATION / PRODUCT_DEFINITION — plus one
NextAssemblyUsageOccurrence per component instance, each carrying its relating and
related view references, a reference designator and an Axis2Placement3D. Every object
carries a uid and every link is a uidRef to one, so the file is a flat,
order-independent object graph that reads in a single pass.
| Option | Kind | What it does |
|---|---|---|
transforms | behavior | Per-instance placements. A solved mate set's poses land on the component instances'
Axis2Placement3D in the XML exactly as they land on
ITEM_DEFINED_TRANSFORMATION in the Part-21 form — the same argument, the same
input, the other serialization. |
multi-file output (partPaths) | behavior · automatic | The export is 1 .xml + N .stp. The part files are written for you, scoped
to that part's own solids and named for the part, so each one opens as the component the XML
says it is. |
| assembly gate | behavior · automatic | A document with no product structure is refused by name — see below. |
of | skips translation | Scope the export to named bodies instead of the whole document — the same body addressing every other format takes. |
A single body is a part, not an assembly of one
The MBx-IF assembly-structure profile describes an assembly, and the objects that carry its information are the component instances. A document holding one bare body has none — so exporting it would mean inventing a product a PLM system was never told about. NativeCAD refuses instead:
| Refusal | Error | When |
|---|---|---|
AP242XML_NO_PRODUCT_STRUCTURE | E_PRECONDITION |
The document carries no component instances. The message counts the product definitions
and bodies it actually found, and the hint names the way out: export the part with
format:"step" (or "x_t"/"sat"), or build the rest of
the assembly first — two or more named bodies in one document produce the structure this
format writes. |
AP242XML_STRUCTURE_UNREADABLE | E_INTERNAL |
The product-structure scan threw on the document's own STEP serialization. Reported as an internal fault rather than a bad file, because at that point both sides are ours. |
This is the third time the kernel has ruled the same way on the same question, in the same words:
the STEP writer refuses to wrap a single body in a root product and a usage occurrence, and
cad_assembly_import refuses a zero-occurrence file rather than report an "assembly of
one". A fabricated answer is worse than a named refusal.
Where the structure comes from
A session document is a set of bodies; it has no product-structure graph of its own, and an import deliberately flattens one. The component that knows how this kernel groups bodies into parts is the STEP writer itself — so the XML export asks it. The writer emits the named scaffold it would write anyway, the geometry-free product-structure scan reads that text straight back, and the resulting instance tree is what gets serialized. No B-rep is built for the scan, no second parse happens, and there is exactly one definition of "what a part is" in the kernel rather than two that can drift apart.
The writer itself has no dependencies at all — no XML library (the document is hand-built, with escaping applied at every text and attribute boundary) and no kernel imports, so it accepts any object with the product-structure shape: the real thing, a subtree of one, or a test fixture.
What is pinned, and what is not
There is no AP242 XSD in this repository and no XML validator in this dependency set. What the
test suite pins is well-formedness and a full structural round trip
— re-read the XML, rebuild the instance tree, compare names, counts and transforms against the
product structure it came from, and re-import every referenced .stp. The element
vocabulary follows the recommended practice's conventions; schema-validating it against the published
ISO 10303-4442 schemas and running the MBx-IF test rounds is the remaining, external step, and
nothing here claims otherwise.
Export only: there is no XML reader. XML import is rare in the wild, and the roadmap says so rather than pretending the spoke is bidirectional.
Try it
The same kernel-authored mounting plate, this time as an assembly: two instances of one
part, stacked 20 mm apart. The XML carries one Part and two
NextAssemblyUsageOccurrences whose placements differ only in Z; the geometry is written
once, in the .stp the XML points at.
AP242 XML nativecad-plate-stack.xml 3.1 KB PART 21 nativecad-plate-stack_mounting_plate.stp 17 KB
Download both into the same directory — the Uri in the XML is relative,
exactly as the format intends. The referenced .stp re-imports to the
same plate, exactly (12,293.8009 mm³): 1 solid, one face per cylinder wall — 15 faces,
34 edges, where the source STEP carries each wall as two seamed halves (20 faces, 54 edges).