Proposed GUI scripting support and other improvements - PR #4797

Here's the place for discussion related to CAM/CNC and the development of the Path module.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Proposed GUI scripting support and other improvements - PR #4797

Post by Russ4262 »

Evening,
This thread is purposed for discussion of PR #4797, [Path] Proposed GUI scripting support and other improvements. The focus of the PR was to add a new Tile Job Utility to the Path workbench, as well as other scripting improvements. Now (24 May 2021) the focus is only on the scripting support and other improvements.

Details from the PR description:
This PR makes some useful changes to the existing operations to ease scripting with GUI support for the Path WB. This improvement is done by relocating the creation of the `PathOpGui.CommandResources` object from inside the `PathOpGui.SetupOperation()` function to each GUI operation module, and passing this resource object to the `PathOpGui.SetupOperation()` function in place of the original argument that were used to create the same resource object. With this relocation, the ability to disable the initial Task Panel GUI interaction is added. This means users can script with GUI/view-provider support without having to interact with the Task Panel for new operations or jobs. The good news is that the normal/existing ability to edit operations and jobs with the Task Panel is still available once the new operation or job is created.

This PR adds the ability to pass the parent job for a new operation as an optional argument in the Create() function within each operation module. This allows the new operation to be pre-assigned to the provided parent job instead of needing to ask the user during GUI sessions.

This PR refactors the `PathDressupBoundary` module only by isolating the boundary dressup algorithm into an independent class so it is accessible without the requirement of creating a new dressup object.

This PR contains a fix for failed toolbit lookups from fixed-path toolbits used in shared files, that allows Path to locate the equivalent bit on the local machine. There is bug 4647 in the tracker system that this might affect in a positive way. I have not investigated whether the fix in this PR has a positive affect on that particular bug.

This PR also adds an improvement to the Job Simulator usage. It simply adds an auto-loading action of a Job in the simulator if the user has one selected, otherwise the simulator feature is untouched. This improvement is really just an ease-of-use improvement. If the user has a job selected prior to running the job simulator, then that job will be auto-loaded in the simulator.

EDIT 24 May 2021: The Tile Job Utility portion of the PR was removed per request, leaving scripting support and improvements. Title of this thread was changed accordingly.

Russell
Last edited by Russ4262 on Mon May 24, 2021 11:58 pm, edited 3 times in total.
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Proposed Tile Job Utility w/ scripting improvements - PR #4797

Post by Russ4262 »

onekk wrote: Tue May 18, 2021 3:58 pm One of the main problem with actual implementation of Operations is that they refer internally to some properties of the original job using expressions.

The problem I have tried to script some Path operation, but creating multiple jobs is not possible without bringing the Gui up and ruining the scripting advantage.
...
Afternoon sir.
I quoted your recent post in another thread, here in this one because the PR discussed in the thread fixes some of the issues you are experiencing. I am quite content with the vast majority of "actual implementation of Operations," but also ran into a scripting snag recently with the development of the Tile Job Utility presented in the PR under discussion in this thread.

Some simple changes included in this PR will allow for users to script creation of operations and jobs with GUI/view-provider support without the initial GUI task panel interaction, while maintaining the ability to later edit them in the task panel as usual once created. If this PR is merged, I will gladly post an example of how to use the changes in this PR to create new operations and jobs without the initial GUI task panel interaction - with this PR, it will be as simple as setting a `useGui` boolean to False, and setting the parent job attribute for the CommandResources object before creating the operation with GUI support. Or, passing the parent job as an argument to the `Create()` function found in each non-gui operation module to pre-assign a new operation to the provided job argument if working in a non-gui environment.

Thank you for your comments. They urge me to revisit the current PR and macro versions of this feature to perhaps streamline the process a bit more and ensure it behaves as I am explaining it and expect it to do.

The PR is still in draft form at this time, to allow for discussion and changes as needed.

Good day, sir.
Russell
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Proposed Tile Job Utility w/ scripting improvements - PR #4797

Post by onekk »

Mornig to you (at least in my timezone).

Non need to be so formal.

Many thanks for the improvements, I have to check them as soon as they are implementend in an AppImage.

