Code: Select all
# triplus @ 2016, 2020
# Toggle object/global display mode
# ==============================
# Global drawstyle
# 0 = "As is"
# 1 = "Flat lines"
# 2 = "Shaded
# 3 = "Wireframe"
# 4 = "Points"
# 5 = "Hidden line"
# 6 = "No shading"
global_drawstyle_A = 0 # As is
global_drawstyle_B = 3 # Wireframe
# Object style
# "Flat Lines"
# "Shaded"
# "Wireframe"
# "Points"
object_style_A = "Flat Lines"
object_style_B = "Wireframe"
transparency_value = 85
# ======================================================================
from PySide import QtGui
import FreeCADGui as Gui
mw = Gui.getMainWindow()
sel = Gui.Selection.getSelectionEx()
act = {
0: mw.findChild(QtGui.QAction, "Std_DrawStyleAsIs"),
1: mw.findChild(QtGui.QAction, "Std_DrawStyleFlatLines"),
2: mw.findChild(QtGui.QAction, "Std_DrawStyleShaded"),
3: mw.findChild(QtGui.QAction, "Std_DrawStyleWireframe"),
4: mw.findChild(QtGui.QAction, "Std_DrawStylePoints"),
5: mw.findChild(QtGui.QAction, "Std_DrawStyleHiddenLine"),
6: mw.findChild(QtGui.QAction, "Std_DrawStyleNoShading"),
}
default = act[0]
actionA = act[global_drawstyle_A]
actionB = act[global_drawstyle_B]
if sel: # Objects selected
obj = []
default.trigger()
for s in sel:
if s.Object.TypeId == "App::Link":
if s.Object.LinkedObject not in obj:
obj.append(s.Object.LinkedObject)
elif s.Object not in obj:
obj.append(s.Object)
else:
pass
for o in obj:
if o.ViewObject.DisplayMode == object_style_A and o.ViewObject.Transparency == 0:
o.ViewObject.Transparency = transparency_value
o.ViewObject.LineWidth = 1
elif o.ViewObject.DisplayMode == object_style_A and o.ViewObject.Transparency > 0:
o.ViewObject.Transparency = 0
o.ViewObject.DisplayMode = object_style_B
o.ViewObject.LineWidth = 1
else:
o.ViewObject.DisplayMode = object_style_A
o.ViewObject.Transparency = 0
o.ViewObject.LineWidth = 2
else: # Objects not selected
if actionA.isChecked():
actionB.trigger()
else:
actionA.trigger()