[Help] How to get WBs, Toolbars, Tools

Need help, or want to share a macro? Post here!
User avatar
Kunda1
Posts: 9209
Joined: Thu Jan 05, 2017 9:03 pm

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

Postby Kunda1 » Sat Apr 04, 2020 12:11 pm

wmayer wrote: git commit 8663e724f

Code: Select all

wb=Gui.activeWorkbench()
wb.getToolbarItems()
Thanks @wmayer :D
Alone you go faster. Together we go farther
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
HakanSeven12
Posts: 1065
Joined: Wed Feb 06, 2019 10:30 pm

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

Postby HakanSeven12 » Mon Apr 06, 2020 11:03 am

It works :)

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

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

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

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

Postby HakanSeven12 » Sun Nov 22, 2020 7:21 pm

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 200 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
Site Admin
Posts: 16852
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Mon Nov 23, 2020 2:55 pm

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
Posts: 1065
Joined: Wed Feb 06, 2019 10:30 pm

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

Postby HakanSeven12 » Mon Nov 23, 2020 3:14 pm

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
Site Admin
Posts: 16852
Joined: Thu Feb 19, 2009 10:32 am

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

Postby wmayer » Mon Nov 23, 2020 3:54 pm

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
Posts: 1065
Joined: Wed Feb 06, 2019 10:30 pm

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

Postby HakanSeven12 » Mon Nov 23, 2020 3:58 pm

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

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

Postby Kunda1 » Mon Nov 23, 2020 7:13 pm

Anybody game to document this?
Alone you go faster. Together we go farther
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
HakanSeven12
Posts: 1065
Joined: Wed Feb 06, 2019 10:30 pm

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

Postby HakanSeven12 » Tue Nov 24, 2020 6:09 am

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.