Script TS TypeScript Free

OCCT plate with ellipses

OCCT plate with ellipses picture
Author
bitbybit
Created
Feb 19, 2024, 11:02:06 AM
Last edit
Oct 21, 2024, 4:39:28 PM

Edit scriptPreview

Project

Export JSCAD to DXF

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

View full project
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 and pricing

Choose your plan

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

EnterpriseB2BCustompricing

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

Learn moreContact us

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

All prices exclude applicable taxesView all plan details

Contact

Talk to us

Tell us what you are building or what is blocking you, through whichever channel suits you.