G-code, or “geometric code,” is the most common CNC programming language used to run or drive computer-controlled manufacturing machines. G-code contains instructions for machines like 3D printers or CNC machines. The G-code document for a specific machining process differs from the 2D model (.dwg or .dxf) file. It is a file that specifies which tool to use, the coordinates and speed of the path it should follow, and various other parameters defining the motion of the tools.
G-code is, therefore, not a file conversion tool, but rather a set of commands derived from a 2D CAD file. In a very high-level outline of the process, G-code generation occurs following the designing of the part or model, the definition of the machine operation and parameters, the creation of toolpaths, and their verification and simulation.
DraftSight contains a generic G-code generation tool that can take .dwg or .dxf geometry and generate machine code. It is important to note that this tool does not generate machine-specific code; you can use some of the tools we will discuss here to add machine-specific options to the beginning or the end of the code, but the G-code generated here should be inspected thoroughly for compatibility with your CNC machine before running any program with a live tool.
The G-code generator functionality, G-Code Generator, is accessed through the DraftSight User Interface (UI) by the following workflow:
The G-code generator may also be accessed by typing _GCODE in the Command Window once in the Drafting and Annotation Workspace. This will also bring up the G-code generator user interface on the right-hand side of the screen.
Once you have your model ready and have accessed DraftSight's G-code generator, it's pretty simple from there.
The G-code Generator panel on the right side of DraftSight’s User Interface handles any modifications to the G-code, as well as its generation and previewing.
First, if you have any comments to include with your G-code file, you can add them at the very top of the G-code generator pane.
You’ll then choose between the types of G-code to be generated:
Preamble and postscript are used to set up and reset the machine. DraftSight automatically provides a default preamble, specifying the CNC machine to start the spindle and to set the RPM. However, you can absolutely create your own and copy and paste it into the Preamble field. DraftSight also includes a default postscript – this too can be customized and correspondingly placed in the Postscript field in the G-code Generator panel.
In this section, the following parameters are specified for the 2D Toolpath selection: Z Safe Height, Z Retraction, FeedRate Z, FeedRate XY, and Depth of Cut. Conversely, the Drill Cycle selection contains the following parameters: Drill Cycle Type, Drill Feed Rate, Depth, and Retract Height.
The differences in the 2D Toolpath and Drill Cycle selections can be viewed below:
Once everything is set up, we can generate the G-code.
First, select all entities in the graphics for which you desire the G-code, then select the Generate button. This creates the initial G-code, which can be edited in the G-code generator panel.
After generating the G-code, the G-code Generator tool displays a preview of the toolpath for the selected entities.
If everything looks good, hit Save!
Depending on your screen resolution, you may have to scroll down to see the View Window (the preview of the tool path).
The preview of the toolpath and drill cycle, which you have selected, appears in the View Window following the generation of the G-code.
This preview also contains controls for a simulation of the tool path and/or drill sequence, with Play, Pause, and Stop, as well as controls for the speed of the preview simulation. Other tools/buttons include Pan, Dynamic Zoom, and Fit.
We hope you find this article explaining DraftSight's G-code helpful. Check out more tips below. Additionally, check out the GoEngineer Community to participate in discussions, create forum posts, and answer questions from other SOLIDWORKS and DraftSight users.
DraftSight 101 - Basic 3D Shapes
DraftSight Make Flat Snapshot Workaround
Master Layers in DraftSight with Layer States Manager
How to Use AutoStack in DraftSight
About Camille Johnson
Camille Johnson is a Certified SOLIDWORKS Expert based out of Atlanta, Georgia. She earned her Bachelor of Science in Biomedical Engineering and Master of Science in Mechanical Engineering from the Georgia Institute of Technology in Atlanta, Georgia. She has been with GoEngineer, helping customers with SOLIDWORKS, SOLIDWORKS Visualize, SOLIDWORKS Composer, and DraftSight needs since January of 2024.
Get our wide array of technical resources delivered right to your inbox.
Unsubscribe at any time.