Param object editor macro

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Param object editor macro

Post by donjan »

For a while now I've been using App::FeaturePython objects filled with values to parametrise sketches, pads, etc. conveniently from the outliner.
I want to share the corresponding GUI macro as I find it quite useful and it has reached some stage of maturity.
Comments welcome.

Usage: run the macro, set a parameter holder (e.g. the shown default name), create entries and use them in any formula editor.

Illustrations:
b.jpg
b.jpg (55.01 KiB) Viewed 1753 times
a.jpg
a.jpg (52.61 KiB) Viewed 1753 times

edit: current version 2019.08.20
Attachments
paramgui.FCMacro
(10.2 KiB) Downloaded 40 times
Last edited by donjan on Tue Aug 20, 2019 12:17 am, edited 3 times in total.
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Post by donjan »

Added a tooltip (also text when deleting) showing labels of where the property is used:
usedin.jpg
usedin.jpg (69.73 KiB) Viewed 1666 times
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Param object editor macro

Post by TheMarkster »

This is similar to DynamicData workbench, but done as a macro.
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Post by donjan »

Had I been aware of the DynamicData workbench a few months ago, I probably would not have written this macro.
Didn't find it because I never expected anyone to want to put this kind of functionality in a workbench.

It's definitely a useful plugin, but I find its UX is rather convoluted due to the multiple dialog click-throughs, name prefix cluttering and having to switch workbenches and hunt for buttons.
In my taste it's too "involved" for what is conceptually a simple task: stashing and fiddling with values. So I'll continue using and developing my macro.

Ideally, the ability to add/remove properties in App::FeaturePython (or even general) objects via right-click context menu should go into FreeCAD proper. This would obliviate the need for 90% of both plugins. I might attempt a hack to smarten up instances of App::FeaturePython, if I get more acquainted with manipulating the main window Qt elements (and have the time to spare). I guess this would require more FreeCAD plugin writing experience (or storing code in the save file *shudder*).
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Post by donjan »

A few updates:
- hidden variable differentiating it from other App::FeaturePython objects. This enables a nicer user interface via dropdown selection.
- "used in" lookup now properly respects word boundaries in expressions.

The current script creates slightly different objects and won't recognise the previous parameter holders. Those few who downloaded the previous versions can update by pasting this into the FreeCAD console with the correct param name inserted:

Code: Select all

App.ActiveDocument.PARAMNAME.addProperty('App::PropertyBool', 'param_holder_marker', '', '', 4)

I'm also playing around with live updates of the window, whenever parameter variables are changed in the outliner. It works by using code roughly equivalent to:

Code: Select all

pwin = ParamWindow()
param = App::FeaturePython()
param.Proxy = pwin
Then I can use the onChanged() method of my ParamWindow class to update the display. The problem is that this can't be serialised into the save file any more, because the macro code is session-only (as it should be). Moreover, if I try to save (or let autosave trigger), the save file becomes corrupt and can't be opened any more.
Current implementation is in the macro, but commented out.
Any ideas on how to get nice window-updates going?
Last edited by donjan on Tue Aug 20, 2019 12:19 am, edited 1 time in total.
donjan
Posts: 33
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Post by donjan »

Added live updating with a global addDocumentObserver(), then filtering for my object. Seems a bit overkill, but does the job.
selector_ui.jpg
selector_ui.jpg (65.96 KiB) Viewed 1476 times
Post Reply