Path Scripting documentation.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Be nice to others! Respect the FreeCAD code of conduct!
Path Scripting documentation.
Hello to All
I'm experimenting with path scripting, but I can't find how to initialize a proper Path job.
I've searched in the forum for discussion, but non is showing how to proper initialize a job.
I've put together some code, but it won't compile without errors.
Edit some working code is done see later on this thread
The work is intended as a test for the path creation in a more articulated project that create some shapes in a parametric way using only scripting and produce some gcode as output.
TIA and Regards
Carlo D.
PS: Happy new year 2021
I'm experimenting with path scripting, but I can't find how to initialize a proper Path job.
I've searched in the forum for discussion, but non is showing how to proper initialize a job.
I've put together some code, but it won't compile without errors.
Edit some working code is done see later on this thread
The work is intended as a test for the path creation in a more articulated project that create some shapes in a parametric way using only scripting and produce some gcode as output.
TIA and Regards
Carlo D.
PS: Happy new year 2021
Last edited by onekk on Tue Jan 05, 2021 9:38 am, edited 3 times in total.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Posts: 327
- Joined: Tue May 28, 2019 10:51 am
Re: Path Scripting.
There are several links to useful Path scripting in this post https://forum.freecadweb.org/viewtopic.php?f=15&t=51033
Re: Path Scripting.
Thanks, but None of the links is showing a proper workflow.
Some of the code I've put together are from the hints in that post.
But the documentation is referring to the old way of setting many things, like Tools data.
Plus many of the documentation are referring to the old way of defining things, like pockets and Jobs,
https://wiki.freecadweb.org/Path_scripting
And from the little code I've seen around there is some differences in the workflow.
My main problem is the creation of the Job itself.
As I've wrote in the first post, I was expecting to be able to create an empty job and then populate it with the proper
Tooltable and Operations, eventually defining a Stock and some other things.
But even this "relatively" simple task is not documented in any place, searching in the forum post for pathjob is returning nothing focused.
Regards
Carlo D.
Some of the code I've put together are from the hints in that post.
But the documentation is referring to the old way of setting many things, like Tools data.
Plus many of the documentation are referring to the old way of defining things, like pockets and Jobs,
https://wiki.freecadweb.org/Path_scripting
And from the little code I've seen around there is some differences in the workflow.
My main problem is the creation of the Job itself.
As I've wrote in the first post, I was expecting to be able to create an empty job and then populate it with the proper
Tooltable and Operations, eventually defining a Stock and some other things.
But even this "relatively" simple task is not documented in any place, searching in the forum post for pathjob is returning nothing focused.
Regards
Carlo D.
Last edited by onekk on Tue Jan 05, 2021 9:36 am, edited 1 time in total.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Path Scripting.
Ok some result achieved, put toghether some code lying around, I have to decompress the Mod directory of my AppImage and analyze sources with grep, to find out some working code that "compiile" without error, not too far from the code posted.
See later on this thread
Regards
Carlo D.
OS: Artix Linux (openbox)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23578 (Git) AppImage
Build type: Release
Branch: master
Hash: 50c3cbf00579dc4941ca743c25720d016b0453ce
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: Italian/Italy (it_IT)
See later on this thread
Regards
Carlo D.
OS: Artix Linux (openbox)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.23578 (Git) AppImage
Build type: Release
Branch: master
Hash: 50c3cbf00579dc4941ca743c25720d016b0453ce
Python version: 3.8.6
Qt version: 5.12.5
Coin version: 4.0.0
OCC version: 7.4.0
Locale: Italian/Italy (it_IT)
Last edited by onekk on Tue Jan 05, 2021 9:37 am, edited 1 time in total.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Path Scripting lack of doumentation.
Continuing the search, sadly no developer seem interested in this thread.
I would be able to achieve some simple operations, at least.
Some pocket, some profiles, with Tags (Holding Tab are called in other CAMS).
As the only viable free offline CAM for Linux seems to be FreeCAD, there are other paid software, but they are not actively developed at least for Linux.
Hope someone will step in and gave me some hints.
Thew documentation on site is not useful as it refer to many deprecated part of code.
Regards
Carlo D.
I would be able to achieve some simple operations, at least.
Some pocket, some profiles, with Tags (Holding Tab are called in other CAMS).
As the only viable free offline CAM for Linux seems to be FreeCAD, there are other paid software, but they are not actively developed at least for Linux.
Hope someone will step in and gave me some hints.
Thew documentation on site is not useful as it refer to many deprecated part of code.
Regards
Carlo D.
Last edited by onekk on Tue Jan 05, 2021 9:38 am, edited 1 time in total.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
- sliptonic
- Veteran
- Posts: 3459
- Joined: Tue Oct 25, 2011 10:46 pm
- Location: Columbia, Missouri
- Contact:
Re: Path Scripting lack of doumentation.
Not true. I'm following your progress closely. Scripting of Path is something that I want to be easier but I just haven't had much time to dig into it.
I will try to help if you'll try to help update the documentation as we go.
Hope someone will step in and gave me some hints.
...
Thew documentation on site is not useful as it refer to many deprecated part of code.
You might also try to connect with me on the gitter channel. Sometimes real-time chat is more productive.
Re: Path Scripting documentation.
Somemore progress, many thanks to sliptonic
Some little quirks to fix but at least path are shown and seems that gcode is useable, more to come
Regards
Carlo D.
Code: Select all
import FreeCAD
from FreeCAD import Base, Rotation, Vector
import Part
import Path
import Draft
from PathScripts import PathJob
from PathScripts import PathJobGui
from PathScripts import PathProfile
import PathScripts.PathDressupDogbone as PathDressupDogbone
import PathScripts.PathDressupHoldingTags as PathDressupHoldingTags
from PathScripts import PathGeom
from PathScripts import PathPostProcessor
from PathScripts import PathUtil
import numpy as np
DOC_NAME = "Pippo"
gcodePath = '/tmp/engrave.ngc'
DOC = FreeCAD.activeDocument()
def clear_doc():
"""
Clear the active document deleting all the objects
"""
for obj in DOC.Objects:
DOC.removeObject(obj.Name)
if DOC is None:
FreeCAD.newDocument(DOC_NAME)
FreeCAD.setActiveDocument(DOC_NAME)
DOC = FreeCAD.activeDocument()
VIEW = FreeCAD.Gui.ActiveDocument.ActiveView
else:
clear_doc()
VIEW = FreeCAD.Gui.ActiveDocument.ActiveView
def setview():
"""Rearrange View"""
DOC.recompute()
VIEW.viewAxometric()
VIEW.setAxisCross(True)
VIEW.fitAll()
EPS = 0.10
EPS_C = EPS * -0.5
VZOR = Vector(0,0,0)
RZO = Rotation(0, 0, 0)
box0 = DOC.addObject('Part::Box', 'Box')
box0.Width = 100
box0.Length = 100
box0.Height = 10
box1 = DOC.addObject('Part::Box', 'Box')
box1.Width = 50
box1.Length = 50
box1.Height = 20
box1.Placement = FreeCAD.Placement(FreeCAD.Vector(25,25,-5), FreeCAD.Rotation(FreeCAD.Vector(0,0,1), 0))
DOC.recompute()
cut = DOC.addObject('Part::Cut', 'Cut')
cut.Base = box0
cut.Tool = box1
DOC.recompute()
# get the upper face?
for i in range(11):
face = "Face%d" % (i+1)
f = cut.Shape.getElement(face)
if f.Surface.Axis == FreeCAD.Vector(0,0,1) and f.Orientation == 'Forward':
break
job = PathJob.Create('Job', [cut], None)
job.ViewObject.Proxy = PathJobGui.ViewProvider(job.ViewObject)
profile = PathProfile.Create('Profile')
profile.Base = (cut, face)
profile.setExpression('StepDown', None)
profile.StepDown = 3.00
profile.setExpression('StartDepth', None)
profile.StartDepth = 10
profile.setExpression('FinalDepth', None)
profile.FinalDepth = 0
profile.processHoles = True
profile.processPerimeter = True
profile.recompute()
DOC.recompute()
job.PostProcessorOutputFile = gcodePath
job.PostProcessor = 'grbl'
job.PostProcessorArgs = '--no-show-editor'
postlist = []
currTool = None
for obj in job.Operations.Group:
print( obj.Name)
tc = PathUtil.toolControllerForOp(obj)
if tc is not None:
if tc.ToolNumber != currTool:
postlist.append(tc)
currTool = tc.ToolNumber
postlist.append(obj)
post = PathPostProcessor.PostProcessor.load(job.PostProcessor)
gcode = post.export(postlist, gcodePath , job.PostProcessorArgs)
#ops = DOC.getObject("Operations")
#ops.Visibility = True
DOC.recompute()
print("--- done ---")
Some little quirks to fix but at least path are shown and seems that gcode is useable, more to come
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
Re: Path Scripting documentation.
More fun on scripting
This is a pethod to obtain information from a tool file saved on disk, a bit rough, but it works:
you pass simply a filename with the complete path, in my example the toolspath contain the proper path i.e "/home/user/.FreeCAD/Tools/Bit/"
To use it see in this snippet
The tooldata from the tool file is composed like :
so the tricks in T1[][] to extract the parameters to put into the proper field of the TC.Tool
Another trick, maybe know but not very documented is in this snippet
The trick is that prior of assign a value to the field if it is filled with an expression, you have to set this expression to 'None' and then assign values in the proper format Note the speed units.
There are some quirks as the toolshape chisen by default Endmill in this case is not perfect I haven't found yet a manner to change it say to ballnose.
The other doubt is the file property of the ToolController.Tool part.
But for now it seems quite useable to make some scripting.
Main concerns for now are the tool shape and to find a way to apply the Tags dressup to a profile.
At least for the scope of my project, a total way to automate MOP (Machine OPerations as they are called by other CAMs) starting from a parametric object created totally in a script.
More to come
Carlo D.
Code: Select all
T1 = PathToolBit.Declaration(toolspath + "tool1.fctb")
you pass simply a filename with the complete path, in my example the toolspath contain the proper path i.e "/home/user/.FreeCAD/Tools/Bit/"
To use it see in this snippet
Code: Select all
# modify some default ToolController data
tc0 = job.ToolController[0]
tc0.Label = "MyTC1"
tc0.setExpression('HorizRapid', None)
tc0.HorizRapid = "15 mm/s"
tc0.setExpression('VertRapid', None)
tc0.VertRapid = "2 mm/s"
tct1 = tc0.Tool
tct1.Label = T1['name']
#tct1.BitShape = shapepath + T1['shape']
tct1.CuttingEdgeHeight = T1['parameter']['CuttingEdgeHeight']
tct1.Diameter = T1['parameter']['Diameter']
tct1.Length = T1['parameter']['Length']
tct1.ShankDiameter = T1['parameter']['ShankDiameter']
tct1.recompute()
#tct1.ViewObject.Visibility = True
tct1.recompute()
tc0.recompute()
Code: Select all
{'version': 2, 'name': '3mm Endmill', 'shape': 'endmill.fcstd', 'parameter': {'CuttingEdgeHeight': '17,00 mm', 'Diameter': '3,00 mm', 'Length': '50,00 mm', 'ShankDiameter': '3,17 mm'}, 'attribute': {}}
Another trick, maybe know but not very documented is in this snippet
Code: Select all
tc0.setExpression('HorizRapid', None)
tc0.HorizRapid = "15 mm/s"
tc0.setExpression('VertRapid', None)
tc0.VertRapid = "2 mm/s"
There are some quirks as the toolshape chisen by default Endmill in this case is not perfect I haven't found yet a manner to change it say to ballnose.
The other doubt is the file property of the ToolController.Tool part.
But for now it seems quite useable to make some scripting.
Main concerns for now are the tool shape and to find a way to apply the Tags dressup to a profile.
At least for the scope of my project, a total way to automate MOP (Machine OPerations as they are called by other CAMs) starting from a parametric object created totally in a script.
More to come
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/
-
- Posts: 327
- Joined: Tue May 28, 2019 10:51 am
Re: Path Scripting documentation.
Sorry no progress since then, I'm busy with some other project.
Some work on sources was blocked due to the release of 0.19 so you have to wait some more, to have some news on this arguments.
Regards
Carlo D.
Some work on sources was blocked due to the release of 0.19 so you have to wait some more, to have some news on this arguments.
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/
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.
Blog: https://okkmkblog.wordpress.com/