Afternoon,
Attached is a module to aid in Job creation and adding tool controllers. It is based on current, restructured code for the Path workbench. No testing has been conducted with the script and pre-restructuring versions of FreeCAD.
Simply place the attached module in your Macros folder to make it accessible to FreeCAD. The module contains four primary public functions:
- add_job(models=[], templateFile=None, useGui=False): Add a new job to current document.
- add_toolcontroller_by_filename(job, name): Adds a new tool controller based on the name argument to the target job object provided. Get a list of available tool filenames using included 'available_tool_filenames()'.
- add_toolcontroller_by_number(job, number): Adds a new tool controller referenced by the number argument to the target job object provided. The number argument is available via the included 'available_tool_filenames()'. If duplicate tool numbers exist across library files, the first instance of the tool number will be used. In this case, I recommend the filename function be used in order to target a specific tool that may exist in multiple library files.
- available_tool_filenames(): Prints a list of available tools and associated tool number as referenced in tool libraries identified in FreeCAD preferences. **I do not declare that this function will find all tool library files on your computer. The function is based on existing libary search code in the Path workbench.
Usage to identify available tools:
In the python console:
Code: Select all
>>> import JobUtils
>>> JobUtils.available_tool_filenames()
Available tool files:
1 :: 5mm_Endmill
2 :: 5mm_Drill
3 :: 6mm_Ball_End
4 :: 6mm_Bullnose
5 :: 60degree_Vbit
6 :: 45degree_chamfer
7 :: slittingsaw
8 :: probe
9 :: 5mm-thread-cutter
10 :: dovetail_635mm
11 :: Endmill_3mm
['5mm_Endmill', '5mm_Drill', '6mm_Ball_End', '6mm_Bullnose', '60degree_Vbit', '45degree_chamfer', 'slittingsaw', 'probe', '5mm-thread-cutter', 'dovetail_635mm', 'Endmill_3mm']
>>>
Usage to add a Job:
In the python console:
Code: Select all
>>> import JobUtils
# In this example, the name of the model base is provided as 'Body'.
# An actual pointer to the model base object is also permitted in place of the model name.
# The leading 'job = ' is optional to capture a pointer to the new Job object created.
>>> job = JobUtils.add_job(models=['Body'])
Usage to add a tool controller to an existing Job object:
In the python console:
Code: Select all
>>> import JobUtils
# First, get a pointer to the target Job object.
>>> job = FreeCAD.ActiveDocument.getObject('Job')
# Next, add a tool controller by filename
# The tool filename is taken from the list provided from the 'available_tool_filenames()' function above
# The leading 'tc1 = ' is optional to capture a pointer to the new tool controller object created.
>>> tc1 = JobUtils.add_toolcontroller_by_filename(job, 'slittingsaw')
# Or, add a tool controller by tool number
# The tool number is taken from the list provided from the 'available_tool_filenames()' function above
# This example uses number '5 :: 60degree_Vbit' seen above
# The leading 'tc2 = ' is optional to capture a pointer to the new tool controller object created.
>>> tc2 = JobUtils.add_toolcontroller_by_number(job, 5)
EDIT 2023-09-10: Added newer Version 2023-09-10 a few posts below.
EDIT 2024-02-25: Upgraded version 2024-02-25 available further in this thread at Re: Scripting Path workbench. Removed original version here, 2023-04-16, downloaded 57 times.
Cheers,
Russell
Code: Select all
OS: Windows 10 Version 2009
Word size of FreeCAD: 64-bit
Version: 0.21.0.32821 (Git)
Build type: Release
Branch: master
Hash: eaf9d43f37238c33dd1c47b859a6fdf5b7f629fc
Python 3.10.10, Qt 5.15.8, Coin 4.0.0, Vtk 9.1.0, OCC 7.6.3
Locale: English/United States (en_US)
Installed mods:
* FC_SU
* freecad.gears 1.0.0
* PathExp
* Z_MacroStartup