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

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

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

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

    export

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

      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. Failure throws an error.

      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: false, 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);

    lifecycle

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

      Parameters

      Returns Promise<void>

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

    modify

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

      Parameters

      Returns Promise<boolean>

      True when the color was set

      const done = await bitbybit.occt.assembly.manager.setDocLabelColor({ document: doc, label: "0:1:1:1", r: 1, g: 0, b: 0, a: 1 });
      
    • Renames a label of a document, a part, instance or assembly.

      Parameters

      Returns Promise<boolean>

      True when the name was set

      const done = await bitbybit.occt.assembly.manager.setDocLabelName({ document: doc, label: "0:1:1:1", name: "Left bracket" });