[Macro] Bit of help for super users :)

Need help, or want to share a macro? Post here!
openBrain
Posts: 3089
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Macro] Bit of help for super users :)

Post by openBrain » Fri Dec 27, 2019 10:37 pm

Kunda1 wrote:
Fri Dec 27, 2019 10:05 pm
What's the usecase for it?
Basically :
  • Property editor split : when you need an intensive access to properties (eg. to enter expressions), having it in a separated dock widget allows to use the whole height of the window, thus to display much more properties on the screen and get better access to it
  • Task tab split : as soon as you use functions that need to either select things in the tree or play with show/hide objects, you have to constantly switch between Task tab and Model tab (to get the tree view). Having both separated prevent this permanent switching
Hope this may explain a bit. :)
chrisb
Posts: 21407
Joined: Tue Mar 17, 2015 9:14 am

Re: [Macro] Bit of help for super users :)

Post by chrisb » Sat Dec 28, 2019 8:42 am

Power users seem to need very different tools. So it may be sensible to think about configurable buttons. E.g. I don't need several of the existing buttons, but I want to toggle the "EnableSelection" parameter from the preferences, which is probably useless for others.

My knowledge of FreeCAD-Python is very limited so I'm still struggling with the code, and it would be great if there was an easy to handle possibility to assign buttons to a few lines of code.
User avatar
Kunda1
Posts: 6440
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Macro] Bit of help for super users :)

Post by Kunda1 » Sat Dec 28, 2019 12:47 pm

openBrain wrote:
Fri Dec 27, 2019 10:37 pm
Basically :
  • Property editor split : when you need an intensive access to properties (eg. to enter expressions), having it in a separated dock widget allows to use the whole height of the window, thus to display much more properties on the screen and get better access to it
  • Task tab split : as soon as you use functions that need to either select things in the tree or play with show/hide objects, you have to constantly switch between Task tab and Model tab (to get the tree view). Having both separated prevent this permanent switching
Hope this may explain a bit. :)
Thank you, that was very helpful. It can also be copy/pasted and added to the documentation because it is very thorough. I see the usefulness of this for sure. It reminds me of the user that is doing their Ph.D. thesis(?) on Multi Body Systems and how many times they have to switch dialogs off and on screen as part of their workflow. It also remind me of the problem that @microelly2 has with pyflow node editor, in other words we're talking 'screen real-estate'
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
User avatar
Kunda1
Posts: 6440
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Macro] Bit of help for super users :)

Post by Kunda1 » Sat Dec 28, 2019 1:06 pm

chrisb wrote:
Sat Dec 28, 2019 8:42 am
My knowledge of FreeCAD-Python is very limited so I'm still struggling with the code, and it would be great if there was an easy to handle possibility to assign buttons to a few lines of code.
This would be a great topic for a tutorial + I remember someone making a feature request perhaps the Addon Manager or FreeCAD Macros repo of adding buttons for macros as an option when installing them (need to confirm this).

Edit: I can't find the feature request
Want to contribute back to FC? Checkout:
#lowhangingfruit | Use the Source, Luke. | How to Help FreeCAD | How to report FC bugs and features
chrisb
Posts: 21407
Joined: Tue Mar 17, 2015 9:14 am

Re: [Macro] Bit of help for super users :)

Post by chrisb » Sat Dec 28, 2019 2:39 pm

To make it clear: I didn't mean the general possibility to assign a macro to an icon. I meant openBrains SU tool, where I would like to assign my own stuff to one of the buttons. It's in fact only two lines (could be reduced to one):

Code: Select all

pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
pref.SetBool(EnableSelection, True)
and on toggle button:

Code: Select all

pref = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/View")
pref.SetBool(EnableSelection, False)
openBrain
Posts: 3089
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Macro] Bit of help for super users :)

Post by openBrain » Sat Dec 28, 2019 5:11 pm

