Macro Print SceneGraph

From FreeCAD Documentation
Revision as of 19:56, 15 October 2017 by Aleph0 (talk | contribs) (Macro code to print the SceneGraph)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

{{Macro|Icon=Text-x-python|Name=Macro_Print_SceneGraph|Description=Prints the SceneGraph|Author=Aleph0|Version=00.01|Date=2017-10-17}

"""
***************************************************************************
*                                                                         *
*   This macro traverses the SceneGraph and prints all the nodes and      *
*   their fields in the Report View window. It can be used just for       *
*   information or you can add code to modify parts of the SceneGraph in  *
*   some way or print more details for particular types of node.          *
*                                                                         *
***************************************************************************
*   Copyright (c) 2017 Richard P. Parkins, M. A.                          *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
"""
__title__   = "Print_SceneGraph"
__author__  = "Aleph0"
__version__ = "00.01"
__date__    = "15/10/2017"
__Comment__ = "SceneGraph explorer"
 __Wiki__ = "http://www.freecadweb.org/wiki/index.php?title=Macro_Print_SceneGraph"
__Help__ = "see first few lines of macro text"
__Status__ = "stable"
__Requires__ = "freecad 0.16"

import FreeCAD
from pivy import coin

def printFields(node,indent):
    fl = node.getFieldData()
    for i in range(fl.getNumFields()):
        name = fl.getFieldName(i)
        val = node.getField(fl.getFieldName(i)).get()
        FreeCAD.Console.PrintLog(indent+str(name)+" -> "+str(val)+"\n")

def printTree(node,indent):
    FreeCAD.Console.PrintLog(indent+node.__str__()+"\n")
    if node.getChildren().__str__() <> 'None':
        printFields(node,indent)
        for i in range(node.getNumChildren()):
            printTree(node.getChild(i),indent+" ")

sg = FreeCADGui.ActiveDocument.ActiveView.getSceneGraph()