Path Postprocessing without GUI

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
WayofWood
Posts: 62
Joined: Mon Nov 26, 2018 4:59 pm

Path Postprocessing without GUI

Post by WayofWood »

Hi all,

I am trying to write a really simple script to run on the command line. The purpose of this script is to simplify basic tasks on the CNC - such as creating a simple hole.

The code below works flawless in the FreeCAD Gui and writes the gcode for a 35mm hole. When I run the same code on the command line the script does not update the diameter of the hole, and writes the gcode for a 25mm hole. The file saved after the recompute looks broken.

As I am just testing the waters of scripting in FreeCAD there is most likely there is a very simple mistake in my code and I would appreciate any help.

Best,
Oliver

OS: Ubuntu 20.04.2 LTS (ubuntu:GNOME/ubuntu)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.
Build type: Release
Branch: unknown
Hash: e8566f22bbeb0b7204e3c45519d0963e8881100b
Python version: 3.8.5
Qt version: 5.12.8
Coin version: 4.0.0
OCC version: 7.5.1
Locale: German/Germany (de_DE)

Code: Select all

import sys
sys.path.append('/usr/lib/freecad-python3/lib/')
sys.path.append('/usr/share/freecad/Mod/Path/')
sys.path.append('/usr/share/freecad/Ext/')

import FreeCAD
import PathScripts.PathPost
from PathScripts.post import grbl_post as pp

# Open the document
doc = FreeCAD.openDocument('./Templates/Hole.FCStd')
FreeCAD.setActiveDocument("Hole")
FreeCAD.ActiveDocument=FreeCAD.getDocument("Hole")

# Print the current parameter
print (FreeCAD.ActiveDocument.Spreadsheet.B2, ": ", FreeCAD.ActiveDocument.Spreadsheet.C2)

# Set the new parameter
FreeCAD.ActiveDocument.Spreadsheet.set('holediameter', "35mm")

# Recompute
for obj in FreeCAD.ActiveDocument.Objects:
 obj.touch()
FreeCAD.ActiveDocument.recompute()

# Save for debugging
FreeCAD.ActiveDocument.saveAs('/tmp/test.FCStd')

# Post process all Operations
job = FreeCAD.ActiveDocument.getObject('Job') 
obj = job.Operations.Group
pp.export(obj, '/tmp/test.nc', '')
Attachments
Hole.FCStd
(25.83 KiB) Downloaded 18 times
spanner888
Posts: 328
Joined: Tue May 28, 2019 10:51 am

Re: Path Postprocessing without GUI

Post by spanner888 »

Scripts in this thread work nicely, but I have not tried from command line.
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path Postprocessing without GUI

Post by onekk »

Sadly Path Scripting "interface" is not complete, you have to do many workarounds to achieve things, so using it through command line (but FreeCAD has no command line, do you intend "Python Console" instead?) it somewhat difficult.

Jobs are rather difficult to cope with, as the "interface" is not intended yet to be used with scripting.

Almsot everything could be achieved, using two or three way, but this involve with writing some "helper code" that could not be "rewritten" on the fly on the Python Console.

I've been told that one of the 0.20 goal for Path development was to achieve a more complete scripting ability, but no progress, seem to be done recently.

My research are stalled, as with promised interface changes, most of them will became obsolete, so I'm waiting for some decision on this by developers of Path workbench.

As I've been told that I'm one of the few that need such things, maybe more "Feature request" would be speed things up.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
WayofWood
Posts: 62
Joined: Mon Nov 26, 2018 4:59 pm

Re: Path Postprocessing without GUI

Post by WayofWood »

onekk wrote: Sun Apr 18, 2021 1:03 pm Sadly Path Scripting "interface" is not complete, you have to do many workarounds to achieve things, so using it through command line (but FreeCAD has no command line, do you intend "Python Console" instead?) it somewhat difficult.

Jobs are rather difficult to cope with, as the "interface" is not intended yet to be used with scripting.
Thanks for the reply. This makes sense from what the file looked like after accessing the job via a script.

It is honestly not a very common use case but in woodworking it would be a very cool feature if the cnc could create a mortise and tenon joint by a few mouse clicks...

Best regards
Oliver
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Path Postprocessing without GUI

Post by Kunda1 »

What's stalling the Path development ATM ?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
onekk
Veteran
Posts: 6222
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Path Postprocessing without GUI

Post by onekk »

Kunda1 wrote: Sun Apr 18, 2021 9:24 pm What's stalling the Path development ATM ?
Main concern is that path scripting is not "taken in account", to do some decent job you have to make many workarounds.

Job are not "scriptable" in an esasy manner, it could be created, but the use of Spreadsheets, with many "properties" set as default make them a relatively difficult thing to manage.

When you are doing something with scripting, you are prepared to set your preferences maybe using default values, but "filling" boxes is left to your work.

When you create a Job, and want to use some default values, a Spreadsheet is created and you have to "delete" all his defaults, and reassign proper values.

Plus creating an op with more than one job will bring up the Gui asking on which job you want to place the operation. Ideally this could be done in two ways:

1) assign the job during op creation (but the interface is not here)
2) create the operation and assign a complete operation to a job, (this is not feasible as during operation creation it inherites something to the job spreadsheet and other data)

There where many way to do things, one is enough, but there is nothing, whichever way you choose GUI is not be brought in, if the operation is "malformed" put a exclamation mark and let the use to adjust thing and "recompute" . If you are scipting you have to be prepared to make choices and not let the program "trying" to guess what you want to do.

Many other little glitches, and thing in other places.

One for example "Tag Dress up ", there would be a manner to assign proper tag position, as like in my case, i don't want tags, to be in some places, so I have to calculate some "possible tags" and assign them as my tags when creating the "dress up", point calculation could be left to the use.

Communication with developer is quite easy at least with @sliptonic that is a very good guy and very helpful, but he is not the only developer so the question was left after 0.19 was "stable".

Said that the goal for a decent scriptability of FreeCAD Path module is left for 0.20 stable, or at least these are the goal of #sliptonic.

Maybe more Feature request will speed up things, (I'm was told many times that I'm one of the very few that is trying to scripting part), in effect, I know few people, one German, one French that have done some post about path scripting, many other use path but not with scripting.

Sadly one of the most "point of strength" of FreeCAD is the Scripting engine, or better the fact that is "powered by Python" at least for make things, and GUI things, so it is relatively easy to create WB and part using Scripting.

CNC world hobby CNC in particular if you are using Linux don't have a decent CAM (left apart LinuxCNC), there are few CAM that could work standalone with Linux, not much are Opensource, so FreeCAD Path was a good candidate to intercept many needs, as many CAD CAM are doing some "pay per use" politics that will force many little shops and hobbyst to search for an alternative.

As the only way is to have more user to ask to have "path fully scriptable" and hoping developer will fulfill request, the only way I see is encouraging users to make "Feature Request".

I have spent many hour to find workarounds, and sadly I have no "horse power" on my machine to develop directly alternatives, but I don't want to "reinvent the wheel". I want only to "make the wheel more round and faster".

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply