Using the Python Console to Generate G-code

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
lmd123
Posts: 1
Joined: Mon Jun 11, 2018 7:47 pm

Using the Python Console to Generate G-code

Post by lmd123 »

Hello everyone,

I am trying to automate creating tool paths and g-code through python scripting. I have dug a bit into PathScripts, but they are pretty vast and call objects from all over the place. It seems like a lot of Path is tied into the Gui/Qt files which I do not have a lot of experience with.

Could anyone offer any advice on how to use the python console to take a part, create a path file and input setup orientation, tools, outputs, etc. with an end result of creating a toolpath that can be exported to g-code? Obviously this is a big task- automating tool path generation, but I just want to know whether you guys think it's possible/have any advice. I have tried using the _trackAll function in PathLog, but the places it logs in PathScripts are limited. I'm about as far as just using PathScripts.PathJob.Create('Name', base, None) and then things get messy. When I try to use other functions after this there are usually missing inputs, etc. and I get a lot of errors back.

Sidenote:
I am pretty new to FreeCAD, but I was delighted to see the addition of a CAM tool with v0.17. You guys really have done a great job with it, and I can't wait to see how much progress you guys make on it.

Thanks!
mlampert
Veteran
Posts: 1772
Joined: Fri Sep 16, 2016 9:28 pm

Re: Using the Python Console to Generate G-code

Post by mlampert »

Every Op has a `Create` function in the source code which you can use. You start by creating a Job, the ToolControllers and then the ops. However, if you create them that way you cannot display them because they won't have a view provider.

The reason for the Create function is exactly this, headless (batch) operation.

I would highly recommend though that you familiarize yourself with the ops through the wiki and the UI first. Since you can't look at interim results debugging these scripts is a bit tricky.

Good luck!
Post Reply