[Solved] Closing Gui's ActiveView using Python console

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
jodark5
Posts: 15
Joined: Thu Apr 21, 2022 8:14 pm

[Solved] Closing Gui's ActiveView using Python console

Post by jodark5 »

Code: Select all

OS: Windows 10 (10.0)
Word size of FreeCAD: 64-bit
Version: 0.20.28929 (Git)
Build type: Release
Branch: master
Hash: 9251480ddb
Python 3.8.13, Qt 5.12.9, Coin 4.0.0, OCC 7.5.3
Locale: English/Canada (en_CA)
Installed mods: 
  * parts_library
When a Page object created with TechDraw Workbench is the active tab in the GUI and,
Gui.ActiveDocument.ActiveView.getPage().Visibility=False is entered in the python console, the Page closes and the next tab to the left is set as the ActiveView.
When a Sheet object created with Spreadsheet Workbench is the active tab in the GUI and,
Gui.ActiveDocument.ActiveView.getSheet().Visibility=False is entered in the python console, the tab and view remain active, but if one tests for the spreadsheets visibility by entering: Gui.ActiveDocument.ActiveView.getSheet().Visibility, the python console returns False. Is getSheet(), in the pop up helper menu not for this purpose?
Last edited by jodark5 on Tue Mar 07, 2023 4:02 pm, edited 1 time in total.
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: Closing Gui's ActiveView using Python console

Post by Kunda1 »

Moved to Python scripting subforum
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
openBrain
Veteran
Posts: 9034
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Closing Gui's ActiveView using Python console

Post by openBrain »

My thinking is that TechDraw and SpreadSheet deals differently with the Visibility attribute.
To close the active tab, the sure way is

Code: Select all

FreeCADGui.getMainWindow().centralWidget().activeSubWindow().close()
jodark5
Posts: 15
Joined: Thu Apr 21, 2022 8:14 pm

Re: Closing Gui's ActiveView using Python console

Post by jodark5 »

Code: Select all

FreeCADGui.getMainWindow().centralWidget().activeSubWindow().close()
Workes perfectly! I can add a Try / if statement to ensure which active window type gets closed. Thanks
Post Reply