[Solved] Get a window

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
xXxStYxXx
Posts: 27
Joined: Sat Sep 24, 2022 9:27 pm

[Solved] Get a window

Post by xXxStYxXx »

Hello there.
I'm trying to edit preferences with Python code. And wanted to know how to get the Preferences window, or actually any window of FreeCAD.

The Preferences window can be opened like this:

Code: Select all

Gui.runCommand('Std_DlgPreferences')
But this command only opens the window. I actually want to get the window, store it to a variable and edit preferences using the variable.
For example, store the window to a variable called "prefWindow", then by accessing the variable change tabs and modes (General, Display, Workbenches, etc.), set check boxes, fill input fields, etc.

Maybe it worths mentioning that I want to edit all preferences during FreeCAD startup, so I want to write a script that fully tune the preferences then run it during FreeCAD startup.

Image

Code: Select all

OS: Ubuntu 22.04.1 LTS (ubuntu:GNOME/ubuntu)
Word size of FreeCAD: 64-bit
Version: 0.21.31063 (Git)
Build type: Unknown
Branch: master
Hash: 7b2a6a3bf7c7cd409be25630d359a316f74fa9fd
Python 3.10.6, Qt 5.15.3, Coin 4.0.0, Vtk 9.1.0, OCC 7.5.1
Locale: English/United States (en_US)
Last edited by xXxStYxXx on Sat Dec 10, 2022 1:43 pm, edited 1 time in total.
User avatar
Roy_043
Veteran
Posts: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Re: Get a window

Post by Roy_043 »

There are functions to deal with parameters directly:

Code: Select all

param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
param.GetBool("alwaysSnap")
param.SetBool("alwaysSnap", False)
xXxStYxXx
Posts: 27
Joined: Sat Sep 24, 2022 9:27 pm

Re: Get a window

Post by xXxStYxXx »

Roy_043 wrote: Tue Nov 29, 2022 6:38 pm There functions to deal with parameters directly:

Code: Select all

param = App.ParamGet("User parameter:BaseApp/Preferences/Mod/Draft")
param.GetBool("alwaysSnap")
param.SetBool("alwaysSnap", False)
I see, thank you so much.
I was about to ask you where to find these crazy strings like "User parameter:BaseApp/Preferences/Mod/Draft" or "alwaysSnap", but I found them myself.

For future generations: these strings are User parameters and can be found in Tools menu -> Edit parameters
Image

On the left you have a tree view of folders and parameters. For example the path to the parameter I'm replying: BaseApp is in the top left corner, then comes Preferences, then Mod and finally Draft where I can see all parameters and their string representations, type and value. The path or command to the parameter can be represented like this: "User parameter:BaseApp/Preferences/Mod/Draft". And the parameter itself in my case is "alwaysSnap", Boolean, true.
Image

Please, correct me if I'm wrong
User avatar
Roy_043
Veteran
Posts: 8456
Joined: Thu Dec 27, 2018 12:28 pm

Re: Get a window

Post by Roy_043 »

xXxStYxXx
Posts: 27
Joined: Sat Sep 24, 2022 9:27 pm

Re: Get a window

Post by xXxStYxXx »

Roy_043 wrote: Tue Nov 29, 2022 8:53 pm Wiki: Std_DlgParameter
Or that, thanks anyway :D
Post Reply