API cam settings for offset stock

Hi! I’m having trouble finding the correct settings to do a CAM outline and roughing operation with the API with an offset stock. I have the camOriginTop set to true but the model still appears to be above the XY plane, and there seems to be unexpected plunging to the origin plane. At first, I thought it could be an issue with the origin not being set correctly but setting the origin differently does not resolve the plunges between operations. Using the same settings and model in grid.space lends to correct results, and the model is positioned below the XY plane. I’m attaching my settings below, if anyone could help me land on the correct settings for these operations I would really appreciate it.

new Engine()
.setListener(display_message)
.load("https://raw.githubusercontent.com/alzatin/donut_5/refs/heads/main/squaretest.stl")
// should to call widget.setTopZ here ideally
.then(eng => eng.setMode("CAM"))
.then(eng => eng.setStock({
    "x": 5,
    "y": 5,
    "z": 0
}))
.then(eng => eng.moveTo(0, 0, 0))
.then(eng=> eng.setTools([{
    id: 1000,
    number: 1,
    type: "endmill",
    name: "end 1/4",
    metric: false,
    shaft_diam: 0.15,
    shaft_len: 1,
    flute_diam: 0.25,
    flute_len: 2,
    taper_tip: 0,
    order: 5
}]))
.then(eng => eng.setProcess({
    camEaseAngle:10,
    camEaseDown:true,
    camZAnchor: "bottom",
    camDepthFirst : true,
    camStockOffset: true,
     camOriginTop: true,
        camOriginCenter: false,
        camOriginOffX: 0,
        camOriginOffY: 0,
        camOriginOffZ: 0,
    camZThru: 1,
    camZBottom:0, // temp hack to get around setTopZ bug
    camToolInit: true,
    ops: [{
        type: "outline",
        tool: 1000,
        spindle: 13000,
        step: 0.4,
        steps: 1,
        down: 4,
        rate: 635,
        plunge: 51,
        dogbones: false,
        omitvoid: false,
        omitthru: false,
        outside: false,
        inside: false,
        wide: false,
        top: false,
        ov_topz: 0,
        ov_botz: 0,
        ov_conv: true
    },
    {
            type: "rough",
            tool: 1000,
            spindle: 1000,
            down: 4,
            step: .4,
            rate: 635,
        plunge: 51,
            leave: 0,
            leavez: 0,
            all: false,
            voids: true,
            flats: true,
            inside: true,
            omitthru: true,
            ov_topz: 0,
            ov_botz: 0,
            ov_conv: false,
          },
    ]
}))
.then(eng => eng.setDevice({
    mode: "CAM",
    internal: 0,
    bedHeight: 2.5,
    bedWidth: 678.18,
    bedDepth: 1524,
    maxHeight: 150,
    originCenter: false,
    spindleMax: 24000,
    gcodePre: [
        "G20 ; set units to inches (required)",
        "G90 ; absolute position mode (required)"
    ],
    gcodePost: [
        "M05 ; spindle off",
        "M30 ; program end"
    ],
    gcodeDwell: [
        "G4 P{time} ; dwell for {time}ms"
    ],
    gcodeSpindle: [
        "M3 S{speed} ; spindle on at {spindle} rpm"
    ],
    gcodeChange: [
        "M05 ; spindle off",
        "M6 T{tool} ; change tool to '{tool_name}'",
        "G37; get tool offset with ETS"
    ],
    gcodeFExt: "nc",
    gcodeSpace: true,
    gcodeStrip: false,
    deviceName: "Tormach.24R",
    useLaser: false
}))
.then(eng => eng.slice())
.then(eng => eng.prepare())
.then(eng => eng.export())
.then(display_gcode);

this is what worked for me. in short, origin and stock calcs are not happening properly in the engine since the client is still computing that in the UI. so you have to set them manually:

new Engine()
.setListener(display_message)
.load("https://raw.githubusercontent.com/alzatin/donut_5/refs/heads/main/squaretest.stl")
// should to call widget.setTopZ here ideally
.then(eng => eng.setMode("CAM"))
.then(eng => eng.setDevice({
    mode: "CAM",
    internal: 0,
    bedHeight: 2.5,
    bedWidth: 678.18,
    bedDepth: 1524,
    maxHeight: 150,
    originCenter: false,
    spindleMax: 24000,
    gcodePre: [
        "G20 ; set units to inches (required)",
        "G90 ; absolute position mode (required)"
    ],
    gcodePost: [
        "M05 ; spindle off",
        "M30 ; program end"
    ],
    gcodeDwell: [
        "G4 P{time} ; dwell for {time}ms"
    ],
    gcodeSpindle: [
        "M3 S{speed} ; spindle on at {spindle} rpm"
    ],
    gcodeChange: [
        "M05 ; spindle off",
        "M6 T{tool} ; change tool to '{tool_name}'",
        "G37; get tool offset with ETS"
    ],
    gcodeFExt: "nc",
    gcodeSpace: true,
    gcodeStrip: false,
    deviceName: "Tormach.24R",
    useLaser: false
}))
.then(eng => eng.moveTo(0, 0, 0))
.then(eng=> eng.setTools([{
    id: 1000,
    number: 1,
    type: "endmill",
    name: "end 1/4",
    metric: false,
    shaft_diam: 0.15,
    shaft_len: 1,
    flute_diam: 0.25,
    flute_len: 2,
    taper_tip: 0,
    order: 5
}]))
.then(eng => eng.setProcess({
    camEaseAngle:10,
    camEaseDown:true,
    camZAnchor: "top",
    camDepthFirst : true,
    camStockOffset: false,
    camOriginTop: true,
    camOriginCenter: false,
    camOriginOffX: 0,
    camOriginOffY: 0,
    camOriginOffZ: 0,
    camZThru: 1,
    camZBottom:0, // temp hack to get around setTopZ bug
    camToolInit: true,
    ops: [{
        type: "outline",
        tool: 1000,
        spindle: 13000,
        step: 0.4,
        steps: 1,
        down: 4,
        rate: 635,
        plunge: 51,
        dogbones: false,
        omitvoid: false,
        omitthru: false,
        outside: false,
        inside: false,
        wide: false,
        top: false,
        ov_topz: 0,
        ov_botz: 0,
        ov_conv: true
    },
    {
        type: "rough",
        tool: 1000,
        spindle: 1000,
        down: 4,
        step: .4,
        rate: 635,
        plunge: 51,
        leave: 0,
        leavez: 0,
        all: false,
        voids: true,
        flats: true,
        inside: true,
        omitthru: true,
        ov_topz: 0,
        ov_botz: 0,
        ov_conv: false,
      },
    ]
}))
.then(eng => eng.setStock({
    "x": 35,
    "y": 35,
    "z": 10,
    "center": { x: 0, y: 0, z: 5 }
}))
.then(eng => eng.setOrigin(-17.5, 17.5, 10))
.then(eng => eng.slice())
.then(eng => eng.prepare())
.then(eng => eng.export())
.then(display_gcode);

Thanks Steward, I was able to get it as I was hoping using offset stock, setting the origin, and setting the camZTop: -1, . Do you happen to know which setting I can use to remove the Zcutthru pass? I know you made some changes that made it possible but i’m struggling to remember what it was.

this is the parameter that controls Z thru

1 Like