Describes a part taken from another document, typically one loaded from STEP, so its whole label tree with sub-assemblies, names and colors is copied into the new assembly.
sourceDocumentIndex points into the sourceDocuments list given to
buildAssemblyDocument, and sourceLabel picks a sub-tree instead of the whole document.
Instance nodes place it by partId like any part.
The part id, the index of the source document, an optional source label, name and color
The imported part definition, ready for combineStructure
const chairDoc = await bitbybit.occt.assembly.manager.loadStepToDoc({ stepData });
const chair = await bitbybit.occt.assembly.manager.createImportedPart({ id: "chair", sourceDocumentIndex: 0, name: "Chair" });
const c1 = await bitbybit.occt.assembly.manager.createInstanceNode({ id: "c1", partId: "chair", name: "Chair 1", translation: [0, 0, 0] });
const c2 = await bitbybit.occt.assembly.manager.createInstanceNode({ id: "c2", partId: "chair", name: "Chair 2", translation: [500, 0, 0] });
const structure = await bitbybit.occt.assembly.manager.combineStructure({ parts: [], nodes: [c1, c2], loadedParts: [chair], clearDocument: false });
const doc = await bitbybit.occt.assembly.manager.buildAssemblyDocument({ structure, sourceDocuments: [chairDoc] });
Describes a part for an assembly structure: an id to reference it by, its shape, a name and an optional color.
Nothing is built yet; the part only becomes real when a structure holding it goes through
buildAssemblyDocument. Instance nodes place the part by its id, as many times as needed.
The part id, its shape, its name and an optional color
The part definition, ready for combineStructure
Describes an assembly node, a container that groups instances and other assemblies in the hierarchy.
parentId names the assembly it sits in; leave it out for a root. An optional matrix places
the whole group.
The node id, its name, an optional parent id, an optional color and an optional placement matrix
The node definition, ready for combineStructure
Describes an instance node, one placement of a part: which part by partId, where it goes
and under which assembly.
translation moves it, rotation turns it by Euler angles in degrees about X, Y and Z,
scale sizes it uniformly; a matrix can replace all three. The same part may be placed by
many instances.
The node id, the part id, the name, an optional parent id and the placement
The node definition, ready for combineStructure
Describes a change to a part that already exists in a document: a new shape, a new name or a new color, or any mix of them, addressed by the part's label.
Collect the updates in combineStructure under partUpdates and pass the structure to
buildAssemblyDocument with the existing document.
The label of the part and the optional new shape, name and color
The update definition, ready for combineStructure
const parts = await bitbybit.occt.assembly.query.getDocumentParts({ document: doc });
const bigger = await bitbybit.occt.shapes.solid.createBox({ width: 20, length: 20, height: 20, center: [0, 0, 0] });
const update = await bitbybit.occt.assembly.manager.createPartUpdate({ label: parts[0].label, shape: bigger, name: "Bigger Box" });
const structure = await bitbybit.occt.assembly.manager.combineStructure({ parts: [], nodes: [], partUpdates: [update], clearDocument: false });
await bitbybit.occt.assembly.manager.buildAssemblyDocument({ structure, existingDocument: doc });
Gathers parts, nodes and, for updates, removals, part updates and imported parts into one
structure definition, the last step before buildAssemblyDocument.
clearDocument false keeps what an existing document already holds when the structure is
applied to it.
The parts, the nodes, and the optional removals, part updates, imported parts and clear flag
The structure, ready to build
Builds an assembly document from a structure, or applies the structure to an existing document.
With existingDocument the labels in removals are dropped first, the partUpdates
applied, then the new parts and nodes added; a structure with neither clears the document
unless clearDocument is false. sourceDocuments supplies the documents imported parts copy
from. The document stays in memory until deleted.
The structure, an optional document to update and the optional source documents
The document handle, new or updated
const structure = await bitbybit.occt.assembly.manager.combineStructure({ parts: [part], nodes: [root, first], clearDocument: false });
const doc = await bitbybit.occt.assembly.manager.buildAssemblyDocument({ structure });
const glb = await bitbybit.occt.assembly.manager.exportDocumentToGltf({ document: doc, meshDeflection: 0.1, meshAngle: 0.5, internalVerticesMode: false, controlSurfaceDeflection: false, mergeFaces: false, forceUVExport: false, fileName: "assembly.glb", tryDownload: false });
Loads a STEP file into a new assembly document, with its parts, sub-assemblies, names, colors and placements.
stepData is the file as text or binary; gzip-compressed STEP-Z is accepted too. A file that
cannot be loaded throws. An instance the file leaves unnamed, as SolidWorks does, is named
after the part it places, numbered when that part repeats beside it.
The STEP file content
The document handle
Writes an assembly document as a STEP file with its hierarchy, names and colors, and returns the file's bytes.
author and organization go into the file header; compress writes gzip-compressed STEP-Z
instead. Failure throws an error.
The document, the file name, the header details, the compression flag and the download option
The STEP file as bytes
Triangulates an assembly document and writes it as a binary glTF (GLB) with the hierarchy, names and colors kept as glTF nodes and materials.
meshDeflection and meshAngle set how finely curved surfaces are triangulated;
mergeFaces joins the faces of a part into one mesh. Failure throws an error.
The document, the meshing settings, the export flags, the file name and the download option
The GLB file as bytes
Writes an assembly document as a binary glTF (GLB) like exportDocumentToGltf and compresses
the geometry with Draco, which makes the file much smaller at the cost of a Draco-capable
loader.
The Draco settings set the compression level and how many bits positions, normals, texture coordinates and colors keep.
The document, the meshing settings, the export flags and the Draco settings
The GLB file as bytes
Deletes an assembly document and frees the memory it holds.
A document built with buildAssemblyDocument or loaded with loadStepToDoc stays in memory
until this is called, so delete it once its shapes and exports have been read.
The document to delete
Nothing; the document handle is no longer valid afterwards
const doc = await bitbybit.occt.assembly.manager.buildAssemblyDocument({ structure });
const glb = await bitbybit.occt.assembly.manager.exportDocumentToGltf({ document: doc, meshDeflection: 0.1, meshAngle: 0.5, internalVerticesMode: false, controlSurfaceDeflection: false, mergeFaces: false, forceUVExport: false, fileName: "assembly.glb", tryDownload: false });
await bitbybit.occt.assembly.manager.deleteDocument({ document: doc });
Colors a label of a document, a part, instance or assembly, with red, green, blue and alpha from 0 to 1.
The color is kept when the document is exported to STEP or glTF.
The document, the label and the four color channels
True when the color was set
Renames a label of a document, a part, instance or assembly.
The document, the label and the new name
True when the name was set
Building and changing assembly documents: describe parts, assembly nodes and instance nodes one object at a time, combine them into a structure, and build a document from it; or load a STEP file into a document. Then recolor and rename labels, update or remove parts, and export to STEP or glTF. A document is an in-memory handle that stays alive until it is deleted, so build once and query or export as often as needed.