What is a G Code Simulator & How to Use One

Screen Shot of NC Viewer G Code Simulator

I’m a hobby machinist, why do I need a g code simulator? I asked the same question for a long time. However, as I learned more about CNC machining, I found myself using a g code simulator to save time. Say you have a g code program that you just created or downloaded. How do you know if it will work? You could take it to your machine and set your x, y & z origin (0,0,0) location safely away from the work table and then run the program. What if something doesn’t work they way you expect and you need to modify the g code. Or worse, you damage your machine. This is where a g code simulator can really help.

Introduction

I started using a g code simulator when I was experimenting with engraving programs. That is, programs the generate g code to engrave text. I didn’t trust the g code the programs were generating. I wanted a way to test the g code. This was a perfect case for a g code simulator. I could test the g code without risking my machine or walking downstairs into the garage.

What is a G Code Simulator

A g code simulator or g code viewer is a software tool that lets you test g code you created. The software reads the .nc file just as your CNC machine would and creates a graphical representation of the tool paths and movements of the machine.

NC Viewer – The G Code Simulator I Use

Ok, so I want to use a g code simulator, where do I get one? My favorite is called NC Viewer a free browser based tool. This runs directly in your browser window. No need to download or install a program. It’s also mobile friendly.

Click the link below to check it out…

https://ncviewer.com/

How to Use a G Code Simulator

The following is specific to NC Viewer but the process will be similar for other simulators. The main screen of NC Viewer is annotated in the image below with the key functions of the tool.

 

Screen Shot of NC Viewer G Code Simulator with annotations for the main functions of the tool

Main Features of NC Viewer

    Step 1 – Click the link to navigate to NC Viewer.

    Step 2 – Load you G Code into the program.

You can either use the file menu in the top left portion of the window or copy and past your g code into the g code window on the left.

    Step 3 – Click the “Plot” button in the G Code window

    Step 4 – Click the “Play” button in the plot area to see a simulation of your g code.

You can also step through the code line by line. To step through the G Code line by line, click a line of G Code in the G Code window and us the up and down arrow keys.

User Tip – If you do not see a tool path, try zooming out or panning around the screen.

Tips for Using a G Code Simulator

The following list of tips will help you get the most out of looking at your g code in NC Viewer.

     1 – The origin

The X, Y, Z = 0 location is represented by the intersection of the red green and blue lines. This is very helpful if you are not exactly sure where to set the origin when setting up your part on the machine.

    2 – Zoom, Pan & Rotate

The plot area image can be manipulated by using the view cube in the top right section of the plot area. For example, this is helpful if you want to confirm the Z = 0 location relative to the tool paths.

    3 – Reset the View

If you want to restore the original view, simply click the “Home” button in the top right section of the plot window. This is helpful if the rotating gets away from you. It’s a quick way to reset the plot view.

    4 –Find G Code

If you want to find a line of G code from the plot window, you simply click on the section of the tool path and the line of G code is highlighted in the G code window.

Conclusion

A G Code Simulator is a great tool for hobbyists and professionals alike. I don’t use an external simulator every time. If I am making my G Code in Fusion360 then I use the build in simulator feature. However, if I am using another program, I run a simulation in NC Viewer before taking the code to my machine.

Special thanks to Xander Luciano the creator of NC Viewer. I appreciate the tool you created and your willingness to share it with the machining community. Check him out on Instagram @XanderLuciano

Thanks for reading. Until next time… Tim

