We recently surveyed G-Wizard Editor customers to see what they were doing with the software.  Here’s what they came back with:


The survey provides a good cross section of uses.  Customers could choose all of the choices that applied to them, and clearly a lot of folks were doing multiple things with the Editor.  Let’s talk just a bit about what each one means and how it might benefit your CNC activities.

Writing G-Code From Scratch

I think this is the one that most commonly comes to mind, and if you stop here (please don’t, the other uses are good stuff!), you probably don’t think you could ever use a G-Code Editor.  After all, it’s so much easier to let the CAM software create your g-code, isn’t it?  Yet, we still see a surprising amount of hand written g-code out there.  Why do it?

For one thing, there are certain things that CAM is good at and certain other things it is terrible at.  A lot of simple parts can be programmed by hand faster than you could do a drawing in CAD to run your CAM against.  So, we could say CAM is not especially good at really simple parts.  CAM is also not very good at macro programming, and you can get a lot of benefits from macros and subprograms.  Most readers will be familiar with the notion of parametric CAD.  In fact many of you probably prefer to use a CAD program that is parametric.  But did you know that your g-code can also be parametric?  You can have variables change the behavior of the g-code.

I have a good friend who hand programmed a collection of g-code routines to make guitar parts.  You might think these would be the hardest possible things to hand program with their smooth flowing curves, and I know my friend had to work hard to put them together.  But now that he has them, he has powerful tools to make these parts (which he sells to the community of luthiers here) very custom to the needs of each guitar they’ll be used on.  Even though the programs were a lot of work to write, he has completed avoided the need to do a CAD drawing and CAM session for each little variation of one of these parts.  Parameterizing the g-code in this way is often called “Family of Parts” programming, because you can use one program to manufacture entire families of similar parts just by changing the parameter variables.

You can do much the same for simpler parts.  A great area for this is fixture programming.  It’s repetitive and things are often laid out on simple grids for plate fixtures.  A lot of the work may simple boil down to drilling and tapping holes in the right places.  This is easy stuff to do in a hand-coded nc program.

Learning G-Code

We get lots of students in at CNCCookbook who want to learn g-code.  Our free GCode Tutorial is one of the most popular if not the most popular NC Programming resources on the web.  When a semester starts, we get block signups from students looking to use the software in class. Pencil, paper, and books are fine, but there’s nothing like a fully interactive simulator to help you get your NC Program running and to help you understand what it’s doing.  In addition, G-Wizard has features that are specially designed to make diving into g-code much easier for beginners.

For example, our Hints feature tells you what each line of code will do in plain English.  Students tell me that the Hints are an absolute life saver that helps them come up to speed on the g-code radically faster.


Hints are in the lower right corner, below the graphical simulation…

Any time you click on a line of g-code or a portion of the graphical plot, you’ll see a hint for the line of g-code you’ve selected.  These hints tell you everything that’s going on with that line, including a lot of things that are otherwise hard to come by.

Checking G-Code for Errors Before Running It

What’s the cost of wasted time?  A program gets onto the machine only to discover something is wrong with it.  In most cases the machine and operator are now idle while they wait for a fix.  Even in a one man shop it’s a nuisance to have to go back and redo the CAM at the workstation and get a fresh version for the machine.

What about the cost of scrap?  You run the program and an errant move scraps the part.  If you’re particularly unlucky, your machine may now be wearing a new blemish as a reminder of the mistake.

Many don’t think CAM programs ever produce errors of this kind, but anyone who has worked with CAM for very long knows that sooner or later you’re going to encounter one.  With that in mind, it should come as no surprise that a great many like to simulate their programs while they’re freshly posted from CAM before they head over to the machine to try to run them directly.  A good simulator catches all kinds of errors.  G-Wizard Editor is particularly meticulous in its error checking.  For many simulators, you just squint at the graphical plot to see if all looks well.  With G-Wizard, we check for a lot of errors that aren’t even visible on the plot.  For example, running at feed speeds (which implies you’re doing some cutting) without having turned the spindle on.  Or having an arc programmed where the two endpoints differ from the center by more than an allowed tolerance.  Running the first one will likely result in a broken endmill if you don’t catch it in time.  Running the second will cause your machine controller to alarm out, perhaps not until it actually executes that code somewhere in the middle of running the program.

G-Wizard even allows you to set soft limit travel alarms.  This can be particularly useful for Z, where you may not want the endmill to descend lower than a certain value lest it start carving up tables and vices.

Soft Limit Alarms are set on the Info Tab…

Modifying CAM Generated G-Code

This is the number one use for the G-Wizard Editor and I’ll be it has some of you scratching your heads.  Why would I want to modify my CAM software’s g-code?

I’m so glad you asked!

Having the ability to modify your CAM generated g-code opens a tremendous number of opportunities and flexibility:

– Post Programming:  A G-Code Editor makes it a lot easier to do post development for your CAM because it lets you see what impact your changes are having on the g-code that’s output.  Having the right post (and often a small library of posts) can help eliminate some of those annoying little steps that have to be constantly attended to manually.

– Common Features:  Create a library of common features that often appear on the kinds of parts you machine.  Pipe fittings and fasteners are two common examples where there is a lot of standardization.  Once you have a library of these subprograms available, it can be faster to plug them into your CAM generated overall part program than to re-program those features on every new part.  Your company’s logo is another good example if you want to engrave it on most parts you make.

– Setup:  Much can be done to simplify setup and make it less error-prone for the operator.  This ranges from inserting helpful messages for the operator to using a probe to sweep a vise or fixture and then doing coordinate rotation so no tramming is necessary.  This sort of thing can save considerable setup time.  Custom g-code macros can also check that offset data and work shifts are within a range to help reduce the likelihood of problems there.

