Macro ExpandTreeItem

From FreeCAD Documentation
Jump to navigation Jump to search
Other languages:
English • ‎français • ‎italiano

Macro ExpandTreeItem.svg Macro ExpandTreeItem

Description
This macro expands selected tree and all sub trees in the tree view.
If there is no selection all trees are collapse False

Macro version: 00.02
Last modified: 2019-07-25
FreeCAD version: All
Download: ToolBar Icon
Author
wmayer, UR_
Download
ToolBar Icon
Links
Macro Version
00.02
Date last modified
2019-07-25
FreeCAD Version(s)
All
Default shortcut
None
See also
None


Description

Expands selected tree and all sub trees in the tree view.

if selected tree is already expanded this tree and all sub trees are collapsed

if there is no selection all trees are collapse False

Collapsed00.gif

Usage

Copy the macro in your macro directory, create your tool bar and launch.

Script

ToolBar Icon .PNG Macro ExpandTreeItem.png and the .SVG Macro ExpandTreeItem.svg

Macro_ExpandTreeItem.FCMacro

# -*- coding: utf-8 -*-
#
# Expands selected tree and all sub trees in the tree view.
# if selected tree is already expanded this tree and all sub trees are collapsed True/False
# if there is no selection all trees are collapse False
#
__Title__    = "Macro ExpandTreeItem"
__Author__   = "wmayer, UR_"
__Version__  = "00.02"
__Date__     = "2019-07-25"

import PySide
from PySide import QtGui ,QtCore
from PySide.QtGui import *
from PySide.QtCore import *

def toggleAll(tree, item, collapse):
    if collapse == False:
        tree.expandItem(item)
    elif collapse == True:  
        tree.collapseItem(item)

    for i in range(item.childCount()):
        toggleAll(tree, item.child(i), collapse)

mw = Gui.getMainWindow()
trees = mw.findChildren(QtGui.QTreeWidget)

for tree in trees:
    items = tree.selectedItems()

    try:
        if items == []:
            #tree.selectAll()                          # select all object
            for obj in FreeCAD.ActiveDocument.Objects: # select obj.OutList
                if len(obj.OutList) != 0:
                    Gui.Selection.addSelection(obj)
                    items = tree.selectedItems()
            for item in items:
                toggleAll(tree, item, False)
    except Exception:
        None

    for item in items:
            if item.isExpanded() == True:
                toggleAll(tree, item, True)
        #            print ("collapsing")
            else:
                toggleAll(tree, item, False)
        #            print ("expanding")

Link

Objektbaum mit einem Klick komplett aufklappen?