Python Scripting for Simple Tasks

I just wanted to share some results from playing around in Python the past couple of days. I wrote a gcode generator from scratch, and I added support for generating paths with lines and arcs. I certainly have aspirations for automating more things in my workflow, but right now, this already saves me a lot of time as ad hoc surfacing programs are a pain.

Right now I just have the code on my computer. Is this something anyone would be interested in?

Here’s the script I wrote for surfacing.

# Lead-in and lead-out using z-arc
        self.lead = ZArcLeadStrategy(tool_diameter/2+1, 25, np.pi/6)
        
        # Create the path
        # Find the number of passes
        if direction == SurfacingProgram.horizontal_surfacing:
            num_passes = np.ceil(height / (self.tool.diameter*stepover))+1
        else:
            num_passes = np.ceil(width / (self.tool.diameter*stepover))+1
        delta = height/(num_passes-1)
        
        # Create the paths
        passes = []
        for i in range(int(num_passes)):
            if direction == SurfacingProgram.horizontal_surfacing:
                p = Path((0,i*delta,0))
                p.LineTo((width,i*delta,0))
            else:
                p = Path((i*delta,0,0))
                p.LineTo((i*delta,height,0))
            passes.append(p)
        
        # Contour on path
        self.contourCut(passes, self.tool, self.lead, zstart, zstop, zstep)

Below are the results in NCViewer for surfacing 100mm x 100mm using McFly:

3 Likes

Very cool!

There are a lot of options for CNC programming — I wish that it was easier and more visual.

I put together some resources for this sort of thing:

https://web.archive.org/web/20210305104601/https://wiki.shapeoko.com/index.php/Programming

and also see:

https://web.archive.org/web/20201111183312/https://wiki.shapeoko.com/index.php/G-Code_Utilities

There’s also a communication/control program:

(which has a Python scripting option)

and

1 Like

This topic was automatically closed after 30 days. New replies are no longer allowed.