Macro ExpandTreeItem

From FreeCAD Documentation
Revision as of 17:22, 11 December 2018 by FuzzyBot (talk | contribs) (Updating to match new version of source page)
Other languages:

File:Macro ExpandTreeItem Macro ExpandTreeItem

Descrizione
Nella vista della struttura espande l'albero selezionato e tutti gli alberi secondari.

Versione macro: 00.00
Ultima modifica: 2018-07-11
Autore: wmayer, UR_
Autore
wmayer, UR_
Download
None
Link
Versione macro
00.00
Data ultima modifica
2018-07-11
Versioni di FreeCAD
None
Scorciatoia
Nessuna
Vedere anche
Nessuno

Descrizione

Espande l'albero selezionato e tutti i sottoalberi nella vista ad albero.

se l'albero selezionato è già espanso, questo albero e tutti gli alberi secondari vengono compressi

se non ci sono selezioni vengono espansi tutti i rami (se sono già espansi vengono compressi)

Uso

Copiare la macro nella directory macro, creare la barra degli strumenti e avviare la macro.

Script

L'icona .png e la .SVG per la barra degli strumenti

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
# if there is no selection all trees are collapse True / False
#
__Title__    = "Macro ExpandTreeItem"
__Author__   = "wmayer, UR_"
__Version__  = "00.00"
__Date__     = "2018-07-11"

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()
    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?