IFC Export & Import
Export
toIfc(model, meta) walks the model and returns IFC-SPF bytes.
import { toIfc } from 'brepjs-bim';
const result = await toIfc(model, {
applicationName: 'office-tool',
applicationVersion: '1.0',
author: { givenName: 'Jane', familyName: 'Doe', email: 'jane@example.com' },
organizationName: 'Example Ltd',
});
if (result.ok) await writeFile('model.ifc', result.value);- Schema: IFC4 by default; pass
ifcSchema: 'IFC4X3'to target the newer schema. - Units: specs are millimeters; the writer emits SI metres (
toIfcLengthM/toLengthMmconvert explicitly). - Owner history: author and organization metadata become a proper
IfcOwnerHistory. - Determinism: element GUIDs and local id counters are stable, and
creationTimestampdefaults to the epoch, so re-exporting an unchanged model yields byte-identical content (modulo the timestampedFILE_NAMEheader line).
toIfcValidated runs export plus the validation suite in one call and returns the bytes together with the reports.
Import
fromIfc(bytes) parses an IFC file (via web-ifc) into an ImportedModel: elements with geometry, property sets, materials, and the spatial tree.
import { fromIfc, disposeImportedModel } from 'brepjs-bim';
const imported = await fromIfc(bytes);
if (imported.ok) {
const model = imported.value;
// model.elements, model.spatialTree, model.psets, ...
disposeImportedModel(model);
}Imported geometry pins kernel memory; call disposeImportedModel when done. For header-level inspection without geometry, SpfReader parses the STEP structure directly.
Round-tripping
Export → import → compare is a first-class operation, not a demo: checkRoundTrip(bytes) re-reads an exported file and reports entity counts and losses, and the test suite gates on semantic round-trip fidelity (identity, relationships, psets, containment, and volumes within 0.5%). If you build on the families layer, GlobalIds additionally survive source-level edits: they derive from key paths, not insertion order.