Script: DVI

DVI picture
Type
Typescript logo indicatortypescript
Project
slice
Date Created
Oct 5, 2024, 12:14:53 AM
Last Edit Date
Aug 7, 2025, 11:42:57 AM

Project Information

slice

View Full Project

Script Code

const start = async () => {

    const url =
        "https://ik.imagekit.io/bitbybit/prod/ik-seo/o/users%2FyVqNAFXmieX0iAkdP6wAz5BJ4X82%2Fprojects%2Fh3XNAbbSL5n6mYgPaGmk%2Fassets%2Fmultiaxis-xyz/multiaxis-xyz.step?alt=media&token=43232172-fef4-4eca-a31d-787f295761c7";
    const stepFile = await bitbybit.asset.fetchFile({ url });
    let center = [0, 2.5, 4];

    const parsedStep = await bitbybit.occt.io.loadSTEPorIGES({
        assetFile: stepFile,
        adjustZtoY: true,
    });
    const scaledShape = await bitbybit.occt.transforms.scale({
        shape: parsedStep,
        factor: 0.01,
    });


    let direction = [0, 1, 1];
    const step = 1;
    let finalcuts = [];
    let z = 4;
    for (let i = 0; i < 4; i++) {
        z = z - step;
        center = [center[0], center[1], z];
        finalcuts[i] = await slice(scaledShape, center, direction)

    }

    const compound = await bitbybit.occt.shapes.compound.makeCompound({
        shapes: finalcuts
    });
    const solids = await bitbybit.occt.shapes.solid.getSolids({ shape: scaledShape });
    const faceCut = await bitbybit.occt.shapes.face.createSquareFace({ size: 10, direction: [direction[0], direction[1], direction[2]], center: [center[0], center[1], center[2]] });
    const extrudedFace = await bitbybit.occt.operations.extrude({
        shape: faceCut,
        direction: [0, 4, 1],
    });

    const drawOpt = new Bit.Inputs.Draw.DrawOcctShapeOptions();
    drawOpt.faceColour = "#ff00ff";
    bitbybit.draw.drawAnyAsync({
        entity: finalcuts,
        options: drawOpt,
    });

    // bitbybit.draw.drawAnyAsync({
    //     entity: extrudedFace,
    //     options: drawOpt,
    // });
    solids.forEach(async s => {
        const leftover = await bitbybit.occt.booleans.difference({ shape: s, shapes: [extrudedFace], keepEdges: false });
        bitbybit.draw.drawAnyAsync({ entity: leftover });
    })

}
async function slice(scaledShape, center, direction) {
    const plane = await bitbybit.occt.shapes.face.createSquareFace({
        size: 10,
        center: center,
        direction: direction
    });
    const scaledPlane = await bitbybit.occt.transforms.scale({
        shape: plane,
        factor: 1,
    });
    const cut = await bitbybit.occt.booleans.intersection({
        shapes: [scaledShape, scaledPlane],
        keepEdges: false,
    });
    console.log(cut);
    return cut;
}

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