Script: OCCT plate with ellipses

OCCT plate with ellipses picture
Type
Typescript logo indicatortypescript
Date Created
Feb 19, 2024, 12:02:06 PM
Last Edit Date
Oct 21, 2024, 6:39:28 PM

Project Information

In this project we demonstrate how to export JSCAD polygons and meshes to dxf file for laser cutters.

View Full Project

Script Code

async function start() {
    const squareOpt = new Bit.Inputs.OCCT.SquareDto();
    squareOpt.direction = [0, 0, 1];
    squareOpt.size = 20;
    const square = await bitbybit.occt.shapes.face.createSquareFace(squareOpt);
    const subdivOpt = new Bit.Inputs.OCCT.FaceSubdivisionDto<Bit.Inputs.OCCT.TopoDSFacePointer>();
    subdivOpt.shape = square;
    subdivOpt.removeEndEdgeU = true;
    subdivOpt.removeEndEdgeV = true;
    subdivOpt.removeStartEdgeU = true;
    subdivOpt.removeStartEdgeV = true;
    const subdivPoints = await bitbybit.occt.shapes.face.subdivideToPoints(subdivOpt)

    const ellipseOpt = new Bit.Inputs.OCCT.EllipseDto();
    ellipseOpt.direction = [0, 0, 1];
    ellipseOpt.radiusMajor = 1;
    ellipseOpt.radiusMinor = 0.6;
    const ellipse = await bitbybit.occt.shapes.wire.createEllipseWire(ellipseOpt);

    const transformedEllipses = await bitbybit.occt.transforms.translateShapes({
        shapes: bitbybit.lists.repeat({ item: ellipse, times: subdivPoints.length }),
        translations: subdivPoints
    });

    const pointsOfJscadPolygons = await bitbybit.occt.shapes.wire.divideWiresByParamsToPoints({
        shapes: transformedEllipses,
        nrOfDivisions: 20,
        removeEndPoint: true,
        removeStartPoint: false,
    });

    const corners = await bitbybit.occt.shapes.edge.getCornerPointsOfEdgesForShape({
        shape: square
    });

    pointsOfJscadPolygons.push(corners);

    const jscadPolygonsPromise = pointsOfJscadPolygons.map(polygonPoints => {
        return bitbybit.jscad.polygon.createFromPoints({ points: polygonPoints });
    });

    const jscadPolygons = await Promise.all(jscadPolygonsPromise);

    bitbybit.jscad.downloadGeometryDxf({
        geometry: jscadPolygons,
        fileName: "ellipses-in-frame"
    });

    const compound = await bitbybit.occt.shapes.compound.makeCompound({
        shapes: [...transformedEllipses, square]
    });

    bitbybit.draw.drawAnyAsync({
        entity: compound
    });

    bitbybit.draw.drawAnyAsync({
        entity: pointsOfJscadPolygons.flat()
    })
}

async function createShape() {

}

start();
Plans & Pricing

Choose Your Plan

Editor plans for 3D development, API keys for server-side CAD algorithms

B2B

ENTERPRISE

Custom pricing

Custom software development, dedicated servers & CAD automation at scale.

CAD Automation & Software
  • Custom software development
  • Cloud CAD automation pipelines
  • 3D configurators (STEP & GLTF)
  • Batch export jobs
  • Custom algorithms & deployment
Infrastructure & Support
  • Custom compute allocation
  • Dedicated / VPS server tenants
  • Long-running computation jobs
  • Custom upload limits & overage
  • SLA & premium support