Edited at

FreeCADのpythonマクロでTree viewをReport viewに表示 してみた

More than 1 year has passed since last update.

# -*- coding: utf-8 -*-

def MYSelect_all():
# https://forum.freecadweb.org/viewtopic.php?f=3&t=19248
# Code: Select all
Gui.Selection.clearSelection()
for obj in FreeCAD.ActiveDocument.Objects:
if obj.ViewObject.isVisible():
Gui.Selection.addSelection(obj)
return
# ------------------------------------------------------
def MYclear_report():
# https://forum.freecadweb.org/viewtopic.php?t=9825
# clear console and clear report by python
from PySide import QtGui
mw=Gui.getMainWindow()
r=mw.findChild(QtGui.QTextEdit, "Report view")
r.clear()
return
# ------------------------------------------------------
import time
print "開始:",time.ctime()
MYclear_report()
MYSelect_all()
# https://www.freecadweb.org/wiki/Manual/jp
# 選択機能を使う
for o in Gui.Selection.getSelectionEx():
print "オブジェクト = ",o.ObjectName ,"(",o.Object.Label,")"
for s in o.SubElementNames:
print "name: ",s
for s in o.SubObjects:
print "object: ",s

Gui.Selection.clearSelection()
print "終了"

# o.Labelとすると、以下のエラーがでます。
# <type 'exceptions.AttributeError'>: 'Gui.SelectionObject' object has no attribute 'Label'

(参考)マクロでラベルを出力する方法を教えて下さい

https://forum.freecadweb.org/viewtopic.php?f=16&t=26805