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, removals go first, then partUpdates, then new parts and nodes;
with neither, the document is cleared unless clearDocument is false. sourceDocuments feeds
imported parts; a placed root assembly goes under a top "Assembly". 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: true, 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
const doc = await bitbybit.occt.assembly.manager.loadStepToDoc({ stepData: stepText });
const parts = await bitbybit.occt.assembly.query.getDocumentParts({ document: doc });
const options = bitbybit.draw.optionsOcctDocument({ drawAnnotations: true });
const drawn = await bitbybit.draw.drawAnyAsync({ entity: doc, options });
Loads a glTF file into a new assembly document, with its hierarchy, names and colors, the meshes becoming faces that carry triangles.
gltfData is a binary .glb or a .gltf with its buffers embedded; the file's header tells
which. glTF's Y-up becomes the document's Z-up, as exportDocumentToGltf writes it, and a file
that holds no mesh is refused.
The glTF file
The document handle
Loads an OBJ file into a new assembly document, its meshes becoming faces that carry triangles, named as the file names them.
Coordinates are taken as they are, since OBJ has no agreed up axis. A material library the file names is not read, and a file that holds no mesh is refused.
The OBJ file
The document handle
Writes an assembly document as a STEP file with its hierarchy, names and colors, and returns the file's bytes.
compress writes gzip-compressed STEP-Z. A document holding dimensions, datums or tolerances is
written as STEP AP242 with them and their pictures, those of each part in that part's own
context and units.
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. With the document's unit, the file is
in metres, glTF's own unit.
The document, the meshing settings, the export flags, the unit, 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
Triangulates an assembly document and writes it as OBJ, returning the file's text and the
text of the material library its mtllib line names.
The file name without its extension names the library, which holds the parts' colors and is
empty for a document without any. Coordinates keep six decimals. meshDeflection sets how
finely curved surfaces are triangulated.
The document, the meshing tolerance, the file name and the download option
The OBJ text and the material library text
Triangulates an assembly document and writes it as ASCII PLY with a normal per vertex and the parts' colors, returning the file's text.
Coordinates keep six significant digits, so a model more than about 1000 units across loses
detail below 0.01. meshDeflection sets how finely curved surfaces are triangulated.
The document, the meshing tolerance, the file name and the download option
The PLY file as text
Deletes an assembly document and frees the memory it holds.
A document built with buildAssemblyDocument or loaded with loadStepToDoc stays in memory
until deleted; deleting it deletes the documents its changes made too, and deleting one of
those, such as setDocLabelColor answers, frees that one alone, which is made again when read.
The document to delete
Nothing; a document deleted with every change made from it can no longer be read
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: true, 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.
It answers the colored document, which an export or a read given it shows, STEP and glTF
included. A label that names no part, instance or assembly of the document is refused;
setDocLabelColors colors many labels in one change.
The document, the label and the four color channels
The colored document
Renames a label of a document, a part, instance or assembly.
It answers the renamed document, which an export or a read given it shows. A label that names
no part, instance or assembly of the document is refused; setDocLabelNames renames many
labels in one change.
The document, the label and the new name
The renamed document
BetaColors many labels of a document, parts, instances or assemblies, with one color in one change.
It answers the colored document as setDocLabelColor does, one change for the whole list. A
label that names no part, instance or assembly is refused before any is colored; an empty
list answers the document as it was.
The document, the labels and the four color channels
The colored document
BetaRenames many labels of a document, parts, instances or assemblies, in one change.
names holds each label's new name, in the order of labels. A label that is no part,
instance or assembly, a name that is not text, a count unlike the labels' or a label given two
names is refused before any is renamed.
The document, the labels and the new name of each
The renamed document
BetaDescribes one shape of a part for a dimension, datum or tolerance: the part's label and which face, edge or vertex of it.
Faces, edges and vertices count from 0 as shapes.face.getFace, shapes.edge.getEdge and
shapes.vertex.getVertices count them on the part's shape, which assembly.query.getShapeFromLabel
reads; kind part means the whole part.
The part's label, whether a face, edge, vertex or the whole part is meant, and its index
The shape, ready for the shapeRefs of createPmiDimension, createPmiDatum and createPmiTolerance
BetaDescribes a dimension for addDocumentPmi: what it states, its value and tolerance, the
shapes it measures, and where its picture is drawn.
With start and end the picture is drawn as io.drawing.dimensionPicture draws it, in the
plane normal faces, in the part's own axes; a presentation replaces it. Nothing is written
until addDocumentPmi.
The type, the value, the tolerance, the shapes and how the picture is drawn
The dimension, ready for addDocumentPmi
const thickness = await bitbybit.occt.assembly.manager.createPmiDimension({
type: Bit.Inputs.OCCT.pmiDimensionTypeEnum.linearDistance, value: 15, upperTolerance: 0.1, lowerTolerance: 0.1,
shapeRefs: [{ part: "0:1:1:1", index: 5 }], otherShapeRefs: [{ part: "0:1:1:1", index: 4 }],
start: [30, 0, 15], end: [30, 0, 0], normal: [0, -1, 0], offset: 12,
});
BetaDescribes a datum for addDocumentPmi: its letter and the shapes it is taken from.
A tolerance in the same call must refer to it by letter, as a STEP file keeps a datum only
through its tolerances. A letter names one datum in a document, given again only on its
shapes. Nothing is written until addDocumentPmi.
The letter, the shapes and an optional presentation
The datum, ready for addDocumentPmi
BetaDescribes a geometric tolerance for addDocumentPmi: what it controls, its value, the shapes
it applies to and the letters of the datums it refers to, primary first.
Only position, perpendicularity and parallelism take a diameter zone or a material
condition. Nothing is written until addDocumentPmi.
The type, the value, the shapes, the datum letters, the zone and material condition and an optional presentation
The tolerance, ready for addDocumentPmi
const position = await bitbybit.occt.assembly.manager.createPmiTolerance({
type: Bit.Inputs.OCCT.pmiToleranceTypeEnum.position, value: 0.1, shapeRefs: [{ part: "0:1:1:1", index: 7 }],
datumLetters: ["A", "B", "C"], diameterZone: true, material: Bit.Inputs.OCCT.pmiMaterialConditionEnum.maximum,
});
BetaAdds dimensions, datums and tolerances to a document as product manufacturing information, all of them or, when one is refused, none.
Each names a part's faces, edges or vertices. It answers the changed document, which
exportDocumentToStep writes as STEP AP242 with their pictures; assembly.query.getDocumentPmi
lists the items with their labels, as taken here. Calls add up until removeDocumentPmi.
The document and the dimensions, datums and tolerances to add
The document with the items added
const measured = await bitbybit.occt.assembly.manager.addDocumentPmi({
document: doc,
dimensions: [{ type: Bit.Inputs.OCCT.pmiDimensionTypeEnum.diameter, value: 10, shapeRefs: [{ part: "0:1:1:1", index: 7 }], start: [30, 20, 15], end: [35, 20, 15] }],
datums: [{ letter: "A", shapeRefs: [{ part: "0:1:1:1", index: 4 }] }],
tolerances: [{ type: Bit.Inputs.OCCT.pmiToleranceTypeEnum.perpendicularity, value: 0.02, shapeRefs: [{ part: "0:1:1:1", index: 7 }], datumLetters: ["A"] }],
});
const labels = (await bitbybit.occt.assembly.query.getDocumentPmi({ document: measured })).dimensions.map(d => d.label);
const step = await bitbybit.occt.assembly.manager.exportDocumentToStep({ document: measured });
const pmi = await bitbybit.occt.assembly.query.getDocumentPmi({ document: source });
const { annotations } = await bitbybit.occt.assembly.query.getDocumentAnnotations({ document: source });
const shown = new Map(annotations.map(annotation => [annotation.label, annotation]));
const measured = await bitbybit.occt.assembly.manager.addDocumentPmi({
document: copy,
dimensions: pmi.dimensions.map(d => ({ ...d, type: d.type as Bit.Inputs.OCCT.pmiDimensionTypeEnum, presentation: shown.get(d.label) })),
datums: pmi.datums.map(d => ({ ...d, presentation: shown.get(d.label) })),
tolerances: pmi.tolerances.map(t => ({ ...t, type: t.type as Bit.Inputs.OCCT.pmiToleranceTypeEnum, presentation: shown.get(t.label) })),
});
BetaRemoves every dimension, datum and geometric tolerance from a document, with their pictures and the saved views that showed only them.
It answers the document without them, which exports as one that never held PMI and which
addDocumentPmi writes into as into a fresh one.
The document
The document without its PMI
const cleared = await bitbybit.occt.assembly.manager.removeDocumentPmi({ document: doc });
const measured = await bitbybit.occt.assembly.manager.addDocumentPmi({
document: cleared,
dimensions: [{ type: Bit.Inputs.OCCT.pmiDimensionTypeEnum.diameter, value: 12, shapeRefs: [{ part: "0:1:1:1", index: 7 }] }],
});
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, glTF or OBJ file into a document. Then recolor and rename labels, update or remove parts, add dimensions, datums and tolerances, and export to STEP, glTF, OBJ or PLY. 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.