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', '')