exporters_export-step.js

import oc from "../opencascade/initializer";

/**
 * Export entities to a STEP file.
 * @memberof exporters
 * @alias exportStep
 * @param {Array} entities - The entities array can include `Solid`, `Face`, `Edge`, and `Wire` objects.
 * @returns {string|null} - The content of the STEP file as a binary string, or null if the export failed.
 */
const exportStep = (entities) => {
  const filename = "temp";
  const compound = new oc.TopoDS_Compound();
  const builder = new oc.BRep_Builder();
  builder.MakeCompound(compound);
  entities.forEach((entity) => {
    builder.Add(compound, entity.wrapped);
  });
  const writer = new oc.STEPControl_Writer_1();
  const transferStatus = writer.Transfer_1(compound, oc.STEPControl_StepModelType.STEPControl_AsIs, true, new oc.Message_ProgressRange_1());
  if (!transferStatus === oc.IFSelect_ReturnStatus.IFSelect_RetDone) {
    return null;
  }
  const writeStatus = writer.Write(filename);
  if (!writeStatus === oc.IFSelect_ReturnStatus.IFSelect_RetDone) {
    return null;
  }
  const content = oc.FS.readFile(`/${filename}`, {encoding: "binary"});
  oc.FS.unlink(`/${filename}`);
  return content;
};

export {exportStep};