14 Comments

  1. Mauricio

    Very nice as an alternative I make a holder for a ball pen in the same place as the original tool so I run the machine and check if everything is perfect
    But I really like the simulator and I will try it
    Thank you Tim

    Reply
    1. Tim (Post author)

      Mauricio, excellent, let me know what you think of the NCviewer.

      Reply
  2. Jack

    I enjoyed using the viewer. Is there a way to combine multiple G code files (different tools) on the same view?

    Reply
    1. Tim (Post author)

      Hi Jack, Good question. The answer is yes, you can combine multiple gcode programs with different tools and run them in NCviewer. I just did a test where I took operation 1 (OP1) from a part I designed that used a 1/8 endmill and combined that will OP2 that used a 1/4 endmill. I just copied and pasted the code from my text editor into the gcode window of NCviewer. I placed the OP1 code first and then pasted the OP2 code directly after then end of the OP1 code and clicked plot.

      Reply
  3. Eddie C

    Question. I’m using. A shapeoko xxl. With carbide create & carbide motion. When beginning a project at 40% completed. Do I delete the gcode prior to that position. Or is there certain lines from the beginning of the gcode I need to the program to run successfully.

    Reply
    1. Tim (Post author)

      Eddie, ah the dreaded half finished part! I have run into this a few times. I typically just run the entire program again. While it is possible to edit the gcode file to eliminate the code for the part that was already machined, it isn’t as simple as just deleting the code. You will need to retain several of the header lines in the file. I find the extra time, effort & risk of trying to modify the file is greater than just running the program again. If you do choose to modify the gcode, this is a perfect application for a gcode simulator.

      Reply
  4. CHRISTOPHER

    I love this works very nice, Is there i get a local copy of this on my machine. Also, how can i add this to my machine simulation inside my CAM system?.

    Reply
    1. Tim (Post author)

      Christopher, great to hear from you. I appreciate the comment. Glad you found the Gcode Simulator useful. NC Viewer can be used offline as its automatically cached by your web browser. As for integrating with a CAM package, you would need to contact the creator of NC Viewer, Xander Luciano.

      Reply
  5. Stefan

    It’s not that easy as you described it. I loaded one of my NC-programs into the ncviewer clicked on PLOT clicked on play. But I saw nothing. This means the G-code-File must fullfil some additional requierements that go beyond what gcode-control-programs like grbl-gcode-sender or ESTLCAM need for milling. The file I loaded was in practical use by me and produced excellent results on a real machine using ESTLCAM and Beamicon. So can you provide a small demo-program that has all the additional commands that are neededto make ncview show the toolpath?

    best regards

    Stefan

    Reply
    1. Tim (Post author)

      Hi Stefan, I appreciate your comment and very glad you sent a copy of the .NC file to me. When I plotted the file you sent to me in NCViewer, I had to zoom out to see the tool path. I will add a note to the blog post above to help others if they run into a similar issue. NCViewer does not require any special or additional commands in a .NC file to plot tool paths. It’s a really great tool to learn hand coding. You get real time feedback on your gcode. If you have additional questions, feel free to email me at Tim@DIYMachining.com

      Reply
  6. Steve

    I generate G Code from Inkscape 0.92 This code is works on my Maslow CNC Router but does not run in NC viewer. The output from Inkscape does not insert “N Line Numbers” (a bummer). and it leaves a space after X, Y, Z, & F so the program doesn’t run in NC Viewer. I haven’t found a way to automate and correct this issue. My Maslow will except both formats.

    Reply
    1. Tim (Post author)

      Steve, that is strange. The code I generate in Fuion360 does not have line numbers (“N” numbers) and NC Viewer runs those programs without any issue. I also just tried a program that had spaces after X,Y,Z & F values and that program ran as well. Will you post an example of the code you cannot run in NC Viewer here or send a copy to me at Tim@DIYMachining.com ? I am very interested to understand what the problem might be.

      Reply
  7. Jeff Flora

    I have been using NCviewer for about a year now. It is a great tool. Recently, while working with a program for a 4 axis horizontal mill, I somehow got the program to plot the tool path as the code scrolled down, creating a “trace” effect on the screen. I’m not sure how I did this and have been trying to re-create the happy accident, but have been unsuccessful. Did I stumble on a glitch, or is there a way to purposefully use NCviewer this way?

    Reply
    1. Tim (Post author)

      Hmm, that’s a great question. I haven’t been able to create the trace effect. I will reach out to the creator and see if this is an option. Perhaps I am missing a setting.

      Reply

Leave a Comment

Your email address will not be published. Required fields are marked *