MIDILLI G-Code Generator for CNC Routers

MIDILLI G-Code Generator is a free and versatile command-line tool for creating G-Codes files to prepare box-shaped parts. It supports circular drill holes, rectangular cutouts, and precise dimensions in metric units. The generated G-code files are compatible with CNC routers supporting GRBL, ensuring seamless design preparation.

Slightly changed version of the example project, with screws, screw heads, recesses, and component rotations.

Derived from the in-house MIDILLI Tech Automation Suite, this tool is a simplified yet robust solution.

It is offered free for non-commercial use. You can find the full license details here.

Please choose a topic from below to read.

Features

  • Box Creation:
    • Generate rectangular shapes with up to six sides to form a complete box structures.
    • Option to omit any side during box design.
    • Option to use the sizing for the inner volume or the outer volume.
  • Customizable Cutouts:
    • Create holes or rectangular cutouts (also called components) on specific sides of the box with precise locations.
    • Create screw holes on top or bottom* side with the given screw diameter.
  • Component Rotation:
    • Rotate components to any specified angle.
  • Recess Support:
    • Create flush surfaces with custom dimensions that prevent movement of e.g., button caps and improve functionality.
    • Create recesses for screw heads*.
  • Bit Diameter Compensation:
    • Compensate the bit diameter to create exactly the specified drill holes/cutouts.
    • Straight and V-shaped bits are supported.
  • Feedrate:
    • Set feedrate for movement on axes.
  • Layered Outputs:
    • Separate component, recess, outline layers’ outputs to only perform a single step at a time.
  • Material Thickness:
    • Adjust material thickness for accurate cuts and fits.
  • Box Sizing:
    • Automatically adjust box sizes for inner or outer edges, depending on user preference.

* Using recess for screws on bottom side requires manual flipping of the surface.

How does it work?

The tool takes a JSON file as input (example below) and generates G-Codes for up to six sides of a box, with each side containing its own drill cutouts, recesses, and engravings. These pieces can then be assembled to construct a 3D shape.

The exported .nc files must be sent/executed with a G-Code sender e.g., Candle (free and open-source) to complete the task.

Warning: Operating CNC routers requires a safe environment to prevent exposure to dust, debris, and high-speed moving parts. Never place your hands near moving parts. Always ensure proper ventilation, wear safety goggles, and use hearing protection. Additionally, perform a simulation to ensure the final G-code does not attempt to drill or move into restricted and/or dangerous sections.

Download

By downloading our free software, you agree to the license conditions.

Windows 64-Bit Download

Version History

  • 1.2.2 (01.04.2025):
    • Minor bug fixes.
  • 1.2.1 (08.02.2025):
    • Replaced height with length in JSON to avoid confusion.
  • 1.2.0 (06.02.2025):
    • V-shaped endmill type added for automatic compensation.
  • 1.1.0 (26.01.2025):
    • Separation of feedrate for x-, y-, and z-axes for more control on speeds.
      • Removed common --feedrate argument.
    • Minor bug fixes.
  • 1.0.0 (22.01.2025):
    • Initial version.

Quick Usage

[Top]

Download the ZIP file and extract to a location. Copy the Example JSON file below and save it as test.json using a simple text editor. To keep the things simple, save it at the same location as the executable.

Example JSON file

The following file generates all six sides for MyPart, placing one hole and one rectangle cutout on the Top side. The top size of the box is 5×5 cm and the components are placed at (x = 1, y = 1) and (x = 3, y = 3) respectively. The visible sizes of the components are the same as drill sizes.

{
	"Generic": {
		"width": 5.0,
		"length": 5.0
	},
	"MyPart_Top": {
		"myRoundComponent#1": {
			"location_x": 1,
			"location_y": 1,
			"drill_diameter": 1,
			"call_name": "Hello",
            "visible_diameter": 1,
			"rotation": 0
		},
		"myRectangleComponent#1": {
			"location_x": 3,
			"location_y": 3,
			"drill_width": 2,
			"drill_length": 1,
			"call_name": "MIDILLI",
			"visible_width" : 2,
			"visible_length" : 1,
			"rotation": 0
		}
	},
	"MyPart_Bottom": {

	},
	"MyPart_Back": {
		
	},
	"MyPart_Front": {

	},
	"MyPart_Left": {

	},
	"MyPart_Right": {

	}
}

Depending on the command-line options, the other sides of the part will be created using different sizing. Read Coordinate system and effect of sizing parameters for more on different results of the arguments.

Note: JSON syntax is very strict. Ensure that the last line before each '}' does not end with a comma, while all other lines should. Use an online validation tool to confirm correctness.

Command line

Assuming that the JSON file is stored at the same location as the executable file, open a command window (Command Prompt, or PowerShell), then execute the following command:

