02Home & Garden · Updated
How to Make a G-Code File for 3D Printing
Short answer
Create a model, slice it, then export machine instructions
To make a G-code file, open a 3D model in a slicer, choose settings for your printer and filament, then slice and export the toolpath. Check printer compatibility before running the file.
G-code is a text-based set of commands that tells a 3D printer how to move, heat, and deposit material. In everyday 3D printing, you usually do not write those commands by hand: a slicer converts a 3D model into a printer toolpath and saves it as a G-code file. The steps below apply to common filament (FDM/FFF) printers; resin printers generally use different sliced file formats.
What You’ll Need
- A computer with a slicer that supports your printer. Use the printer maker’s recommended software or another slicer with a matching machine profile.
- A 3D model file, commonly in STL, 3MF, or OBJ format. Use a model you created or are permitted to print.
- Your printer’s model name and reliable setup information, including its build volume, nozzle size, and supported filament types.
- The filament you plan to use, so you can select the correct material profile and temperature recommendations.
- A way to transfer the finished file, such as a memory card, USB drive, or supported network connection.
Step-by-Step
- Install a compatible slicer. Download the slicer from its official source and select a profile for your exact printer model. If your printer is not listed, check the manufacturer’s documentation before creating a custom profile. The profile defines important limits and motion settings; a close-looking but incompatible profile can make a job unsafe or unsuccessful.
- Import the model. Open the slicer and load the STL, 3MF, or OBJ file. Inspect the model in the preview: it should appear on the virtual build plate, at a sensible size, and without missing sections. Units can be a source of surprises, so confirm that the dimensions shown match the intended object.
- Choose the printer and material. Confirm the printer profile and select the filament type and profile that match the spool, such as PLA or PETG. Follow the filament maker’s temperature range and the printer maker’s limits. Do not assume that settings for one material or machine are safe for another.
- Position and orient the model. Move the object fully onto the build plate and rotate it to provide stable support and a suitable surface finish. Avoid placing parts outside the printer’s usable area. If the model is too large, use the slicer’s scale controls only if changing its dimensions is acceptable.
- Set print options. Choose a layer height, wall thickness, infill, and support strategy appropriate to the model and printer. For a first attempt, a standard profile is usually easier to evaluate than many custom changes at once. Add a brim or other bed-adhesion aid only when the model or recommended profile calls for it.
- Slice the model. Select the slicer’s slice or prepare command. The software calculates the paths and displays an estimate and layer preview. Wait for slicing to finish, then review the preview from the first layer upward. Look for missing parts, unsupported overhangs, empty layers, or travel paths that seem to leave the build area.
- Review machine and start commands. Check that the chosen profile uses the correct bed size, nozzle and bed temperatures, and start/end sequences for your printer. Start commands can home axes and heat components; incorrect custom commands can cause collisions or overheating. Avoid editing generated G-code unless you understand the command and your printer’s firmware.
- Export the G-code. Use the slicer’s export or save-to-file option and give the file a clear name. Save it with the extension and format expected by your printer, usually a .gcode file for many filament machines. Do not rename a different file type to .gcode; changing the name does not convert its contents.
- Transfer and verify the file. Copy or send the file using the printer’s supported method. Safely eject removable storage, then check the printer’s screen or control software to ensure the expected file appears. If the printer does not list it, verify the file extension, storage format, folder location, and compatibility instructions.
- Prepare and start the print. Make sure the printer is on a stable surface, the build plate is clear, and the correct filament is loaded. Start the job only after confirming the selected file and printer profile. Watch the initial layer: stop the print if the nozzle moves unexpectedly, strikes the bed, or material does not adhere as expected.
Common Mistakes
- Using the wrong printer profile: This can produce incorrect bed limits, temperatures, or start commands. Confirm the exact model and configuration, including any relevant hardware changes.
- Sending the model instead of sliced output: An STL describes geometry; it is not usually a ready-to-print G-code toolpath. Slice it first, then export the generated file.
- Ignoring scale or placement: A model can import at an unexpected size or sit partly beyond the build plate. Check dimensions and the whole preview before slicing.
- Choosing a material profile by guesswork: Filaments with different properties may need different temperatures and settings. Match the material and use manufacturer guidance rather than copying values blindly.
- Assuming every printer accepts the same file: Firmware, file naming, storage, and transfer requirements vary. Check the printer’s manual if a file is rejected or behaves unexpectedly.
- Editing G-code without understanding it: Commands can control heaters and motion. A small-looking edit may change startup behavior or cause a collision, so keep the original and use documented settings.
Tips
- Save a copy of the model and note the slicer profile and material used. This makes it easier to repeat a successful print.
- Change one setting at a time when tuning. That helps identify which adjustment affected the result.
- Use the layer preview, not just the finished-object image. It can reveal weak supports, gaps, or unexpected toolpaths before printing.
- Keep the printer’s firmware and slicer profile in mind when selecting options; a setting available in one setup may not work in another.
- For a first print, choose a small, familiar model and a standard profile. A short test can help confirm file transfer and basic printer operation.
Troubleshooting
The printer cannot see the file: Confirm that slicing completed, the file has the expected extension, and it is saved in a location the printer scans. Recheck storage and file-format requirements in the printer manual, then export a fresh copy if needed.
The printer refuses to start: Check that the file was sliced for the correct machine and that the selected material and printer are supported. If the printer displays an error, consult its manual rather than bypassing the warning.
The toolpath appears off the bed: Return to the slicer and verify the printer profile, build volume, model dimensions, and placement. Slice again after correcting the issue; do not try to compensate by forcing the print to run.
The print starts but the first layer fails: Stop if the nozzle is scraping, the bed is being struck, or the printer moves abnormally. Check leveling or bed calibration, surface cleanliness, filament loading, and the printer’s documented first-layer settings before reslicing or restarting.
The output is incomplete or unexpectedly different: Inspect the sliced preview, confirm that the whole model is present, and check for incorrect supports or settings. Re-export after changes and make sure you transfer the newest file rather than an older copy with a similar name.
Frequently Asked Questions
Can I make G-code without a 3D model?
Yes, but you need to create or obtain the toolpath another way, such as writing commands manually or using software for a specific machine task. For ordinary 3D printing, a model and slicer are the practical route.
Can I write G-code by hand?
It is possible, but it requires knowing your printer’s firmware, command dialect, coordinate system, and safety limits. A slicer is safer and more convenient for typical prints.
Is G-code the same for every 3D printer?
No. Many printers share common commands, but firmware behavior, machine dimensions, startup sequences, and supported features can differ. Use a profile intended for your printer.
Can I edit a G-code file after exporting it?
You can edit it with a text editor, but that does not make changes safe. Keep an untouched copy and avoid changing motion or heater commands unless you understand the effects and have reliable documentation.
Do resin printers use G-code?
Many resin printers rely on specialized sliced formats that store layer images and machine instructions, rather than the ordinary G-code used by many filament printers. Use the format and slicer specified for your resin printer.
Related
- KY Meaning: What It Means and How to Use It
- How to Store Dry Ice Safely and Keep It Longer
- How to Get Rid of Heartburn Fast and Safely
Further reading: Prusa Research. Details can change, so check the official page for anything that matters to you. Spotted a mistake? Tell us. How we write an answer.