chrisb wrote:
Sat Dec 28, 2019 2:39 pm
To make it clear: I didn't mean the general possibility to assign a macro to an icon. I meant openBrains SU tool, where I would like to assign my own stuff to one of the buttons. It's in fact only two lines (could be reduced to one:
This is clear. Let me do a bit of work on the macro and you should be able to tune things by yourself without deep Python knowledge.

Just notice that in the example you give, you can get a toggling mechanism with :

Code: Select all

pref = App.ParamGet("User parameter:BaseApp/Preferences/View")
pref.SetBool('EnableSelection',not pref.GetBool('EnableSelection', True))
chrisb
Posts: 21407
Joined: Tue Mar 17, 2015 9:14 am

Re: [Macro] Bit of help for super users :)

Post by chrisb » Sat Dec 28, 2019 5:31 pm

Thanks (in my case it probably needs a bit more to show the state of the button).
I could imagine something like an XML, or json file, which is read by SU where an entry has two or three values; ButtonText, FunctionName, (optional ToolText). I have no idea though, if Python has the possibility to execute a function if the name is given as string.
vocx
Posts: 2829
Joined: Thu Oct 18, 2018 9:18 pm

Re: [Macro] Bit of help for super users :)

Post by vocx » Sun Dec 29, 2019 2:03 am

chrisb wrote:
Sat Dec 28, 2019 5:31 pm
...I have no idea though, if Python has the possibility to execute a function if the name is given as string.
Basically all scripting languages can do this. In Python use the exec() function.

It is a bit dangerous because if you don't check your string, somebody could potentially inject harmful code. So make sure you can only execute a string that you want, and not arbitrary code.

Code: Select all

exec("print('inside string')")

exec("%s('inside string')" % "print")

a = "print"
exec("%s('inside string')" % a)
To support the documentation effort, and code development, your donation is appreciated: paypal.
openBrain
Posts: 3089
Joined: Fri Nov 09, 2018 5:38 pm

Re: [Macro] Bit of help for super users :)

Post by openBrain » Sun Dec 29, 2019 6:06 pm

chrisb wrote:
Sat Dec 28, 2019 5:31 pm
Thanks (in my case it probably needs a bit more to show the state of the button).
I could imagine something like an XML, or json file, which is read by SU where an entry has two or three values; ButtonText, FunctionName, (optional ToolText). I have no idea though, if Python has the possibility to execute a function if the name is given as string.
Hi chrisb, I'm currently working a bit on your request. :)
In your case it's pretty easy but I'd like to enlarge a bit around your need :
  • In your case, how do you imagine the UI ? The button is a "push" type and it switches value between True & False each time it's pressed (with a "tooltip" indicating the value) ? Or something like a "toggle" type that is pushed for True and released for False ?
  • If we go further, do you imagine cases where it would deal with other that boolean (eg. integers, floats, strings) ? In this case the button could round-switch between a set of values each time it's pressed.
  • Even dealing with integers with a slider (in the way the Visibility tool works) ? A use case would be eg. to live change pick radius ?
Obviously the more cases is handled, the more complex is the code. :) But I prefer to match the full need.

EDIT : actually there is a difficult case to handle. It's when the user goes to the Parameter Editor and manually changes the value there. the button will lose the sync. But I guess we can ignore this. ;)
chrisb
Posts: 21407
Joined: Tue Mar 17, 2015 9:14 am

Re: [Macro] Bit of help for super users :)

Post by chrisb » Sun Dec 29, 2019 6:28 pm

openBrain wrote:
Sun Dec 29, 2019 6:06 pm
In your case, how do you imagine the UI ? The button is a "push" type and it switches value between True & False each time it's pressed (with a "tooltip" indicating the value) ? Or something like a "toggle" type that is pushed for True and released for False ?
Thanks for working on this. I would like to see the state immediately like I do now. Tooltip help is nice, but not for quick use.
Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot] and 2 guests