– Custom Accessories and External Devices:  You may have create a series of custom accessories for your machine that need a little hand programming to make full use of.  Such accessories could range from the fairly complex, such as right angle cutting heads to something super simple, like dipping a tap into a container of tapping fluid before each hole is tapped.  Other examples include communicating with printers, bar code readers, or metrology devices of various kinds.  I’ve seen programs written that operated a solenoid switch to an air line that locked and unlocked the workholding fixture.  It was set up so that the tip of an endmill was used to activate the switch as needed.  In another case an air-operated indexer was being used this way to make it possible to do 4th axis style machining.  On lathes, I’ve seen programs written to position a wire down the center of a hollow part so it would be captured when parted off.  The wire then carried the part over to a hopper that had a scraper to drag the part off the wire and let it drop into the finished part hopper.  It’s easy to make a library of subprograms that makes these things reusable without requiring reprogramming every time.

– Parameterize a Generic Part:  Start with a CAM generated program and go back into it to convert key dimensions and coordinates to variables that allow these different aspects of the part to be parameterized.

– Special Cycles:  Deep Hole Drilling is hard.  Most of the built-in cycles are not really optimal.  For example, they may retract too far.  You don’t want to retract the tip of the bit out of the hole lest coolant wash chips back down the hole.  With work-hardening materials this can cause real mayhem.  But you can always right a custom cycle that behaves exactly the way you want it to.  Many shops have reaped great benefits by substituting a carefully hand-optimized drilling cycle for the canned cycle that came with the controller.  And it’s easy to do.  You have the custom cycle in a subprogram that gets called whenever needed.  You can either use a custom post to summon the cycle (perhaps based on the hole depth) or search and replace in a GCode Editor to make sure it gets called as needed.  G-Wizard Editor comes with a Conversational Wizard that will program up a state of the art drilling cycle based on whatever recipe you want.

– Safety Checks:  It’s not uncommon to need to be sure that large objects in the spindle not turn faster than a rated speed.  On the lathe, you may want to make sure when CSS (Constant Surface Speed) is in use that there is a speed limit so that a large poorly balanced workpiece or chuck doesn’t get spun up too fast.  The analagous situation on a mill would be spinning a boring head too fast.  This can be done by adding macro code that checks these things when the spindle speed is set.

– Personalize and Customize:  Serial numbering is a common example.  If you’re lucky, your machine has a neat cycle like the Haas engraving cycle that takes care of it for you.  But if not, you can always write code to do serial numbering that bumps up the serial number each time the part is made.  There are many other examples where each part needs to be different in some way from the others, even though they are mostly the same.  I had a customer who manufactures the same part that a lot of his dealers resell under their own name.  He uses macros to engrave each customer’s logo on a run of parts when they order.- Optimizations for Speed

– Tool Life Managment:  It’s pretty easy to come up with a set of macros to do tool life management if your control doesn’t have those features built in.  You just need to keep some non-volatile variables (they save their value when the machine is shut down and remember the next time it is started up) that track how many parts a particular tool has made.  At the start of a part, macros check to see whether the tool should be changed before the run begins.  A similar idea can be used to turn the chip conveyor on or off periodically.  Given the proper sensors on the machine, you can even set up macros that check whether a tool has become chipped or broken and then switches automatically to a backup tool so things can keep running in a “Lights Out” situation.  I’ve even seen macros that change a wear offset by 0.001″ for every N parts made and then make an automatic switch to another tool after a certain number of parts have gone by.

– 1..N Parts Flexibility + Rework:  Who here hasn’t had to do some parts rework?  Perhaps a tool broke or something wasn’t set up quite right.  The green button was pushed, the operator went on to other things, the program ran, but the part isn’t really finished.  If you’re lucky, a little rework will save the parts from the scrap bin, but that rework often means you need to do a little hand modification of the CAM software’s g-code.  Or perhaps you just want flexibility in how many parts will be made per setup.  You’ve got a fixture that holds 16, but maybe you only need 4 one day and 8 the next.  Minor mods to g-code make this kind of thing easy.

– Probing:  Probing is one of the most interesting and productive areas for adding a little custom code to your CAM-generated programs.  The most common use for probing is to determine part location for machining.  But, probes can also be used to measure features.  This is great for automating part inspection, but it turns out that by measuring features you can increase the accuracy of your part program as well.  Renishaw has made a real science out of this with their innovative approach to manufacturing which they call “RAMTIC”.

There are many other things folks are doing to their CAM Software’s g-code.  Performance tuning is a big opportunity as we’ve all seen that CAM doesn’t always make the swiftest decisions.  Watch nearly any program run and ideas to eliminate waste quickly come to mind.



Who knew there were so many great uses for g-code editing?  I’m sure many felt that hand writing g-code of any kind was a dying art when in fact it is the secret weapon of many modern and highly automated manufacturers.

G-Code certainly looks arcane and hard to learn, but in fact it’s pretty straightforward.  If you’ve never tried to learn some, give it a shot with our Free G-Code Programming Tutorial.  Be sure to hook up with the Free 30-Day Trial of G-Wizard Editor too–it’ll make the process even easier.


Like what you read on CNCCookbook?

Join 100,000+ CNC'ers!  Get our latest blog posts delivered straight to your email inbox once a week for free. Plus, we’ll give you access to some great CNC reference materials including:

  • Our Big List of over 200 CNC Tips and Techniques
  • Our Free GCode Programming Basics Course
  • And more!

Just enter your name and email address below:

Full Name
Email *
100% Privacy: We will never Spam you!