Toggling a checkbox with a macro?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
kenwoodfox
Posts: 1
Joined: Sat Dec 04, 2021 5:50 pm

Toggling a checkbox with a macro?

Post by kenwoodfox »

Hello FreeCAD fourms! I came here from the irc channel on libre.

I just got this nifty SpacePilot pro and it has been working awesome! but there are a few things missing, i noticed that i cant use the translation lock, rotation lock and dominant mode buttons in freecad, freecad has checkboxes for these settings, but in the tools > customize > spaceball buttons you cant select checkboxes as a thing to tie a spaceball button to.

Anyway, you *can* select macros! so, my plan is to find a way to write a macro that can toggle that specific checkbox on and off! I looked through the example code posted on the fourm and on irc and i still feel lost, links to documentation would be awesome! Thank you so much!
User avatar
onekk
Veteran
Posts: 6144
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Toggling a checkbox with a macro?

Post by onekk »

Not clear what you want.

Do You want to write a macro that select a checkbox, or to toggle some preferences?

They are different things, many settings could be simply toggled using proper commands in Python (that could be put in a Macro, that is simply a Python script, with a different extension).

Better to modify the title of this thread to something like that refer to the dialog you are trying to modify, toggling a checkbox is simply to refer to the checkbox and setting it to True or False.

The point is how to obtain a Qt reference for this checkbox, and sometimes it is not exposed as a child of the MainWindow, directly, so you have to mimick "Gui actions" that is not a "robust way" to do things.

Alternatively if they are exposed as a "parameter", you could set the proper parameter, using this syntax:

Code: Select all

param_grp=FreeCAD.ParamGet("User parameter:BaseApp/Preferences/....")
param_grp.SetString("parameter_name", "Value")
FreeCAD.saveParameter
"User parameter:BaseApp/Preferences/.... will be the path to the parameter

while:

parameter_name are the name of the parameters (usually as written in the dialog)

Value is the desired value.

If you issue Saveparameters modifications are written in the preferences, and became persistent, if not they are used in this session only.

Hope it helps.

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/
chrisb
Veteran
Posts: 53922
Joined: Tue Mar 17, 2015 9:14 am

Re: Toggling a checkbox with a macro?

Post by chrisb »

No answer to your question, but I think the far better way to solve this, is to fix the root of the problem, i.e. the mouse buttons. See here for a proposal: https://forum.freecadweb.org/viewtopic. ... 65#p517486
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply