A Polar Pre-Processor for the Pen Bot Written in Python

I got a little push back on the Cartesian to Polar gcode processor because it was a Windows, Visual Studio C# program. I rewrote it in Python, to make it more accessible to other operating systems.

I don’t do much Python programming, so I probably did some thing in a very non Python style, but here is is.

Usage: The program will accept 1 or two command line arguments. The first is the file you want to convert. The second the the output file name.  If you skip the second, it will just append “_polar” to the input file name.  For example box.gcode will be converted and output as box_polar.gcode.

PolarPreProcessor.zip (python file)

Before and After Example GCode

Here is the gcode for the logo if you want to test.

Visual Examples

To get a feel for what the translation looks like, here is what a simple square looks like in gcode before translation.

And here is is after translation

Here is what that python logo in the first image looks like in gcode after translation.


You must have python 3 installed. You also need the “pathlib” library. Type “pip install pathlib” in your python scripts folder to get that. The easiest way to run it, is to put the file you want to convert in the folder with the python script. To convert a file called test.gcode you type “python PolarPreProcessor.py test.gcode. It will print done when complete and you will now have a new gcode file called test_polar.gcode. If python is not in your path, you will need to put the location info in front, like c:python3python PolarPreProcessor.py test.gcode.


Here is a video of it drawing the Python logo.


Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks

17 Responses to “A Polar Pre-Processor for the Pen Bot Written in Python”

  1. Faizal Shaikh

    Brother thanks alot for this blog.
    can i get the GCODE which you have converted to polar via python?
    thanks again.

  2. bdring

    I added a link at the end of the post with some before and after gcode. The gcode draws a simple 40mm square centered on the coaster.

  3. Faizal Shaikh

    you mean to say “square_polar.gcode” is in form of GCODES but it works for polar printer.

  4. bdring

    The firmware is Grbl so it wants to see GCodes. It normally works in inches or mm, but ultimately that is just steps on the motor. This machine is designed to work in mm and degrees. The gcode starts out as normal cartesian mm coordinates. That needs to be converted to mm and degrees. As far as Grbl is concerned it is running normal gcode, but it has been processed to produce images on a polar machine.

    If this machine were to use unprocessed gcode, it would produce a distorted image. We therefore modify the gcode for an “anti” distorted image so it looks ok when printed on the machine.

  5. Faizal Shaikh

    i have taken a screenshot of your “square polar.gcode” file, where i can post that image?

  6. bdring

    The gcode in a viewer should look like four vertically linked arcs.

    You can email me at bdring@ this domain

  7. bdring


    I have added some screen shots.

  8. Faizal

    Thanks alot.
    And yeah for sure I will seek out for help from you.
    I am making 3d polar printer, so I have to look out for z axis increment too.
    Thanks alot for polar processor code.

  9. Bugs

    Thanks so much for this! Exactly what I need to add a new feature/mode to my little polar laser engraver besides raster-engraving by spiralling outwards from the centre. I’ve been putting off trying to write something like this myself for months!

    Nicely commented code, too, which as a decidedly rudimentary programmer I’m especially grateful for.

  10. David

    What software are you using to ‘center’ your gcode?
    I’ve tried G-code Ripper and it is skewing my work to one quadrant.

    Keep up the great work!

  11. bdring

    I was using V-Carve from Vectric. It allows the 0,0 to be placed anywhere.

  12. Cristiano Almeida

    What a beautiful project, I will try to make one, I already did a mini cnc with a CD drive and this computer works great. I understood the mechanical part and part of the software, would it be possible to step-by-step in video from assembly to final drawing so that mere mortals like me could succeed? Once again, congratulations on the beautiful project.

  13. BrAzILiAn_Boy

    Friend I’m not familiar with python, could make a video of how to run python and make the machine work, would be of great help. Congratulations on your work.

  14. Brian H

    Hi! Nice work. I was wondering how you generate the original g code without any G02 or G03 arcs.

  15. bdring

    I typically use products from vectric like vcarve. They have arc free post processors.

    Inventables Easel also is arc free.

    It seemed easier to use them than add arc to my code.

  16. DocVok


    love that machine. I built something similar, not for drawing but for dragging around a steel ball with a magnet in sand. Sort of a CNC-Zen-garden.
    I am currently running into the problem of how to set up the rotary axis feed rate in grbl as it is depending on the radius. How did you solve the problem? Did you use the outermost radius as the reference?


  17. bdring

    Not sure how well my method worked, but…

    My method divides moves into small lines and converts those to polar. It then calculates the the real world lengths of the before and after lengths. It then applies that ratio to get a new feed rate.

    A single long move in cartesian space will result in lots of little moves, each with their own feed rates.