Macro Visibility Manager: Difference between revisions
TheMarkster (talk | contribs) (→Script) |
(MacroCode) |
||
(22 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
<languages/> |
|||
<translate> |
|||
<!--T:1--> |
|||
{{Macro |
{{Macro |
||
|Name=Visibility_Manager |
|Name=Visibility_Manager |
||
|Icon=Macro_Visibility_Manager.png |
|Icon=Macro_Visibility_Manager.png |
||
|Description=Use this to manage the visibility of document objects.<br/>There are 2 modes of operation: Show All and Show Types.<br/>In Show Types mode (the default) you only see a list of the types of objects, e.g. Body, Sketch, Pad, Extrude.<br/>Toggling one of the types off/on will set the visibility of all document |
|||
|Description=Manage visibility of document objects by type or individiually. |
|||
objects of that type in the active document.<br/>In Show All mode (Press Shift key while executing the macro) you see a different checkbox for each and every document object, sorted alphabetically.<br/>You can toggle each object's visibility individually. |
|||
|Author=TheMarkster |
|Author=TheMarkster |
||
|Version=1. |
|Version=1.06 |
||
|Date= |
|Date=2020-06-18 |
||
|FCVersion=All |
|FCVersion=All |
||
|Download=[https://www.freecadweb.org/wiki/images/c/c8/Macro_Visibility_Manager.png ToolBar Icon] |
|Download=[https://www.freecadweb.org/wiki/images/c/c8/Macro_Visibility_Manager.png ToolBar Icon] |
||
}} |
}} |
||
⚫ | |||
<!--T:3--> |
|||
⚫ | |||
Use this macro to manage visibility of document objects either by type or individually. |
Use this macro to manage visibility of document objects either by type or individually. |
||
⚫ | |||
<!--T:5--> |
|||
⚫ | |||
ToolBar icon |
|||
</translate> |
|||
[[Image:Macro_Visibility_Manager.png]] |
|||
'''Macro_Visibility_Manager.FCMacro''' |
'''Macro_Visibility_Manager.FCMacro''' |
||
{{ |
{{MacroCode|code= |
||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||
""" |
""" |
||
Line 72: | Line 77: | ||
__author__ = "TheMarkster" |
__author__ = "TheMarkster" |
||
__url__ = "" |
__url__ = "" |
||
__Wiki__ = "https://www.freecadweb.org/wiki/Macro_Visibility_Manager" |
|||
__Wiki__ = "" |
|||
__date__ = " |
__date__ = "2020.06.18" |
||
__version__ = 1. |
__version__ = 1.06 |
||
import FreeCAD |
import FreeCAD |
||
Line 85: | Line 90: | ||
self.types={} #dict of types |
self.types={} #dict of types |
||
self.showAll = bShowAll |
self.showAll = bShowAll |
||
self.reload = False |
|||
self.infoLabel = QtGui.QLabel() |
|||
self.infoLabel.mousePressEvent = self.label_clicked |
|||
if self.showAll: |
if self.showAll: |
||
infoLabel.setText("Show All mode") |
self.infoLabel.setText("Show All mode") |
||
else: |
else: |
||
infoLabel.setText("Show Type mode |
self.infoLabel.setText("Show by Type mode") |
||
checkboxLayout = QtGui.QVBoxLayout() |
checkboxLayout = QtGui.QVBoxLayout() |
||
self.checkboxes = [] |
self.checkboxes = [] |
||
Line 101: | Line 108: | ||
scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) |
scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) |
||
scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) |
scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) |
||
scroll.setWidgetResizable( |
scroll.setWidgetResizable(True) |
||
scroll.setWidget(widget) |
scroll.setWidget(widget) |
||
vLayout = QtGui.QVBoxLayout() |
vLayout = QtGui.QVBoxLayout() |
||
vLayout.addWidget(scroll) |
vLayout.addWidget(scroll) |
||
buttons = QtGui.QDialogButtonBox( |
#buttons = QtGui.QDialogButtonBox( |
||
QtGui.QDialogButtonBox.Ok.__or__(QtGui.QDialogButtonBox.Cancel), |
# QtGui.QDialogButtonBox.Ok.__or__(QtGui.QDialogButtonBox.Cancel), |
||
QtCore.Qt.Horizontal, self) |
# QtCore.Qt.Horizontal, self) |
||
buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok, QtCore.Qt.Horizontal,self) |
|||
buttons.addButton(QtGui.QDialogButtonBox.Cancel) |
|||
mode_button = buttons.addButton('Switch Mode', QtGui.QDialogButtonBox.ActionRole) |
|||
mode_button.clicked.connect(self.label_clicked) |
|||
buttons.accepted.connect(self.accept) |
buttons.accepted.connect(self.accept) |
||
buttons.rejected.connect(self.reject) |
buttons.rejected.connect(self.reject) |
||
buttons.setCenterButtons(True) |
buttons.setCenterButtons(True) |
||
layout = QtGui.QVBoxLayout() |
layout = QtGui.QVBoxLayout() |
||
layout.addWidget(infoLabel) |
layout.addWidget(self.infoLabel) |
||
⚫ | |||
layout.addLayout(vLayout) |
layout.addLayout(vLayout) |
||
layout.addWidget(buttons) |
layout.addWidget(buttons) |
||
self.setLayout(layout) |
self.setLayout(layout) |
||
def label_clicked(self, event): |
|||
self.reload = True |
|||
⚫ | |||
QtGui.QApplication.processEvents() |
|||
time.sleep(0.1) |
|||
def addCheckboxes (self, cbLayout): |
def addCheckboxes (self, cbLayout): |
||
Line 137: | Line 153: | ||
objLabel = getattr(FreeCAD.ActiveDocument,self.types[name][nn]).Label |
objLabel = getattr(FreeCAD.ActiveDocument,self.types[name][nn]).Label |
||
objName = self.types[name][nn] |
objName = self.types[name][nn] |
||
if objLabel != objName: |
if objLabel != objName and self.showAll: |
||
ck = QtGui.QCheckBox(self.types[name][nn]+" ("+objLabel+")", self) |
ck = QtGui.QCheckBox(self.types[name][nn]+" ("+objLabel+")", self) |
||
else: |
else: |
||
Line 164: | Line 180: | ||
""" |
""" |
||
for nl in nameList: |
for nl in nameList: |
||
if nl in name: |
if nl in name and nl[:3] == name[:3]: |
||
self.addToTypes(nl,name) |
self.addToTypes(nl,name) |
||
return True |
return True |
||
Line 177: | Line 193: | ||
def accept(self): |
def accept(self): |
||
"""user clicked Ok""" |
"""user clicked Ok""" |
||
self.setWindowOpacity(0. |
self.setWindowOpacity(0.85) |
||
self.infoLabel.setText("Working...") |
|||
if self.showAll: |
if self.showAll: |
||
for ii in range(1, len(self.checkboxes)): |
for ii in range(1, len(self.checkboxes)): |
||
Line 185: | Line 202: | ||
if state == QtCore.Qt.Checked: |
if state == QtCore.Qt.Checked: |
||
obj = getattr(FreeCAD.ActiveDocument, name) |
obj = getattr(FreeCAD.ActiveDocument, name) |
||
obj.ViewObject.Visibility |
if not obj.ViewObject.Visibility: |
||
obj.ViewObject.Visibility = True |
|||
else: |
else: |
||
obj = getattr(FreeCAD.ActiveDocument, name) |
obj = getattr(FreeCAD.ActiveDocument, name) |
||
obj.ViewObject.Visibility |
if obj.ViewObject.Visibility: |
||
obj.ViewObject.Visibility = False |
|||
QtGui.QApplication.processEvents() |
QtGui.QApplication.processEvents() |
||
time.sleep(0.01) |
time.sleep(0.01) |
||
Line 219: | Line 238: | ||
dlg.setWindowTitle("Visibility Manager v"+str(__version__)) |
dlg.setWindowTitle("Visibility Manager v"+str(__version__)) |
||
result = dlg.exec_() |
result = dlg.exec_() |
||
while dlg.reload: |
|||
showAll = not dlg.showAll |
|||
dlg = Dlg(showAll) |
|||
dlg.setWindowTitle("Visibility Manager v"+str(__version__)) |
|||
result = dlg.exec_() |
|||
else: |
else: |
||
FreeCAD.Console.PrintWarning("Visibility Manager v"+str(__version__)+": no active document\n") |
FreeCAD.Console.PrintWarning("Visibility Manager v"+str(__version__)+": no active document\n") |
Latest revision as of 10:44, 21 December 2021
Description |
---|
Use this to manage the visibility of document objects. There are 2 modes of operation: Show All and Show Types. In Show Types mode (the default) you only see a list of the types of objects, e.g. Body, Sketch, Pad, Extrude. Toggling one of the types off/on will set the visibility of all document objects of that type in the active document. |
Author |
TheMarkster |
Download |
ToolBar Icon |
Links |
Macros recipes How to install macros How to customize toolbars |
Macro Version |
1.06 |
Date last modified |
2020-06-18 |
FreeCAD Version(s) |
All |
Default shortcut |
None |
See also |
None |
Description
Use this macro to manage visibility of document objects either by type or individually.
Script
Macro_Visibility_Manager.FCMacro
# -*- coding: utf-8 -*- """ *************************************************************************** * Copyright (c) 2019 <TheMarkster> * * * * This file is a supplement to the FreeCAD CAx development system. * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License (LGPL) * * as published by the Free Software Foundation; either version 2 of * * the License, or (at your option) any later version. * * * * This software is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License at http://www.gnu.org/licenses * * for more details. * * * * For more information about the GNU Library General Public License * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307 USA * * * *************************************************************************** """ """ Visibility_Manager Macro Use this to manage the visibility of document objects. There are 2 modes of operation: Show All and Show Types. In Show Types mode (the default) you only see a list of the types of objects, e.g. Body, Sketch, Pad, Extrude. Toggling one of the types off/on will set the visibility of all document objects of that type in the active document. In Show All mode (Press Shift key while executing the macro) you see a different checkbox for each and every document object, sorted alphabetically. You can toggle each object's visibility individually. """ __title__ = "Visibility_Manager" __author__ = "TheMarkster" __url__ = "" __Wiki__ = "https://www.freecadweb.org/wiki/Macro_Visibility_Manager" __date__ = "2020.06.18" __version__ = 1.06 import FreeCAD from PySide import QtCore, QtGui import time class Dlg(QtGui.QDialog): def __init__(self, bShowAll=False): QtGui.QDialog.__init__(self) self.types={} #dict of types self.showAll = bShowAll self.reload = False self.infoLabel = QtGui.QLabel() self.infoLabel.mousePressEvent = self.label_clicked if self.showAll: self.infoLabel.setText("Show All mode") else: self.infoLabel.setText("Show by Type mode") checkboxLayout = QtGui.QVBoxLayout() self.checkboxes = [] widget = QtGui.QWidget() #will hold scroll area checkboxLayout = QtGui.QVBoxLayout() self.addCheckboxes(checkboxLayout) widget.setLayout(checkboxLayout) #Scroll Area Properties scroll = QtGui.QScrollArea() scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn) scroll.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setWidget(widget) vLayout = QtGui.QVBoxLayout() vLayout.addWidget(scroll) #buttons = QtGui.QDialogButtonBox( # QtGui.QDialogButtonBox.Ok.__or__(QtGui.QDialogButtonBox.Cancel), # QtCore.Qt.Horizontal, self) buttons = QtGui.QDialogButtonBox(QtGui.QDialogButtonBox.Ok, QtCore.Qt.Horizontal,self) buttons.addButton(QtGui.QDialogButtonBox.Cancel) mode_button = buttons.addButton('Switch Mode', QtGui.QDialogButtonBox.ActionRole) mode_button.clicked.connect(self.label_clicked) buttons.accepted.connect(self.accept) buttons.rejected.connect(self.reject) buttons.setCenterButtons(True) layout = QtGui.QVBoxLayout() layout.addWidget(self.infoLabel) layout.addLayout(vLayout) layout.addWidget(buttons) self.setLayout(layout) def label_clicked(self, event): self.reload = True self.close() QtGui.QApplication.processEvents() time.sleep(0.1) def addCheckboxes (self, cbLayout): objectList = FreeCAD.ActiveDocument.findObjects() objectList.sort(key=lambda x: x.Name, reverse=False) nameList = [] for obj in objectList: if not self.nameInList(obj.Name, nameList): nameList.append(obj.Name) self.newType(obj.Name) all = QtGui.QCheckBox("All", self) all.setObjectName("all") all.toggled.connect(self.allToggled) cbLayout.addWidget(all) self.checkboxes = [all] for name in nameList: for nn in range(0,len(self.types[name])): objLabel = getattr(FreeCAD.ActiveDocument,self.types[name][nn]).Label objName = self.types[name][nn] if objLabel != objName and self.showAll: ck = QtGui.QCheckBox(self.types[name][nn]+" ("+objLabel+")", self) else: ck = QtGui.QCheckBox(objName,self) ck.setObjectName(objName) if getattr(FreeCAD.ActiveDocument,self.types[name][nn]).ViewObject.Visibility: ck.setCheckState(QtCore.Qt.Checked) else: ck.setCheckState(QtCore.Qt.Unchecked) if nn != 0 and not self.showAll: ck.hide() cbLayout.addWidget(ck) self.checkboxes.append(ck) def addToTypes(self, typeName, name): self.types[typeName].append(name) def newType(self, typeName): self.types[typeName] = [typeName] def nameInList(self, name, nameList): """ check if name is in nameList e.g. name = "Extrude002" nameList = ["Extrude", "Extrude001", "Extrude002"...] """ for nl in nameList: if nl in name and nl[:3] == name[:3]: self.addToTypes(nl,name) return True return False def allToggled(self): """all checkbox was toggled""" allState = self.checkboxes[0].checkState() for ii in range(1,len(self.checkboxes)): self.checkboxes[ii].setCheckState(allState) def accept(self): """user clicked Ok""" self.setWindowOpacity(0.85) self.infoLabel.setText("Working...") if self.showAll: for ii in range(1, len(self.checkboxes)): name = self.checkboxes[ii].objectName() state = self.checkboxes[ii].checkState() if state == QtCore.Qt.Checked: obj = getattr(FreeCAD.ActiveDocument, name) if not obj.ViewObject.Visibility: obj.ViewObject.Visibility = True else: obj = getattr(FreeCAD.ActiveDocument, name) if obj.ViewObject.Visibility: obj.ViewObject.Visibility = False QtGui.QApplication.processEvents() time.sleep(0.01) else: #show type mode for ii in range(1, len(self.checkboxes)): if not self.checkboxes[ii].isVisible(): continue name = self.checkboxes[ii].objectName() state = self.checkboxes[ii].checkState() if state == QtCore.Qt.Checked: for n in self.types[name]: obj = getattr(FreeCAD.ActiveDocument, n) obj.ViewObject.Visibility = True else: for n in self.types[name]: obj = getattr(FreeCAD.ActiveDocument, n) obj.ViewObject.Visibility = False QtGui.QApplication.processEvents() time.sleep(0.01) self.close() showAll = False modifiers = QtGui.QApplication.keyboardModifiers() if modifiers == QtCore.Qt.ShiftModifier: showAll = True if FreeCAD.ActiveDocument: dlg = Dlg(showAll) dlg.setWindowTitle("Visibility Manager v"+str(__version__)) result = dlg.exec_() while dlg.reload: showAll = not dlg.showAll dlg = Dlg(showAll) dlg.setWindowTitle("Visibility Manager v"+str(__version__)) result = dlg.exec_() else: FreeCAD.Console.PrintWarning("Visibility Manager v"+str(__version__)+": no active document\n")