Post Process from a script
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Post Process from a script
Hello,
Please help.
I am using FC 0.18 and I just need a script to post process the path since I am writing a macro to save G Code to a file.
I am using linuxcnc as a post processor and I have used the following without success
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced from the screenshot below ?
I have tried many combinations without success.
If there is another way to do it, please share as the script should be able to save without dialog box confirmation
I am able to manually post process the "Profile_Edges" path
Thanks
Please help.
I am using FC 0.18 and I just need a script to post process the path since I am writing a macro to save G Code to a file.
I am using linuxcnc as a post processor and I have used the following without success
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced from the screenshot below ?
I have tried many combinations without success.
If there is another way to do it, please share as the script should be able to save without dialog box confirmation
I am able to manually post process the "Profile_Edges" path
Thanks
- Attachments
-
- Script-Post-Process.jpg (70.93 KiB) Viewed 1502 times
- dubstar-04
- Posts: 698
- Joined: Mon Mar 04, 2013 8:41 pm
- Location: Chester, UK
- Contact:
Re: Post Process from a script
Could explain a bit more about the goal and the required outcome?
Post processing the path job will write GCode to a file using the selected post (linux_cnc for example)
Does this not achieve what you require?
Note that each operation contains generic gcode. A rough example (There are much better ways to do this using the Path.Utils):
job = App.ActiveDocument.getObject('Job') # Get the path 'job' from the current document
ops = job.Operations.Group # Get the operations group from the job
op = ops[0] # Get first operation from the job group
commands = op.Path.Commands # Get the commands from the operation
Thanks,
Dan
Post processing the path job will write GCode to a file using the selected post (linux_cnc for example)
Does this not achieve what you require?
Note that each operation contains generic gcode. A rough example (There are much better ways to do this using the Path.Utils):
job = App.ActiveDocument.getObject('Job') # Get the path 'job' from the current document
ops = job.Operations.Group # Get the operations group from the job
op = ops[0] # Get first operation from the job group
commands = op.Path.Commands # Get the commands from the operation
Thanks,
Dan
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Re: Post Process from a script
Thanks for replying
I would like the script to post process the file using the linuxcnc post processor (saved in the C:\Program Files\FreeCAD 0.18\Mod\Path\PathScripts\post) and save it without further intervention to a file on my computer so I can just use it to machine the part
I am trying to save the Path to a file so I get an output like this:
(Exported by FreeCAD)
(Post Processor: linuxcnc_post)
(Output Time:2020-04-18 23:24:07.240089)
(begin preamble)
G21
G90
G17
G40
G80
G21
(begin operation: Default Tool)
(machine: not set, mm/min)
(Default Tool)
M6 T1
M3 S15000
(finish operation: Default Tool)
(begin operation: Profile_Edges)
(machine: not set, mm/min)
(Profile_Edges)
(Uncompensated Tool Path)
G00 Z14.000
G00 X780.000 Y950.000
G00 Z6.000
G01 X780.000 Y950.000 Z-5.000 F600.000
G01 X780.000 Y150.000 Z-5.000 F1200.000
G01 X120.000 Y150.000 Z-5.000 F1200.000
G01 X120.000 Y950.000 Z-5.000 F1200.000
G01 X780.000 Y950.000 Z-5.000 F1200.000
G01 X780.000 Y950.000 Z-10.000 F600.000
G01 X780.000 Y150.000 Z-10.000 F1200.000
G01 X120.000 Y150.000 Z-10.000 F1200.000
G01 X120.000 Y950.000 Z-10.000 F1200.000
G01 X780.000 Y950.000 Z-10.000 F1200.000
G01 X780.000 Y950.000 Z-15.000 F600.000
G01 X780.000 Y150.000 Z-15.000 F1200.000
G01 X120.000 Y150.000 Z-15.000 F1200.000
G01 X120.000 Y950.000 Z-15.000 F1200.000
G01 X780.000 Y950.000 Z-15.000 F1200.000
G00 Z14.000
(finish operation: Profile_Edges)
(begin postamble)
G0 X0.000 Y0.000
M05
G17 G54 G90 G80 G40
M2
I would like the script to post process the file using the linuxcnc post processor (saved in the C:\Program Files\FreeCAD 0.18\Mod\Path\PathScripts\post) and save it without further intervention to a file on my computer so I can just use it to machine the part
I am trying to save the Path to a file so I get an output like this:
(Exported by FreeCAD)
(Post Processor: linuxcnc_post)
(Output Time:2020-04-18 23:24:07.240089)
(begin preamble)
G21
G90
G17
G40
G80
G21
(begin operation: Default Tool)
(machine: not set, mm/min)
(Default Tool)
M6 T1
M3 S15000
(finish operation: Default Tool)
(begin operation: Profile_Edges)
(machine: not set, mm/min)
(Profile_Edges)
(Uncompensated Tool Path)
G00 Z14.000
G00 X780.000 Y950.000
G00 Z6.000
G01 X780.000 Y950.000 Z-5.000 F600.000
G01 X780.000 Y150.000 Z-5.000 F1200.000
G01 X120.000 Y150.000 Z-5.000 F1200.000
G01 X120.000 Y950.000 Z-5.000 F1200.000
G01 X780.000 Y950.000 Z-5.000 F1200.000
G01 X780.000 Y950.000 Z-10.000 F600.000
G01 X780.000 Y150.000 Z-10.000 F1200.000
G01 X120.000 Y150.000 Z-10.000 F1200.000
G01 X120.000 Y950.000 Z-10.000 F1200.000
G01 X780.000 Y950.000 Z-10.000 F1200.000
G01 X780.000 Y950.000 Z-15.000 F600.000
G01 X780.000 Y150.000 Z-15.000 F1200.000
G01 X120.000 Y150.000 Z-15.000 F1200.000
G01 X120.000 Y950.000 Z-15.000 F1200.000
G01 X780.000 Y950.000 Z-15.000 F1200.000
G00 Z14.000
(finish operation: Profile_Edges)
(begin postamble)
G0 X0.000 Y0.000
M05
G17 G54 G90 G80 G40
M2
- dubstar-04
- Posts: 698
- Joined: Mon Mar 04, 2013 8:41 pm
- Location: Chester, UK
- Contact:
Re: Post Process from a script
Its a bit hacky but if you're not looking to do anything special then you should be able to do something like:
import PathScripts.PathPost
myPost = PathScripts.PathPost.CommandPathPost()
myPost.Activated()
This will require the output policy to be set to overwite or append unique ID in the preference or you could so it in python. See PathPreferences.py.
Thanks,
Dan
import PathScripts.PathPost
myPost = PathScripts.PathPost.CommandPathPost()
myPost.Activated()
This will require the output policy to be set to overwite or append unique ID in the preference or you could so it in python. See PathPreferences.py.
Thanks,
Dan
Last edited by dubstar-04 on Tue Apr 21, 2020 9:06 am, edited 1 time in total.
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Re: Post Process from a script
Thanks again for your input. I am trying to learn Python as I am getting better at FreeCad as well.
I have tried your suggestion but I get an error message and I am not sure that I will achieve the expected result.
On FreeCad 018, the path preferences as shown in your picture has changed.
I am just wanted to write the G-Code output to an external file using the post processor file linuxcnc_post.py
The following code is from the wiki page
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced to be able to write the G- code path to an external file using the linuxcnc_post ?
Thanks.
I have tried your suggestion but I get an error message and I am not sure that I will achieve the expected result.
On FreeCad 018, the path preferences as shown in your picture has changed.
I am just wanted to write the G-Code output to an external file using the post processor file linuxcnc_post.py
The following code is from the wiki page
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced to be able to write the G- code path to an external file using the linuxcnc_post ?
Thanks.
- Attachments
-
- Script-Post-Process1.jpg (38.37 KiB) Viewed 1371 times
- dubstar-04
- Posts: 698
- Joined: Mon Mar 04, 2013 8:41 pm
- Location: Chester, UK
- Contact:
Re: Post Process from a script
Inventthis wrote: ↑Tue Apr 21, 2020 5:33 am
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced to be able to write the G- code path to an external file using the linuxcnc_post ?
Thanks.
The objectName should be a list of the objects to be post processed. using this method will only process the gcode from each object you pass.
An example of posting all the ops from the operations group:
Code: Select all
from PathScripts.post import linuxcnc_post as pp
obj = App.ActiveDocument.getObject("Operations").Group
pp.export(obj, 'C:/Documents/FreeCAD-Gcode/outputFile.cnc', '')
Thanks,
Dan
Re: Post Process from a script
Thanks! Bookmarked this one!
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Re: Post Process from a script
Thank you so much Dan, it worked. I just have to disable the Input box that pops up for validation [ok] and [cancel] since from the script running I do not wish any more user interaction.
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Re: Post Process from a script
Hello Dan
I found the argument in linuxcnc_post to get rid of the validation box
pp.export(obj, 'C:/Documents/FreeCAD-Gcode/outputFile.cnc', '--no-show-editor')
Thanks again for your help
I found the argument in linuxcnc_post to get rid of the validation box
pp.export(obj, 'C:/Documents/FreeCAD-Gcode/outputFile.cnc', '--no-show-editor')
Thanks again for your help
- Inventthis
- Posts: 23
- Joined: Tue Mar 17, 2020 8:11 pm
- Location: USA
Re: Post Process from a script
Hello Dan,dubstar-04 wrote: ↑Tue Apr 21, 2020 8:26 amInventthis wrote: ↑Tue Apr 21, 2020 5:33 am
import linuxcnc_post
linuxcnc_post.export (ObjectName,"C:/Documents/FreeCAD-Gcode/outputFile.cnc", " ")
What ObjectName should I referenced to be able to write the G- code path to an external file using the linuxcnc_post ?
Thanks.
The objectName should be a list of the objects to be post processed. using this method will only process the gcode from each object you pass.
An example of posting all the ops from the operations group:
I hope that helps.Code: Select all
from PathScripts.post import linuxcnc_post as pp obj = App.ActiveDocument.getObject("Operations").Group pp.export(obj, 'C:/Documents/FreeCAD-Gcode/outputFile.cnc', '')
Thanks,
Dan
You are correct , I just found out that the information from the "Default tool" is not in the G-code such as:
(Default Tool)
M6 T1
M3 S15000
Do you know how to add that to the post processor script?
Thanks