Reputation: 23
I am attempting to create an automation script/macro by going through the FreeCADGui and selecting the Button I want, like this:
def click_toolbar_button(button_name, toolbar_name):
mw = FreeCADGui.getMainWindow()
# workbench = FreeCADGui.activeWorkbench()
# print(workbench.__class__.__name__)
# Find the toolbar associated with the active workbench
for tb in mw.findChildren(QtWidgets.QToolBar):
# print("toolbar: ", tb.objectName())
if toolbar_name in tb.objectName():
toolbar = tb
break
else:
print("Toolbar not found for the active workbench.")
# Find the button by its name
for action in toolbar.actions():
if action.objectName() == button_name:
button = action
break
else:
print(f"Button '{button_name}' not found on the toolbar.")
return
# Trigger the button's click event
print("triggering button")
button.trigger()
print("finished click toolbar button")
click_toolbar_button("Path_Job", "Project Setup")
This works however upon completion a subwindow/QDialog appears and pauses my script not allowing for the remaining lines - of which are attempting to click ok in this subwindow - to run. Remaining code:
def find_and_click_ok_button():
print("Attempting findand click")
subwindows = FreeCADGui.getMainWindow().findChildren(QtWidgets.QDialog)
for subwindow in subwindows:
if "Project Setup" in subwindow.windowTitle():
ok_button = subwindow.findChild(QtWidgets.QPushButton, "okButton")
if ok_button:
ok_button.click()
break
find_and_click_ok_button()
I have tried searching this up but nobody seems to know what this is, or I'm using the wrong keywords. If anyone can expand my knowledge of the situation that would be great.
Upvotes: 1
Views: 168