DraftSight G-Code Generator Explained

Article by Camille Johnson on Sep 04, 2025

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.

G-Code in DraftSight

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:

  1. Navigate to the Drafting and Annotation Workspace from the top toolbar drop-down menu.
  2. The Powertools tab should appear in the top toolbar between the View and Toolbox tabs (unless otherwise customized).
  3. Select 2D G-code Generator… from the Powertools selections.

    DraftSight 2D G-code Generator

  4. You should notice a new pane on the right-hand side of the screen titled G-code Generator.

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.

Generate Your G-Code

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.

Generate G-code in DraftSight

Comments

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.

Path and Drill Cycle

You’ll then choose between the types of G-code to be generated:

  • To define how the engraving tool will move, pick 2D Toolpath.
  • To define how holes are drilled, pick Drill Cycle.

Preamble and Postscript

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.

Retraction and Feed Rate

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:

DraftSight Retraction and Feed Rate Fields

Generate and Save

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!

DraftSight G-code Generator Tool Explained

View Window

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. 

Related Articles

DraftSight 101 - Basic 3D Shapes

DraftSight Make Flat Snapshot Workaround

Master Layers in DraftSight with Layer States Manager

How to Use AutoStack in DraftSight

Using DraftSight Split Dimension

VIEW ALL DRAFTSIGHT ARTICLES

 

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.

View all posts by Camille Johnson