DeclaraCAD provides a Toolpath node for generating simple gcode for 2.5D plotters, cutters, and engravers. To use it set the wires to generate toolpaths for the start_point, end_point, and output filename where it should be saved.

Note: Since the Toolpath node works with any wire topology custom processing can be performed on the wires before generating the toolpath.

Additional options can be provided to alter the toolpath, for example reverse=True will generate the reverse the toolpath direction, and optimize=True (the default) will perform a shortest path optimization of the movements. If the device supports 3d movements the clearance value sets how far the head will lift between cuts.

from declaracad.cnc.toolpath import Toolpath
from stencils.bga import BGAStencil

enamldef Assembly(Part):
    BGAStencil: stencil:
           pass # etc..
    Toolpath: cutting_path:
        wires = stencil.topology.wires
        show_direction = False
        start_point = Point(0, 0, 2*inch)
        end_point = Point(0, 0, 2*inch)
        clearance = 1
        #reverse = True
        filename = "path/to/output.gcode"

BGA Stencil toolpath