Keyboard shortcut, View toolbar - Wireframe

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
herrdeh
Posts: 350
Joined: Wed Sep 03, 2014 12:15 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby herrdeh » Sun Nov 27, 2016 1:37 pm

Oh - thanks for reminding me to the "dailys". Now I've a 0.17 as well - great.

Anyway. The macro is running now - I set it to toggle between "Flat lines" and "wireframe", these are the views I'm using most.

But now - after once having used the macro, I no longer can use the ctrl-D ("view properties" or so) control - this one will no longer work. It needs a programme relaunch, then it does again.
So - this is not what at least I want. I'm mainly using wireframe for outer elements and leave the inner ones Flat lines, so I can clearly distinguish them, and if that possibility varnishes, I would rather not use that nice macro.

W
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Sun Nov 27, 2016 2:49 pm

You have access to all global draw style modes on the View toolbar. Therefore you don't have to restart FreeCAD at any point to change the mode. Based on your description you therefore need to toggle between 3 global modes:

Code: Select all

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

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

styleA = 0
styleB = 1
styleC = 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]
                actionC = b.menu().actions()[styleC]

                if actionA.isChecked():
                    actionB.trigger()
                elif actionB.isChecked():
                    actionC.trigger()
                else:
                    actionA.trigger()
            else:
                pass
    else:
        pass
P.S. But i do have a feeling you won't be happy with the macro until it supports changing object/global draw style modes. ;)
herrdeh
Posts: 350
Joined: Wed Sep 03, 2014 12:15 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby herrdeh » Sun Nov 27, 2016 3:03 pm

True.

And maybe you'll not be happy til you found a solution for this challenge...? (-;

W l
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Sun Nov 27, 2016 4:14 pm

herrdeh wrote:True.

And maybe you'll not be happy til you found a solution for this challenge...? (-;

W l
Well i was planning to do something else today and this macro challenge probably already exceeded the initial goal. As i went after compatibility with FreeCAD 0.16 (or older) and up therefore solution has some corner case scenarios when it won't work and it is not as future proof as it could be. Investing effort and building on that doesn’t make much sense. But i guess here we are and therefore:

Just selection:

Code: Select all

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

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
Combination object/global:

Code: Select all

# triplus @ 2016
# Toggle object/global DisplayMode
# ==============================

# 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
herrdeh
Posts: 350
Joined: Wed Sep 03, 2014 12:15 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby herrdeh » Sun Nov 27, 2016 5:02 pm

Great! - A big step forward. Most of the desired works.

One little thing remains, in 0.16 as well as 0.17.
Try to reproduce:
  • deselect all
  • trigger macro - e.g. everything to wireframe
  • select one item
  • trigger macro
    => several (not only the selected) items change their appearance.
  • from now everything works as desired
The same vice versa.

Keep going... (-;
W
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Sun Nov 27, 2016 5:26 pm

Nothing to fix here as when you deselected all objects you toggled global mode to Wireframe. If you want to toggle some or all objects to Wireframe mode and want to see that on the screen you need to select the objects first (macro will automatically adjust the global mode to As is).
mario52
Posts: 2861
Joined: Wed May 16, 2012 2:13 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby mario52 » Sun Nov 27, 2016 6:31 pm

Hi
work fine thanks

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Sun Nov 27, 2016 6:49 pm

To reduce potential confusion i will gather all possible solutions we discussed here:

Toggle global display mode:

Code: Select all

# 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
Toggle selected object(s) display mode (changes visible only in global As is (located on View toolbar) display mode):

Code: Select all

# 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
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:

Code: Select all

# 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
mario52
Posts: 2861
Joined: Wed May 16, 2012 2:13 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby mario52 » Tue Nov 29, 2016 10:29 am

hi
work fine i use
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:
thanks
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Dialog creation. My macros on Gist.github.
triplus
Posts: 9278
Joined: Mon Dec 12, 2011 4:45 pm

Re: Keyboard shortcut, View toolbar - Wireframe

Postby triplus » Tue Nov 29, 2016 10:45 am

Good to hear that and you're welcome.