Bitbybit Docs
    Preparing search index...

    Class OCCTAssemblyManager

    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.

    Index

    Constructors

    Methods

    • 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.

      Parameters

      • inputs: CreateImportedPartDto

        The part id, the index of the source document, an optional source label, name and color

      Returns Promise<AssemblyLoadedPartDef>

      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] });

    assembly

    • 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.

      Parameters

      Returns Promise<AssemblyPartDef<TopoDSShapePointer>>

      The part definition, ready for combineStructure

      const box = await bitbybit.occt.shapes.solid.createBox({ width: 10, length: 10, height: 10, center: [0, 0, 0] });
      const part = await bitbybit.occt.assembly.manager.createPart({ id: "box", shape: box, name: "Box", colorRgba: { r: 1, g: 0, b: 0, a: 1 } });
    • 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.

      Parameters

      • inputs: CreateAssemblyNodeDto

        The node id, its name, an optional parent id, an optional color and an optional placement matrix

      Returns Promise<AssemblyNodeDef>

      The node definition, ready for combineStructure

      const root = await bitbybit.occt.assembly.manager.createAssemblyNode({ id: "root", name: "Root Assembly" });
      const sub = await bitbybit.occt.assembly.manager.createAssemblyNode({ id: "sub", name: "Sub Assembly", parentId: "root" });
    • 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.

      Parameters

      • inputs: CreateInstanceNodeDto

        The node id, the part id, the name, an optional parent id and the placement

      Returns Promise<AssemblyNodeDef>

      The node definition, ready for combineStructure

      const first = await bitbybit.occt.assembly.manager.createInstanceNode({ id: "box1", partId: "box", name: "Box 1" });
      const second = await bitbybit.occt.assembly.manager.createInstanceNode({ id: "box2", partId: "box", name: "Box 2", translation: [20, 0, 0], rotation: [0, 0, 45] });
    • 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.

      Parameters

      Returns Promise<AssemblyPartUpdateDef<TopoDSShapePointer>>

      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.

      Parameters

      Returns Promise<AssemblyStructureDef<TopoDSShapePointer>>

      The structure, ready to build

      const structure = await bitbybit.occt.assembly.manager.combineStructure({ parts: [part], nodes: [root, first, second], clearDocument: false });
      const doc = await bitbybit.occt.assembly.manager.buildAssemblyDocument({ structure });
    • 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The document handle, new or updated

      Error if assembly building fails

      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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The document handle

      Error if STEP loading fails

      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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The document handle

      const doc = await bitbybit.occt.assembly.manager.loadGltfToDoc({ gltfData: glbBytes });
      const parts = await bitbybit.occt.assembly.query.getDocumentParts({ document: doc });
    • 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The document handle

      const doc = await bitbybit.occt.assembly.manager.loadObjToDoc({ objData: objText });
      const tree = await bitbybit.occt.assembly.query.getAssemblyHierarchy({ document: doc });

    export

    • 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.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The STEP file as bytes

      const step = await bitbybit.occt.assembly.manager.exportDocumentToStep({ document: doc, fileName: "assembly.step", author: "Bitbybit user", organization: "Bitbybit", compress: false, tryDownload: false });
      
    • 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.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      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 });
      
    • 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.

      Parameters

      Returns Promise<Uint8Array<ArrayBufferLike>>

      The GLB file as bytes

      const options = new Bit.Inputs.OCCT.ExportDocumentToGltfWithDracoDto<Bit.Inputs.OCCT.TDocStdDocumentPointer>();
      options.document = doc;
      options.meshDeflection = 0.1;
      options.dracoCompressionLevel = 7;
      const glb = await bitbybit.occt.assembly.manager.exportDocumentToGltfWithDraco(options);
    • 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.

      Parameters

      Returns Promise<ObjFiles>

      The OBJ text and the material library text

      const files = await bitbybit.occt.assembly.manager.exportDocumentToObj({ document: doc, meshDeflection: 0.1, fileName: "assembly.obj", tryDownload: false });
      console.log(files.obj, files.mtl);
    • 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.

      Parameters

      Returns Promise<string>

      The PLY file as text

      const ply = await bitbybit.occt.assembly.manager.exportDocumentToPly({ document: doc, meshDeflection: 0.1, fileName: "assembly.ply", tryDownload: false });
      

    lifecycle

    • 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.

      Parameters

      Returns Promise<void>

      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 });

    modify

    • 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The colored document

      const colored = await bitbybit.occt.assembly.manager.setDocLabelColor({ document: doc, label: "0:1:1:1", r: 1, g: 0, b: 0, a: 1 });
      const step = await bitbybit.occt.assembly.manager.exportDocumentToStep({ document: colored });
    • 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The renamed document

      const renamed = await bitbybit.occt.assembly.manager.setDocLabelName({ document: doc, label: "0:1:1:1", name: "Left bracket" });
      const tree = await bitbybit.occt.assembly.query.getAssemblyHierarchy({ document: renamed });
    • Beta

      Colors 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The colored document

      const parts = await bitbybit.occt.assembly.query.getDocumentParts({ document: doc });
      const labels = parts.filter(part => part.type === "part").map(part => part.label);
      const colored = await bitbybit.occt.assembly.manager.setDocLabelColors({ document: doc, labels, r: 1, g: 0, b: 0, a: 1 });
    • Beta

      Renames 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The renamed document

      const renamed = await bitbybit.occt.assembly.manager.setDocLabelNames({ document: doc, labels: ["0:1:1:1", "0:1:1:2"], names: ["Left bracket", "Right bracket"] });
      const tree = await bitbybit.occt.assembly.query.getAssemblyHierarchy({ document: renamed });

    pmi

    • Beta

      Describes 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.

      Parameters

      • inputs: PmiShapeDto

        The part's label, whether a face, edge, vertex or the whole part is meant, and its index

      Returns Promise<PmiShapeDto>

      The shape, ready for the shapeRefs of createPmiDimension, createPmiDatum and createPmiTolerance

      const top = await bitbybit.occt.assembly.manager.createPmiShape({ part: "0:1:1:1", kind: Bit.Inputs.OCCT.pmiShapeKindEnum.face, index: 5 });
      const bottom = await bitbybit.occt.assembly.manager.createPmiShape({ part: "0:1:1:1", kind: Bit.Inputs.OCCT.pmiShapeKindEnum.face, index: 4 });
    • Beta

      Describes 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.

      Parameters

      • inputs: PmiDimensionDto

        The type, the value, the tolerance, the shapes and how the picture is drawn

      Returns Promise<PmiDimensionDto>

      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,
      });
    • Beta

      Describes 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.

      Parameters

      • inputs: PmiDatumDto

        The letter, the shapes and an optional presentation

      Returns Promise<PmiDatumDto>

      The datum, ready for addDocumentPmi

      const datumA = await bitbybit.occt.assembly.manager.createPmiDatum({ letter: "A", shapeRefs: [{ part: "0:1:1:1", index: 4 }] });
      
    • Beta

      Describes 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.

      Parameters

      • inputs: PmiToleranceDto

        The type, the value, the shapes, the datum letters, the zone and material condition and an optional presentation

      Returns Promise<PmiToleranceDto>

      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,
      });
    • Beta

      Adds 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      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) })),
      });
    • Beta

      Removes 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.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      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 }] }],
      });