Macro Toggle Drawstyle Optimized

From FreeCAD Documentation
Revision as of 13:07, 28 August 2019 by Mario52 (talk | contribs) (Created page with "Macro Toggle Drawstyle Optimized")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Other languages:

Macro Toggle Drawstyle Optimized

Description
Script optimized for all languages and to object selected or all objects.
When working with FreeCAD there are times when you want to quickly change the Drawstyle of the object you are working with. This is available through the Drawstyle pull-down menu where any Drawstyle may be selected. This macro makes 2 of the Drawstyles available as a clickable button on a toolbar which the user may click to toggle back and forth between the two Drawstyles.
See also:
Toggle global display mode: Macro_Toggle_Drawstyle_Optimized_2.FCMacro
Toggle selected object(s) display mode (changes visible only in global As is (located on View toolbar) display mode): Macro_Toggle_Drawstyle_Optimized_3.FCMacro

Last modified: 2016-11-27
FreeCAD version: All
Download: ToolBar Icon
Author: Piffpoof , triplus
Author
Piffpoof , triplus
Download
ToolBar Icon
Links
Macro Version
1.0
Date last modified
2016-11-27
FreeCAD Version(s)
All
Default shortcut
None
See also
Macro Toggle Drawstyle

Description

Script optimized for all languages and to object selected or all objects.

Tree macro are available:

When working with FreeCAD there are times when you want to quickly change the Drawstyle of the object you are working with. This is available through the Drawstyle pull-down menu where any Drawstyle may be selected. This macro makes 2 of the Drawstyles available as a clickable button on a toolbar which the user may click to toggle back and forth between the two Drawstyles.

Installation

Installation is comprised of copying the two code to the appropriate Macro directory and invoking it from the Macro menu. It is much preferable to add it both to a toolbar so as to be more easily available.

Usage

Select an object, then click on the associated toolbar button, or invoke from the Macro menu. The Drawstyle of the slected object will toggle between the two drawstyles specified in the macro code (see code listing below).

Script

Combination that toggle global display mode when nothing is selected and/or toggle selected objects display mode if objects are selected. When objects are selected global display mode is automatically set to As is:


The icon ToolBar

Macro_Toggle_Drawstyle_Optimized.FCMacro

# triplus @ 2016
# Toggle object/global display mode
# ==============================

# 0 = "As is"
# 1 = "Flat lines"
# 2 = "Shaded
# 3 = "Wireframe"
# 4 = "Points"

globalA = 0
globalB = 3

a = "Flat Lines"
b = "Shaded"
c = "Wireframe"
d = "Points"

objectA = a
objectB = c

# ==============================

from PySide import QtGui
import FreeCADGui as Gui

mw = Gui.getMainWindow()

s = FreeCADGui.Selection.getSelectionEx()

default = None
actionA = None
actionB = None

for i in mw.findChildren(QtGui.QToolBar):
    if i.objectName() == "View":
        for b in i.findChildren(QtGui.QToolButton):
            if b.menu():
                default = b.menu().actions()[0]
                actionA = b.menu().actions()[globalA]
                actionB = b.menu().actions()[globalB]
            else:
                pass

if s:
    if default:
        default.trigger()
    else:
        pass

    for i in s:
        if i.Object.ViewObject.DisplayMode == objectA:
            i.Object.ViewObject.DisplayMode = objectB
        else:
            i.Object.ViewObject.DisplayMode = objectA
else:
    if actionA and actionB:
        if actionA.isChecked():
            actionB.trigger()
        else:
            actionA.trigger()
    else:
        pass

Script 2

Toggle global display mode:

The icon ToolBar

Macro_Toggle_Drawstyle_Optimized_2.FCMacro

# triplus @ 2016
# Toggle global display mode
# ==============================

# 0 = "As is"
# 1 = "Flat lines"
# 2 = "Shaded
# 3 = "Wireframe"
# 4 = "Points"

styleA = 0
styleB = 3

# ==============================

from PySide import QtGui
import FreeCADGui as Gui

mw = Gui.getMainWindow()

for i in mw.findChildren(QtGui.QToolBar):
    if i.objectName() == "View":
        for b in i.findChildren(QtGui.QToolButton):
            if b.menu():
                actionA = b.menu().actions()[styleA]
                actionB = b.menu().actions()[styleB]

                if actionA.isChecked():
                    actionB.trigger()
                else:
                    actionA.trigger()
            else:
                pass
    else:
        pass

Script 3

Toggle selected object(s) display mode (changes visible only in global As is (located on View toolbar) display mode):

The icon ToolBar

Macro_Toggle_Drawstyle_Optimized_3.FCMacro

# triplus @ 2016
# Toggle selected object(s) display mode
# ==============================

a = "Flat Lines"
b = "Shaded"
c = "Wireframe"
d = "Points"

styleA = a
styleB = c

# ==============================

s = FreeCADGui.Selection.getSelectionEx()

for i in s:
    if i.Object.ViewObject.DisplayMode == styleA:
        i.Object.ViewObject.DisplayMode = styleB
    else:
        i.Object.ViewObject.DisplayMode = styleA

Link

The Forum link : Keyboard shortcut, View toolbar - Wireframe