Sadly at least until I could afford a more powerful machine,(I'm stuck with an old i3-2100 machine) I can't help with developing or suggest some code change with real code.

At a first glance they seems to avoid most of the problems, with the Gui popping up during script running.

The PR is almost big so I have to read all the code, so better not to speak on anything.

One thing that during script is "entering in the play" and could make complicated to set Jobs, is the Spreadsheet thing.

As a simple example:

Code: Select all

    job.SetupSheet.Label = s_name
    job.SetupSheet.HorizRapid = '{} mm/s'.format(str(ssdata[0]))
    job.SetupSheet.VertRapid = '{} mm/s'.format(str(ssdata[1]))
    job.SetupSheet.setExpression('StartDepthExpression', u'{}'.format(ssdata[4]))
    job.SetupSheet.setExpression('SafeHeightExpression', u'{}'.format(10))
    job.SetupSheet.setExpression('ClearanceHeightExpression', u'{}'.format(17))

There is room for a switch that mantain the SetupSheet, but permit to set directly the Operation property, a sort of "use_SS = False" somewhere, maybe with a checkbox in the Gui?

Some thoughs, only to talk, not a "feature request" nor a criticize, as I don't want to bother in any ways other than could make CAM jobs with scripting.

Maybe some hints on future feature, or "different ways" to implement things, that maybe will come handy for someone.

As I'm using another CAM, in this CAM is possible to select with the Gui some operations, even very different, and to modify them in a bunch, "obviously the Gui will show as editable only the "common fields" of all operations, like:
  • - horizrapid
    - vertrapid
    . start_depth
    - end_depth
    - safe_height
    - XYfeed and Zfeed rates
    - tool number
    - finishing and roughing
    ...

Plus each field has a flag that permit to select:
  • - use the "default" settings, this default is taken from the a "default setting list" that in this CAM is called "default style"
    - use the "Job" - "default setting", in this CAM you could have some levels of "CAM styles" one is at "Part level" that resemble a "Job", one at "MOP level", that is somewhat a "lower layer" that group some operation to make a job done.
    - use the "operation setting" in other word use the settings I put in the field

This permits to as example to:
  • - make a "Part" that visually and "pratically" separate operations to make a "part", permitting to produce, as example a gcode file and maybe a different "starting point" in term of "WCS coordinate" from other Parts.
    - group operations, like a "roughing pass" and a "finishing pass" with different settings maybe in order to feed and speeds but also with Stepover or Stepdown.
    - manage some operations assigning a "CAM Style" in other word I set some different "CAM Styles" one for "Roughing operations" and another for "finishing passes" and then apply them to all the related operation even in different Parts.

Many thanks for the PR, and hoping not to have bothered you.

Best 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/
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Proposed Tile Job Utility w/ scripting improvements - PR #4797

Post by Russ4262 »

Afternoon,
This PR has been altered today. The PR is now dedicated only to the improvements and fixes contained therein. I plan to get another PR in place with the new Tile Job Utility if these scripting improvements are approved and merged, since the utility depends upon some of the improvements presented in this PR.

Thanks to all those who have expressed an interest in the Tile Job Utility and to the many that have downloaded it in macro form in the related source thread here in the forum.

I will at this point change the title of this thread to reflect the new purpose and title of the PR, "[Path] GUI scripting support and other improvements."

Thanks,
Russell
eyalm
Posts: 11
Joined: Mon Dec 06, 2021 5:06 pm

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by eyalm »

Hi,

I'm trying to figure out how to script op creation with gui enabled afterwards.
Is there anywhere a place with an example of how this can be done using this PR ?

Thanks !
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by Russ4262 »

eyalm wrote: Tue Dec 07, 2021 11:26 am Hi,

I'm trying to figure out how to script op creation with gui enabled afterwards.
Is there anywhere a place with an example of how this can be done using this PR ?

Thanks !
Evening.
I stripped out the scripting changes before that PR was merged. However, doing what you want is currently doable with a little more coding effort than would be had that PR not been reduced.

Time is very limited and I do not have an example handy. Sorry. If I get a free moment I might try to put an example script together to share.

Russell
eyalm
Posts: 11
Joined: Mon Dec 06, 2021 5:06 pm

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by eyalm »

Thank you Russal, that woul be really valuable info !
eyalm
Posts: 11
Joined: Mon Dec 06, 2021 5:06 pm

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by eyalm »

Thank you Russal, that woul be really valuable info !
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by onekk »

eyalm wrote: Tue Dec 07, 2021 11:26 am Hi,

I'm trying to figure out how to script op creation with gui enabled afterwards.
Is there anywhere a place with an example of how this can be done using this PR ?

Thanks !
Maybe you will find some hints on this thread:

https://forum.freecadweb.org/viewtopic. ... 22#p464122

Not too polished as it is an example, of what could be done now.

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/
Russ4262
Posts: 941
Joined: Sat Jun 30, 2018 3:22 pm
Location: Oklahoma
Contact:

Re: Proposed GUI scripting support and other improvements - PR #4797

Post by Russ4262 »

Evening.
Attached is one example method to script Job and Profile object creation that includes full GUI support but bypasses the initial GUI interactions. Other ops could be handled in a similar fashion to the Profile op example provided in this script. This script attempts to be compatible with FreeCAD >= 0.19, but it might work with 0.18 - though, I have no 0.18 version available for testing at the moment.

I have made no attempt to script tool management.

Cheers,
Russell
Attachments
_Path_scripting_with_gui_support.FCMacro
Path scripting with GUI support 1.0
(4.71 KiB) Downloaded 40 times
Post Reply