Is it possible to use ParameterGrp from Python?

Need help, or want to share a macro? Post here!
User avatar
furti
Posts: 57
Joined: Mon Nov 27, 2017 5:27 pm

Is it possible to use ParameterGrp from Python?

Postby furti » Wed Sep 12, 2018 3:32 pm

Hi :)

Is it possible to use ParameterGrp from python to load a FreeCAD config File? I saw that there is a ParameterPy.cpp file (https://github.com/FreeCAD/FreeCAD/blob ... eterPy.cpp) that contains the parameter Group and a Import method. But i couldn't figure out how to use it via python.

I ask because I want to add the possibility to merge settings into existing presets for my macro https://github.com/furti/FreeCAD-PreferencesPresets

Thanks in advance :)

Best Regards
Daniel
User avatar
easyw-fc
Posts: 1926
Joined: Thu Jul 09, 2015 9:34 am

Re: Is it possible to use ParameterGrp from Python?

Postby easyw-fc » Fri Sep 14, 2018 10:20 pm

furti wrote:
Wed Sep 12, 2018 3:32 pm
Hi :)

Is it possible to use ParameterGrp from python to load a FreeCAD config File? I saw that there is a ParameterPy.cpp file (https://github.com/FreeCAD/FreeCAD/blob ... eterPy.cpp) that contains the parameter Group and a Import method. But i couldn't figure out how to use it via python.

I ask because I want to add the possibility to merge settings into existing presets for my macro https://github.com/furti/FreeCAD-PreferencesPresets

Thanks in advance :)

Best Regards
Daniel
are you looking for:

Code: Select all

pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
pg.GetString('constructiongroupname')
wmayer
Site Admin
Posts: 13090
Joined: Thu Feb 19, 2009 10:32 am

Re: Is it possible to use ParameterGrp from Python?

Postby wmayer » Sat Sep 15, 2018 9:34 am

Code: Select all

pg = FreeCAD.ParamGet("User parameter:BaseApp")
pg.Import(myparameterfile)
User avatar
furti
Posts: 57
Joined: Mon Nov 27, 2017 5:27 pm

Re: Is it possible to use ParameterGrp from Python?

Postby furti » Sat Sep 15, 2018 4:23 pm

easyw-fc wrote:
Fri Sep 14, 2018 10:20 pm
pg = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
wmayer wrote:
Sat Sep 15, 2018 9:34 am
pg = FreeCAD.ParamGet("User parameter:BaseApp")
Thank you for your answers. But this is not exactly what I am searching for. I want to load e.g. a user.cfg file that is stored in a different location than the default user.cfg file and compare it to the parameters of the running FreeCAD instance. Then i can compare this two groups and show the user a diff. The user selects the parameters to merge and i save the group back into the other user.cfg file.

As it seems to me, your examples use the parameter groups of the running FreeCAD instance and a "Import" will override the settings of FreeCAD.

But after trying this I realized that the "getContents" method does no list the ParameterGroups inside a ParameterGroup. So it is not possible to list all parameters inside a group without knowing the parameter names beforehand.

Do you think such functionality will likely be available via Python in the future?

Best Regards
Furti
wmayer
Site Admin
Posts: 13090
Joined: Thu Feb 19, 2009 10:32 am

Re: Is it possible to use ParameterGrp from Python?

Postby wmayer » Sat Sep 15, 2018 6:03 pm

Do you think such functionality will likely be available via Python in the future?
In C++ the class ParameterGrp has the methods GetGroups() and GetGroupName() so that we can expose a function to Python access this information.
User avatar
furti
Posts: 57
Joined: Mon Nov 27, 2017 5:27 pm

Re: Is it possible to use ParameterGrp from Python?

Postby furti » Sat Sep 15, 2018 6:29 pm

wmayer wrote:
Sat Sep 15, 2018 6:03 pm
In C++ the class ParameterGrp has the methods GetGroups() and GetGroupName()
That sounds great. :)
Do you think it is also possible to get access to the ParameterGrp constructor from python? As it seems it is not available in the Base module right now.

Thank you for your help. :)
wmayer
Site Admin
Posts: 13090
Joined: Thu Feb 19, 2009 10:32 am

Re: Is it possible to use ParameterGrp from Python?

Postby wmayer » Sat Sep 15, 2018 7:41 pm

Do you think it is also possible to get access to the ParameterGrp constructor from python?
What for?
User avatar
furti
Posts: 57
Joined: Mon Nov 27, 2017 5:27 pm

Re: Is it possible to use ParameterGrp from Python?

Postby furti » Sat Sep 15, 2018 8:35 pm

wmayer wrote:
Sat Sep 15, 2018 7:41 pm
What for?
Need a way to load different config files and compare them against each other for this macro i created https://forum.freecadweb.org/viewtopic.php?f=22&t=30795

Then the user can choose the settings to override and i can save the file back to the preset location without messing up the preferences of the current FreeCAD instance.
wmayer
Site Admin
Posts: 13090
Joined: Thu Feb 19, 2009 10:32 am

Re: Is it possible to use ParameterGrp from Python?

Postby wmayer » Sun Sep 16, 2018 5:40 pm

git commit 476a07ae2 exposes some more methods to Python.

Code: Select all

pg = FreeCAD.ParamGet("User parameter:BaseApp")
pg.GetGroups()
# returns ['Preferences', 'Macro', 'Workbench', 'MainWindow', 'History', 'Workbenches', 'LogLevels']
pg.GetGroup("Macro")
If you want to create a new group then simply write the name of the new group which will be created on-the-fly if it doesn't exist.

Code: Select all

pg.GetGroup("ThisCreatesANewGroup")