Param object editor macro

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
donjan
Posts: 22
Joined: Wed Jun 21, 2017 11:40 am

Param object editor macro

Postby donjan » Fri Jul 19, 2019 11:36 pm

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 258 times
a.jpg
a.jpg (52.61 KiB) Viewed 258 times

edit: current version 2019.08.16
Attachments
paramgui.FCMacro
(9.84 KiB) Downloaded 2 times
Last edited by donjan on Fri Aug 16, 2019 5:37 pm, edited 2 times in total.
donjan
Posts: 22
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Postby donjan » Fri Aug 09, 2019 7:56 pm

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

Re: Param object editor macro

Postby TheMarkster » Sat Aug 10, 2019 11:09 pm

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

Re: Param object editor macro

Postby donjan » Sun Aug 11, 2019 10:26 pm

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: 22
Joined: Wed Jun 21, 2017 11:40 am

Re: Param object editor macro

Postby donjan » Fri Aug 16, 2019 5:40 pm

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?