.\GCodeGenerator.exe --json-file .\test.json --output-directory . --material-thickness 3 --cut-depth-per-pass 1 --box-height-3d 30

You will be provided with an output showing the current settings as following:

~~~~~ Settings ~~~~~
Outer sizing enabled: No
Components enabled: Yes
Side outline enabled: Yes
Screw diameter top in mm: 0
Screw diameter bottom in mm: 0
Screw head diameter in mm: 0
Screw head height in mm: 0
Screw extra margin in mm: 0
Recess depth in mm: 0
Feedrate on X-axis: 200
Feedrate on Y-axis: 200
Feedrate on Z-axis: 100
Bit shape: straight
Bit diameter in mm: 0
Material thickness in mm: 3
Depth per pass in mm: 1
Box height in 3D in mm: 30
Cut depth per pass in mm: 1
Simulation enabled: No

Each setting on the console output can be customized with command line arguments.

After completion, 6 files starting with MyPart_ and ending with .nc will be visible under test directory. Opening MyPart_Top.nc in a program which can parse G-Codes should display a view similar to the following:

3D view of the test project in the Candle software.

Execution of the G-Code will move at 200 feedrate and drill 1 millimeter (mm) at each pass at 100 feedrate to open the holes for the components of a material with the thickness of 3 mm. At the end, it will cut along the outline of the Top to separate it from the larger material. For more customization, read the Detailed usage section.

Coordinate system and effects of sizing parameters

[Top]

Read more on the following page:

Tip: If you want the overall size to be exactly as you specify in the JSON file, use the --outer-sizing option. If you want the usable inner area to be the same as you define, leave it as default.

Detailed Usage

[Top]

Below, the detailed usage of the tool and the standard JSON project file will be explained.

Command line arguments

If the program is executed with -h or --help option, the following quick help will be displayed:

  GCodeGenerator.exe [OPTION...]

  -j, --json-file arg           Project JSON file
  -o, --output-directory arg    Output folder
  -t, --material-thickness arg  Material thickness to cut in mm
  -b, --box-height-3d arg       Box height in 3D in mm
  -d, --cut-depth-per-pass arg  Depth per pass to cut in mm
  -p, --bit-shape arg           Bit shape for drill size compensation:
                                straight, or v-shaped (default: straight)
  -m, --bit-diameter arg        Bit diameter in mm for drill size
                                compensation (default: 0)
  -k, --bit-angle arg           Bit angle in degrees for v-shaped bits for
                                drill size compensation (default: 0)
  -f, --bit-cutter-height arg   Bit cutter height in mm at which the
                                maximum diameter is reached (default: 0)
  -g, --outer-sizing            Box sizes are for outside borders (inner
                                area will be smaller), default: inner
                                sizing
  -r, --recess-depth arg        The depth of recess in mm (Default: no
                                recess) (default: 0)
  -x, --feedrate-x arg          Feedrate to use for x-axis (default: 200)
  -y, --feedrate-y arg          Feedrate to use for y-axis (default: 200)
  -z, --feedrate-z arg          Feedrate to use for z-axis (default: 100)
  -l, --outline                 Enable side outline cutting (default: true)
  -c, --components              Enable component cutting (default: true)
  -e, --screw-size-top arg      Screw diameter for top side in mm (Default:
                                0 - no screws) (default: 0)
  -w, --screw-size-bottom arg   Screw diameter for bottom side in mm
                                (Default: 0 - no screws) (default: 0)
  -i, --screw-head-diameter arg
                                Screw head diameter in mm (default: 0)
  -a, --screw-head-height arg   Screw head height in mm (default: 0)
  -n, --screw-extra-margin arg  Screw extra margin in mm (default: 0)
  -s, --simulate                Simulate, do not write NCs
  -h, --help                    Show this help message and quit

Both short and long versions of the arguments can be used.

The arguments -j, -o, -t, -b, and -d are mandatory. Other arguments have default values as mentioned above. To set an argument to false, use the long version and assign the value false. For example, to disable outline cut, use --outline=false. Similarly, for activation of options, which are disabled by default, only use the argument. For example, to enable simulation, use either -s or --simulate. Argument values can be provided with a space or an equal sign if long versions are used. For instance, both --json-file test.json and --json-file=test.json are valid usage. For short versions, only space allowed, e.g., -b 30.

--json-file

A valid path to JSON file to be used as input. Can be a relative path (starting from the working directory) or an absolute path.

--output-directory

The directory to write the output files to. Using . (dot) will use the current working directory. The final files will be written into a new folder having the name of the --json-file.

--material-thickness

This value is used to calculate the depth required for creating holes for components and/or screws, in conjunction with the --cut-depth-per-pass argument. The value is in millimeters (mm).

