bitbybit.dev v1.0.0-rc.1
    Preparing search index...

    Class OCCTAssemblyManager

    Index

    Constructors

    • Parameters

      • occWorkerManager: OCCTWorkerManager

      Returns OCCTAssemblyManager

    assembly

    • Create a part definition for use in assembly structures. This is a helper for visual programming - it simply wraps the inputs into a part object.

      Parameters

      Returns Promise<AssemblyPartDef<any>>

      Part definition that can be added to an assembly structure

      create part

      false

      const box = await occt.shapes.solid.createBox({ width: 10, length: 10, height: 10 });
      const part = await occt.assembly.manager.createPart({ id: "box", shape: box, name: "Box", color: { r: 1, g: 0, b: 0, a: 1 } });
    • Create an assembly node definition (a container for other nodes). Assembly nodes group instances and other assemblies together in the hierarchy.

      Parameters

      Returns Promise<AssemblyNodeDef>

      Node definition that can be added to an assembly structure

      create assembly node

      false

      const rootAsm = await occt.assembly.manager.createAssemblyNode({ id: "root", name: "Root Assembly" });
      const subAsm = await occt.assembly.manager.createAssemblyNode({ id: "sub", name: "Sub Assembly", parentId: "root" });
    • Create an instance node definition (a reference to a part with transform). Instance nodes place a part at a specific location with optional translation, rotation, and scale.

      Parameters

      Returns Promise<AssemblyNodeDef>

      Node definition that can be added to an assembly structure

      create instance node

      false

      const inst1 = await occt.assembly.manager.createInstanceNode({ id: "box1", partId: "box", name: "Box 1" });
      const inst2 = await occt.assembly.manager.createInstanceNode({
      id: "box2", partId: "box", name: "Box 2",
      translation: [20, 0, 0], rotation: [0, 0, 45]
      });
    • Create a part update definition for modifying an existing part in a document. Part updates can change the shape, name, and/or color of an existing part.

      Parameters

      • inputs: CreatePartUpdateDto<any>

        Update details including label and optional new shape/name/color

      Returns Promise<AssemblyPartUpdateDef<any>>

      Part update definition that can be added to an assembly structure's partUpdates array

      create part update

      false

      // Get existing parts from document
      const parts = await occt.assembly.query.getDocumentParts({ document });

      // Create a new shape to replace the old one
      const newBox = await occt.shapes.solid.createBox({ width: 20, length: 20, height: 20 });

      // Create an update definition
      const update = await occt.assembly.manager.createPartUpdate({
      label: parts[0].label,
      shape: newBox,
      name: "Bigger Box",
      colorRgba: { r: 0, g: 1, b: 0, a: 1 }
      });

      // Combine with structure and rebuild
      const structure = await occt.assembly.manager.combineStructure({ parts: [], nodes: [], partUpdates: [update] });
      await occt.assembly.manager.buildAssemblyDocument({ structure, existingDocument: document });
    • Combine parts and nodes into a complete assembly structure definition. This is the final step before calling buildAssemblyDocument.

      Parameters

      Returns Promise<AssemblyStructureDef<any>>

      Complete assembly structure ready for building

      combine structure

      false

      const parts = [part1, part2];
      const nodes = [rootAsm, inst1, inst2];
      const structure = await occt.assembly.manager.combineStructure({ parts, nodes });
      const result = await occt.assembly.manager.buildAssemblyDocument({ structure });
    • Build an assembly document from a structure definition. Returns the document handle directly - document stays in worker memory.

      This is the recommended approach for creating assemblies:

      1. Define parts with shapes, names, and optional colors
      2. Define nodes (assemblies and instances) with hierarchy and transforms
      3. Call this method to create the document
      4. Query the document or to STEP/glTF
      5. Call deleteDocument() to release memory when done

      If existingDocument is provided and valid, the document will be cleared and updated instead of creating a new one. This is useful for updating an assembly without allocating a new document each time.

      Parameters

      Returns Promise<TDocStdDocumentPointer>

      The document handle (reference to worker-side document, new or updated)

      Error if assembly building fails

      build document

      false

      // Create new document
      const structure = await occt.assembly.manager.combineStructure({ parts, nodes });
      const document = await occt.assembly.manager.buildAssemblyDocument({ structure });

      // Update existing document (reuses same handle)
      const updatedStructure = await occt.assembly.manager.combineStructure({ parts: newParts, nodes: newNodes });
      await occt.assembly.manager.buildAssemblyDocument({ structure: updatedStructure, existingDocument: document });

      // Cleanup
      await occt.assembly.manager.deleteDocument({ document });
    • Load a STEP file into a new assembly document. Supports both regular STEP and gzip-compressed STEP-Z.

      Parameters

      • inputs: LoadStepToDocDto

        STEP file data (as string, ArrayBuffer, Uint8Array, File, or Blob)

      Returns Promise<TDocStdDocumentPointer>

      The document handle (reference to worker-side document)

      Error if STEP loading fails

      load STEP to document

      false

      const stepData = await fetch("model.step").then(r => r.text());
      const document = await occt.assembly.manager.loadStepToDoc({ stepData });
      const parts = await occt.assembly.query.getDocumentParts({ document });
      console.log("Found parts:", parts);

    export

    • Export an assembly document to STEP format.

      Parameters

      Returns Promise<Uint8Array>

      STEP file content as Uint8Array

      document STEP

      false

      const document = await occt.assembly.manager.buildAssemblyDocument({ structure });
      const stepData = await occt.assembly.manager.exportDocumentToStep({
      document,
      fileName: "my-assembly.step",
      author: "John Doe",
      tryDownload: true
      });
    • Export an assembly document to glTF binary (GLB) format.

      Parameters

      Returns Promise<Uint8Array>

      GLB content as Uint8Array

      document glTF

      false

      const document = await occt.assembly.manager.buildAssemblyDocument({ structure });
      const glbData = await occt.assembly.manager.exportDocumentToGltf({
      document,
      meshDeflection: 0.1,
      tryDownload: true
      });

    lifecycle

    • Delete an assembly document and release its memory. Call this when done with the document to free resources.

      Parameters

      Returns Promise<void>

      delete document

      false

      const document = await occt.assembly.manager.buildAssemblyDocument({ structure });
      // ... use the document ...
      await occt.assembly.manager.deleteDocument({ document });

    modify

    • Set the color of a label in the document. Colors are preserved when exporting to STEP and other formats.

      Parameters

      Returns Promise<boolean>

      true on success, false on failure

      set label color

      false

      const success = await occt.assembly.manager.setDocLabelColor({
      document,
      label: "0:1:1:1",
      r: 255, g: 0, b: 0, a: 255
      });
    • Set or change the name of a label (part, instance, or assembly).

      Parameters

      Returns Promise<boolean>

      true on success, false on failure

      set label name

      false

      const success = await occt.assembly.manager.setDocLabelName({
      document,
      label: "0:1:1:1",
      name: "Updated Part Name"
      });