Skip to content

OpenSCAD library for moving a tool in lines and arcs so as to model how a part would be cut using G-Code or described as a DXF.

License

Notifications You must be signed in to change notification settings

WillAdams/gcodepreview

Repository files navigation

gcodepreview

OpenSCAD library for moving a tool in lines and arcs so as to model how a part would be cut using G-Code, so as to allow OpenSCAD to function as a compleat CAD/CAM solution for subtractive CNC (mills and routers) by writing out G-code (in some cases toolpaths which would not normally be feasible), and to write out DXF files which may be imported into a traditional CAM program to create toolpaths.

OpenSCAD Cut Joinery Module

Updated to make use of Python in OpenSCAD:

https://pythonscad.org/ (previously this was http://www.guenther-sohler.net/openscad/ )

(previous versions had used RapCAD, so as to take advantage of the writeln command, that was re-written in Python)

A BlockSCAD file for the initial version of the main modules is available at:

https://www.blockscad3d.com/community/projects/1244473

The project is discussed at:

https://forum.makerforums.info/t/g-code-preview-using-openscad-rapcad/85729

and

https://forum.makerforums.info/t/openscad-and-python-looking-to-finally-be-resolved/88171

and

https://willadams.gitbook.io/design-into-3d/programming

The files are:

  • gcodepreview.py (gcpy)
  • pygcodepreview.scad (pyscad)
  • gcodepreview.scad(gcpscad)
  • gcodepreview_template.scad (gcptmpl)
  • cut2Dshapes.scad (cut2D)

Usage is:

Place the files in C:\Users\~\Documents\OpenSCAD\libraries (C:\Users\~\Documents\RapCAD\libraries is deprecated since RapCAD is no longer needed since Python is now used for writing out files)

 use <gcodepreview.py>;
 use <pygcodepreview.scad>;
 include <gcodepreview.scad>;

Note that it is necessary to use the first two files (this allows loading the Python commands and then wrapping them in OpenSCAD commands) and then include the last file (which allows using OpenSCAD variables to selectively implement the Python commands via their being wrapped in OpenSCAD modules) and define variables which match the project and then use commands such as:

 opengcodefile(Gcode_filename);
 opendxffile(DXF_filename);

 difference() {
     setupstock(stocklength, stockwidth, stockthickness, zeroheight, stockorigin);

 movetosafez();

 toolchange(squaretoolno,speed * square_ratio);

 begintoolpath(0,0,0.25);
 beginpolyline(0,0,0.25);

 cutoneaxis_setfeed("Z",-1,plunge*square_ratio);
 addpolyline(stocklength/2,stockwidth/2,-stockthickness);

 cutwithfeed(stocklength/2,stockwidth/2,-stockthickness,feed);

 endtoolpath();
 endpolyline();

 }

 closegcodefile();
 closedxffile();

which makes a G-code file:

OpenSCAD template G-code file

but one which could only be sent to a machine so as to cut only the softest and most yielding of materials, and of which has a matching DXF which may be imported into a CAM tool --- but which it is not directly possible to assign a toolpath in readily available CAM tools.

Importing this DXF and actually cutting it is discussed at:

https://forum.makerforums.info/t/rewriting-gcodepreview-with-python/88617/14

Tool numbers match those of tooling sold by Carbide 3D (ob. discl., I work for them). Comments are included in the G-code to match those expected by CutViewer.

A complete example file is: gcodepreview_template.scad another example is openscad_gcodepreview_cutjoinery.tres.scad which is made from an OpenSCAD Graph Editor file:

OpenSCAD Graph Editor Cut Joinery File

Version 0.1 supports setting up stock, origin, rapid positioning, making cuts, and writing out matching G-code, and creating a DXF with polylines.

Added features since initial upload:

  • endpolyline(); --- this command allows ending one polyline so as to allow multiple lines in a DXF
  • separate dxf files are written out for each tool where tool is ball/square/V and small/large (10/31/23)
  • re-writing as a Literate Program using the LaTeX package docmfp (begun 4/12/24)
  • support for additional tooling shapes such as dovetail and keyhole tools

Version 0.2 adds support for arcs

  • DXF: support for arcs (which may be used to make circles) (6/1/24)
  • Specialty toolpaths such as Keyhole which may be used for dovetail as well as keyhole cutters

Deprecated feature:

  • exporting SVGs --- while this was begun, it turns out that these are written out upside down due to coordinate differences between OpenSCAD/DXFs and SVGs (it is possible that METAPOST will be used instead for future versions)

Possible future improvements:

  • Support for curves along the 3rd dimension --- this will require measuring the difference between the current Z-position and the specified ending Z-axis depth and apportioning it out over the course of the movement along the arc
  • G-code: support for G2/G3 arcs and circles
  • G-code: import external tool libraries and feeds and speeds from JSON or CSV files ---
  • support for additional tooling shapes such as roundover tooling
  • general coding improvements --- current coding style is quite prosaic
  • generalized modules for cutting out various shapes/geometries --- an in-process one is to cut a rectangular area as vertical passes (the horizontal version will be developed presently)

Note for G-code generation that it is up to the user to implement Depth per Pass so as to not take a single full-depth pass.

About

OpenSCAD library for moving a tool in lines and arcs so as to model how a part would be cut using G-Code or described as a DXF.

Topics

Resources

License

Stars

Watchers

Forks