Additionally, this value is used to determine the dimensions of the left, right, front, and bottom sides (if enabled) based on whether the --outer-sizing parameter is active. See Coordinate system and effects of sizing parameters for more info.

--box-height-3d

The height of the box in millimeters (mm). If --outer-sizing is used, this will be the outer height of the box. Otherwise, it is the inner height of the box.

--bit-shape

The shape of the endmill/bit/cutter. Currently straight and v-shaped cutters are supported.

Default: straight

--bit-diameter

The diameter of the bit or cutter can affect not only the size of drilled holes but also the overall dimensions of the cuts. This may result in slightly larger or smaller dimensions than intended. G-Code already supports compensation for cutter diameter using specific commands. This argument adjusts the coordinates to account for the bit diameter, ensuring accurate cuts and dimensions in case native compensation is not desired.

Default: 0, no compensation

--bit-angle

Angle in degrees which forms the v-shape. Only effective for v-shaped bits.

Default: 0, straight cutter

--bit-cutter-height

The height of the cutter in mm at which it reaches its maximum cut width. After this height (or after reaching this depth), always --bit-diameter value will be used. Only effective for v-shaped bits. Note that this is not the total height of the bit itself.

Default: 0, straight cutter, starting directly with --bit-diameter width.

--outer-sizing

If used, the sizes defined in the JSON file as well as the --material-thickness and --box-height-3d arguments will be used to create the outer volume with the given dimensions. Otherwise, these values will be used to create the inner volume with the given dimensions.

Default: false, use inner dimensions.

--recess-depth

The depth of the recess for components in millimeters (mm).

Recesses also take the sizing from visible_diameter (priority) or visible_width and visible_height properties. Recesses may be helpful to have slightly lowered shapes to e.g., stabilize or limit the movement of button caps. This value does not change the behavior of the screw head recess (See --screw-head-height).

Default: 0 mm, no recess for the components

Recesses also take the sizing from visible_diameter (priority) or visible_width and visible_height properties. Recesses may be helpful to have slightly lowered shapes to e.g., stabilize or limit the movement of button caps. This value does not change the behavior of the screw head recess (See --screw-head-height).

Default: 0 mm, no recess for the components

--feedrate-x

The speed at which the tool moves during cutting or engraving on x-axis, measured in units per minute (e.g., millimeters per minute). This value is crucial for controlling the precision and quality of the cut, with higher feedrates generally resulting in faster cuts but potentially lower accuracy or finish quality.

Default: 200

--feedrate-y

The speed at which the tool moves during cutting or engraving on y-axis, measured in units per minute (e.g., millimeters per minute). This value is crucial for controlling the precision and quality of the cut, with higher feedrates generally resulting in faster cuts but potentially lower accuracy or finish quality.

Default: 200

--feedrate-z

The speed at which the tool moves during cutting or engraving on z-axis, measured in units per minute (e.g., millimeters per minute). This value is crucial for controlling the precision and quality of the cut, with higher feedrates generally resulting in faster cuts but potentially lower accuracy or finish quality.

Default: 100

--outline

Enables side outline cuts, which adjust the dimensions of the sides according to the given sizes, based on the --outer-sizing property.

Default: true

--components

Enables the component output to cut circles and/or rectangular shapes through the --material-thickness.

Default: true

--screw-size-top

Screw hole diameter to be drawn as hole in millimeters (mm) on the top side of the box.

Default: 0 mm, no screws.

Brown: Screw diameter (or screw size)

--screw-size-bottom

Screw hole diameter to be drawn as hole in millimeters (mm) on the bottom side of the box.

Default: 0 mm, no screws.

Brown: Screw diameter (or screw size)

--screw-head-diameter

If the screws must be counterbore/recessed, any value given in millimeters (mm) (preferably greater than --screw-size-top or --screw-size-bottom) will create a circular shape to bury the head.

Default: 0 mm, protruding screw head.

Red: Screw head diameter

--screw-head-height

The depth of the screw-head to create counterbore/recessed screws given in millimeters (mm).

Default: 0 mm, protruding screw head.

Gray: Screw head height

The images below show how --screw-head-diameter and --screw-head-height affect the creation of screw head related recesses.

--screw-extra-margin

By default, screws are added at the four corners of the top and/or bottom side of the box, leaving a margin of --material-thickness from the sides. If an additional margin is desired, any value given in millimeters (mm) will increase this gap.

Default: 0 mm, no additional margin.

Green: Screw extra margin

--simulate

If used, simulates the settings, without writing to actual files.

Default: false, write to actual files.

--help

Shows the quick help with the list of arguments and their short descriptions.

JSON File

See the definition on this page: MIDILLI JSON File Definition.