About a month ago, I wrote a post about PCB milling with FlatCAM. In that post, I explained how to generate G-code for PCB milling from Gerber files exported from EasyEDA. The process was a bit cumbersome, as it required several manual steps to set up the FlatCAM project and generate the G-code.

I also shared a series on YouTube where I walk through the process.

At some point in writing that article, I realized that I could automate the process, because FlatCAM has an integrated TCL language interpreter and script engine built in. I took what I learned and recreated the steps from the blog post in script form.

The script is available here.

The script loads the default EasyEDA Gerber files by name from the c:/temp directory. It creates all the necessary geometry, mirrors the bottom layer on the Y axis, and creates CNC jobs for the bottom and top isolation layers. It gets as far as loading the Excellon files for drills and alignment drills, but there seems to be a defect in FlatCAM that prevents the script from creating the CNC job for the drills. I have not been able to figure out why this is happening, but I will update the script when I do. I’ve got the FlatCAM source loaded locally, but I have thus far not been successful in fixing the problem in order to submit a pull request to the project. So, for now, you’ll have to create the drill jobs manually.

Since the script ends in a manual step, I left commented out the code which actually saves the CNC jobs. It’s a minor step at the end, and I don’t want to forget to manually create the drill job, so I leave this out for now.

In order to use the script, simply unzip your EasyEDA Gerber files into the c:/temp directory, and then run the script from the TCL console in FlatCAM. You can load the file directly. Once you click the play button in FlatCAM, the script will run, and you’ll have to click back to the plot area to see the results. Then create the drill geometry & jobs, save CNC files, and you’re ready to go.

I hope the script is helpful to someone, I know it’s saving me a lot of time already!