MIDILLI G-Code Generator for CNC Routers

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.

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.

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.
  • 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:

Version History

  • 1.0.0 (22.01.2025):
    • Initial version

Quick Usage

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,
		"height": 5.0
	},
	"MyPart_Top": {
		"myRoundComponent#1": {
			"location_x": 1,
			"location_y": 1,
			"drill_diameter": 1,
			"call_name": "Hello",
            "visible_diameter": 0,
			"visible_height" : 1,
			"visible_width" : 1,
			"rotation": 0
		},
		"myRectangleComponent#1": {
			"location_x": 3,
			"location_y": 3,
			"drill_width": 2,
			"drill_height": 1,
			"call_name": "MIDILLI",
			"visible_height" : 2,
			"visible_width" : 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: 100
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 100 feedrate and drill 1 millimeter (mm) at each pass 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

In the MIDILLI G-Code Creator, 2D coordinate system is used for the components, but the box height is also specified specified to enable assembling the generated sides into a complete box structure.

The coordinate system with direction of increase and direction of rotation in the MIDILLI G-Code Generator.

Each side of the shape has its local origin starting at the top-left corner (x = 0, y = 0). The default rotation of the added components is set to zero (0) degrees, with rotation occurring clockwise. For example, a 90-degree rotation will rotate the component 90 degrees to the right. All coordinates and locations in the JSON file are given in centimeters (cm), and the rotation is measured in degrees. This is how the final box without any components may look like if all sides are exported:

The dots represent the local origins of each side.

The two images below show how each side appears in the 2D view. Imagine pressing the 3D box above and flattening it to see this perspective:

Sizing summary if inner-sizing option is used (by default).

If the inner-sizing option is used (enabled by default), the left and right sides will have a greater height to cover the back and front sides. Additionally, the left, right, back, and front will be slightly taller to maintain the specified inner volume. The top and bottom will then fit in accordingly.

Sizing summary if outer-sizing option is used (can be enabled with command-line argument).

If the outer-sizing option is enabled (via --outer-sizing command-line argument), the front and back sides will be slightly shorter to align with the width of the left and right sides. Similarly, all four sides (left, right, front, and back) will be slightly adjusted to maintain the specified outer volume. The top and bottom will then fit precisely on top of and beneath the other sides.

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

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
  -m, --bit-diameter arg        Bit diameter in mm for drill size
                                compensation (default: 0)
  -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
  -z, --outer-sizing            Box sizes are for outside borders (inner
                                area will be smaller)
  -r, --recess-depth arg        The depth of recess in mm (Default: no
                                recess) (default: 0)
  -f, --feedrate arg            Feedrate to use for axes (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 -m, -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 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-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

–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

–feedrate

The speed at which the tool moves during cutting or engraving, 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

–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

Simulate 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.

Frequently Asked Questions

No questions so far. Let us know by sending us a message.