[Help] How to get WBs, Toolbars, Tools

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by Kunda1 »

wmayer wrote: git commit 8663e724f

Code: Select all

wb=Gui.activeWorkbench()
wb.getToolbarItems()
Thanks @wmayer :D
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by HakanSeven12 »

It works :)

https://forum.freecadweb.org/viewtopic. ... 37#p384479

ModernUI.png
ModernUI.png (115.02 KiB) Viewed 875 times

Test3.gif
Test3.gif (343.61 KiB) Viewed 872 times
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by HakanSeven12 »

wmayer wrote: Sat Apr 04, 2020 9:49 am git commit 8663e724f

Code: Select all

wb=Gui.activeWorkbench()
wb.getToolbarItems()
Hi. I can get every command by using this code. But some commands are command groups. How can I get the commnds of command group?
For example I want to get this commands.
command group.png
command group.png (11.69 KiB) Viewed 791 times

Code: Select all

workbenches = Gui.listWorkbenches()

for wb_name in workbenches:
    Gui.activateWorkbench(wb_name)
    wb = Gui.getWorkbench(wb_name)
    items = wb.getToolbarItems()
    for i in items:
        #if i in pass_list: pass
        tb_name = i
        toolbar = items[i]
        for cmd in toolbar:
            command = Gui.Command.get(cmd)
            print(command)
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [Help] How to get WBs, Toolbars, Tools

Post by wmayer »

HakanSeven12 wrote: Sun Nov 22, 2020 7:21 pm Hi. I can get every command by using this code. But some commands are command groups. How can I get the commnds of command group?
For example I want to get this commands.
command group.png
I see. This is currently not possible. What we need is a way to check if a QAction has a QMenu and if yes also list its items.
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by HakanSeven12 »

When I created Modern UI, I accessed to qpushbuttons in toolbars. But İt's just a work around. So I don't like this method. If there is another way, it would be good for me.
wmayer
Founder
Posts: 20245
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: [Help] How to get WBs, Toolbars, Tools

Post by wmayer »

git commit b3200a8a9 implements a way to get the QAction of a Command. This function always returns a list which can
  • be empty if the command is not used yet in a workbench
  • have a single element which is the case for the majority of commands
  • have several elements for an action group

Code: Select all

cmd = Gui.Command.get("Sketcher_CompCreateRegularPolygon")
cmd.getAction()

Code: Select all

cmd = Gui.Command.get("Sketcher_CreatePoint")
cmd.getAction()
From a QAction you should get all the additional information you need. See https://doc.qt.io/qt-5/qaction.html
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by HakanSeven12 »

That was realy quick :) thanks
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by Kunda1 »

Anybody game to document this?
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
HakanSeven12
Veteran
Posts: 1481
Joined: Wed Feb 06, 2019 10:30 pm

Re: [Help] How to get WBs, Toolbars, Tools

Post by HakanSeven12 »

Kunda1 wrote: Mon Nov 23, 2020 7:13 pm Anybody game to document this?
I think there must be an UI api for python which UI developers can reach, edit or disable UI objects. Then we can talk about a documentation. Otherwise there is just some code that can reach wbs and their commands.
Post Reply