407 lines
18 KiB
HTML
407 lines
18 KiB
HTML
<html><head><title>Macro Dump Objects/fr</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link type='text/css' href='wiki.css' rel='stylesheet'></head><body><h1>Macro Dump Objects/fr</h1></div>
|
|
|
|
<div id="mw-content-text" lang="fr" dir="ltr" class="mw-content-ltr"><hr/><div class="mw-parser-output"><table class="fcinfobox wikitable ct" width="100%" style="float: right; width: 230px; margin-left: 10px;">
|
|
<tr>
|
|
<td class="ctTitle">
|
|
<h3><span class="mw-headline" id="Macro_Dump_Objects"><a href="https://www.freecadweb.org/wiki/index.php?title=File:Macro_Dump_Objects.png" class="image"><img alt="Macro Dump Objects.png" src="32px-Macro_Dump_Objects.png" width="32" height="32" srcset="/wiki/images/thumb/2/2e/Macro_Dump_Objects.png/48px-Macro_Dump_Objects.png 1.5x, /wiki/images/2/2e/Macro_Dump_Objects.png 2x" /></a> Macro Dump Objects</span></h3>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Description
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven left">This macro generates a listing of all objects in the current document - the list can be in a window or on the Report view.
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Auteur
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=User:Piffpoof" title="User:Piffpoof">Piffpoof</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Liens
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven"><a href="https://www.freecadweb.org/wiki/index.php?title=Macros_recipes/fr" title="Macros recipes/fr">Recettes macros</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=How_to_install_macros/fr" title="How to install macros/fr">Comment installer une macro</a><br /><a href="https://www.freecadweb.org/wiki/index.php?title=Customize_Toolbars/fr" title="Customize Toolbars/fr">Comment ajouter une barre d'outils</a>
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Version
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-version">1.0
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">Date dernière modification
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctEven macro-date">2015-03-02
|
|
</td></tr>
|
|
<tr>
|
|
<th class="ctOdd">
|
|
</th></tr>
|
|
<tr>
|
|
<td class="ctToc"><br /><div id="toc" class="toc"><div class="toctitle"><h2>Contents</h2></div>
|
|
<ul>
|
|
<li class="toclevel-1"><a href="#Macro_Dump_Objects"><span class="tocnumber">1</span> <span class="toctext">Macro Dump Objects</span></a></li>
|
|
<li class="toclevel-1 tocsection-1"><a href="#Description"><span class="tocnumber">2</span> <span class="toctext">Description</span></a></li>
|
|
<li class="toclevel-1 tocsection-2"><a href="#Installation"><span class="tocnumber">3</span> <span class="toctext">Installation</span></a></li>
|
|
<li class="toclevel-1 tocsection-3"><a href="#Usage"><span class="tocnumber">4</span> <span class="toctext">Usage</span></a></li>
|
|
<li class="toclevel-1 tocsection-4"><a href="#User_Interface"><span class="tocnumber">5</span> <span class="toctext">User Interface</span></a></li>
|
|
<li class="toclevel-1 tocsection-5"><a href="#Options"><span class="tocnumber">6</span> <span class="toctext">Options</span></a></li>
|
|
<li class="toclevel-1 tocsection-6"><a href="#Remarks"><span class="tocnumber">7</span> <span class="toctext">Remarks</span></a></li>
|
|
<li class="toclevel-1 tocsection-7"><a href="#Links"><span class="tocnumber">8</span> <span class="toctext">Links</span></a></li>
|
|
<li class="toclevel-1 tocsection-8"><a href="#Script"><span class="tocnumber">9</span> <span class="toctext">Script</span></a></li>
|
|
</ul>
|
|
</div>
|
|
|
|
</td></tr>
|
|
</table>
|
|
<p><br />
|
|
</p><p>When developing complex object models it is easy to loose track of exactly which objects are present as some may be hidden, obscured or transparent. Additionally with a large number of objects a naming system becomes necessary to keep track of the objects.
|
|
</p><p><a href="https://www.freecadweb.org/wiki/index.php?title=File:DumpObjectsScreenSnapshot.jpg" class="image"><img alt="DumpObjectsScreenSnapshot.jpg" src="DumpObjectsScreenSnapshot.jpg" width="500" height="249" /></a>
|
|
</p>
|
|
<h2><span class="mw-headline" id="Description">Description</span></h2>
|
|
<p>The Dump Object code takes the current document and enumerates all the objects. A report is then generated listing each object, then a summary giving the total number of instances of each Class, followed by the total number of Classes and finally the total number of objects. The output may be directed to the Report view or to a window. The window is non-modal and will stay open until closed by the user. Each window has the time of the object dump in it's title bar, so the contents of multiple windows can be compared, say before and after a piece of code running.
|
|
</p><p>The default operation lists all objects, optionally the placement of each object can be listed. Also for Sketches, each segment of the Geometry can be listed.
|
|
</p>
|
|
<h2><span class="mw-headline" id="Installation">Installation</span></h2>
|
|
<p>All the code for dumpObject.FCMacro is in one macro. So installation is comprised of copying the code to the appropriate Macro directory and invoking dumpObject from the Macro menu. Alternatively it may be run from the console.
|
|
</p>
|
|
<ul><li> see <a href="How_to_install_macros.html" title="How to install macros">How to install macros</a> for information on how to install this macro code</li>
|
|
<li> see <a href="Customize_Toolbars.html" title="Customize Toolbars">Customize Toolbars</a> for information how to install as a button on a toolbar</li></ul>
|
|
<h2><span class="mw-headline" id="Usage">Usage</span></h2>
|
|
<p>Select the document you wish to dump objects for, then start the macro from one of:
|
|
</p>
|
|
<ul><li> the Macro menu</li>
|
|
<li> from the Python console</li>
|
|
<li> from a Toolbar</li></ul>
|
|
<p>Depending on the parameters selected in the first window, the report will be displayed on the Report view or in a window.
|
|
The information will show all objects in the current document. Some of the benefits to be expected are the detection of:
|
|
</p>
|
|
<ul><li> irregularities in object names (e.g. spelling errors or default names generated by FreeCAD)</li>
|
|
<li> duplicate objects</li>
|
|
<li> objects with duplicate names (where FreeCAD has had to make the second object name unique)</li>
|
|
<li> unexpected objects</li>
|
|
<li> unexpected object Placements (when the Show Positions option is selected)</li>
|
|
<li> unexpected segments in the Sketch Geometry (when the Show Sketcher Segments option is selected)</li></ul>
|
|
<h2><span class="mw-headline" id="User_Interface">User Interface</span></h2>
|
|
<p>The first window will take input which configures the Object Dump:
|
|
</p><p><a href="https://www.freecadweb.org/wiki/index.php?title=File:DumpObjectsGui1.jpg" class="image"><img alt="DumpObjectsGui1.jpg" src="DumpObjectsGui1.jpg" width="400" height="172" /></a>
|
|
</p><p><br />
|
|
The second window will be the report on the objects in the current document:
|
|
</p><p><br />
|
|
<a href="https://www.freecadweb.org/wiki/index.php?title=File:DumpObjectsGui2.jpg" class="image"><img alt="DumpObjectsGui2.jpg" src="DumpObjectsGui2.jpg" width="769" height="383" /></a>
|
|
</p>
|
|
<h2><span class="mw-headline" id="Options">Options</span></h2>
|
|
<ul><li> output may be directed to one of:
|
|
<ul><li> the Report view</li>
|
|
<li>a non-modal window</li></ul></li>
|
|
<li> segments in the Geometry for each Sketch may be listed</li>
|
|
<li> Placement specifics may be listed for objects</li></ul>
|
|
<h2><span class="mw-headline" id="Remarks">Remarks</span></h2>
|
|
<p>Although tested with many object types in FreeCAD, there probably are some objects that it does not expect, in that case it should list them generically.
|
|
</p>
|
|
<h2><span class="mw-headline" id="Links">Links</span></h2>
|
|
<p>none (so far)
|
|
</p>
|
|
<h2><span class="mw-headline" id="Script">Script</span></h2>
|
|
<pre>#
|
|
#Dump Object
|
|
# v 0.2 - added report to CSV file
|
|
# v 0.1 - added report to window
|
|
# v 0.0 - report to Report view
|
|
#
|
|
#***********************************************************************************
|
|
# routine to dump object space for Geometric model in the currently active file
|
|
#
|
|
# import statements
|
|
from PySide import QtGui, QtCore
|
|
from datetime import datetime# datestamp on output window
|
|
from os.path import expanduser# output directory for CSV
|
|
|
|
# UI Class definitions
|
|
|
|
class configureMacro(QtGui.QDialog):
|
|
""""""
|
|
def __init__(self):
|
|
super(configureMacro, self).__init__()
|
|
self.initUI()
|
|
def initUI(self):
|
|
self.result= None
|
|
# set up display only field for selected path type
|
|
self.cbss= QtGui.QCheckBox("Show Sketcher Segments?", self)
|
|
self.cbss.move(20,20)
|
|
self.cbp= QtGui.QCheckBox("Show Positions?", self)
|
|
self.cbp.move(220,20)
|
|
self.pathTypeLbl= QtGui.QLabel("Select Report Destination:", self)
|
|
self.pathTypeLbl.move(20, 70)
|
|
# cancel button
|
|
cancelButton = QtGui.QPushButton('Cancel', self)
|
|
cancelButton.clicked.connect(self.onCancel)
|
|
cancelButton.move(10, 100)
|
|
# button #1
|
|
button1 = QtGui.QPushButton(choice1, self)
|
|
button1.clicked.connect(self.onBtn1)
|
|
button1.move(120, 100)
|
|
# button #2
|
|
button2 = QtGui.QPushButton(choice2, self)
|
|
button2.clicked.connect(self.onBtn2)
|
|
button2.move(235, 100)
|
|
# button #3
|
|
button3 = QtGui.QPushButton(choice3, self)
|
|
button3.clicked.connect(self.onBtn3)
|
|
button3.move(327, 100)
|
|
# define windowxLoc,yLoc,xDim,yDim
|
|
self.setGeometry(250, 250, 435, 150)
|
|
self.setWindowTitle("Select a Report Destination")
|
|
self.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
|
|
self.show()
|
|
def onCancel(self):
|
|
self.result = "cancelled"
|
|
self.close()
|
|
def onBtn1(self):
|
|
self.result = choice1
|
|
self.close()
|
|
def onBtn2(self):
|
|
self.result = choice2
|
|
self.close()
|
|
def onBtn3(self):
|
|
self.result = choice3
|
|
self.close()
|
|
|
|
class DisplayText(QtGui.QWidget):
|
|
""""""
|
|
def __init__(self, textToDisplay):
|
|
self.text = textToDisplay
|
|
super(DisplayText, self).__init__()
|
|
self.initUI(textToDisplay)
|
|
def initUI(self, textToDisplay):
|
|
"""Constructor"""
|
|
self.textToDisplay = textToDisplay
|
|
# some window dimensions
|
|
self.windowHome = screenWidth * 0.05
|
|
self.windowWidth = screenWidth * 0.9
|
|
self.windowHeight = 400
|
|
self.fieldMargin = 40
|
|
# some column titles
|
|
columnLabels = QtGui.QLabel(formatPrintLine("Type / WB","Shape","User Supplied Label","Name"))
|
|
columnLabels.setFont('Courier')
|
|
# set up text editing widget
|
|
text_editor = QtGui.QTextEdit(self)
|
|
#self.setCentralWidget(self.text_editor)
|
|
text_editor.setFont('Courier')
|
|
text_editor.setLineWrapMode(QtGui.QTextEdit.NoWrap)
|
|
text_editor.move(self.fieldMargin,self.fieldMargin)
|
|
text_editor.move(0,self.fieldMargin)
|
|
text_editor.resize(self.windowWidth-(2*self.fieldMargin),self.windowHeight-(2*self.fieldMargin))
|
|
text_editor.resize(self.windowWidth,self.windowHeight-(2*self.fieldMargin))
|
|
text_editor.append(self.textToDisplay)
|
|
# set up the layout
|
|
vBox = QtGui.QVBoxLayout()
|
|
vBox.addWidget(columnLabels)
|
|
vBox.addWidget(text_editor)
|
|
self.setLayout(vBox)
|
|
# define windowxLoc,yLoc,xDim,yDim
|
|
self.setGeometry(self.windowHome, self.windowHome, self.windowWidth, self.windowHeight)
|
|
self.setWindowTitle("Object Dump of '" + FreeCADGui.ActiveDocument.Document.Label + "' at " + str(datetime.now()))
|
|
self.show()
|
|
#----------------------------------------------------------------------
|
|
def onOk(self):
|
|
self.close()
|
|
|
|
# Class definitions
|
|
|
|
# Function Definitions
|
|
|
|
def countObjects():
|
|
printList = list()
|
|
objectTypeTable = {}
|
|
# build up dictionary of different classes and keep a count
|
|
for obj in FreeCAD.ActiveDocument.Objects:
|
|
if objectTypeTable.has_key(obj.TypeId):
|
|
objectTypeTable[obj.TypeId] = objectTypeTable[obj.TypeId]+1
|
|
else:
|
|
objectTypeTable[obj.TypeId] = 1
|
|
wb = obj.TypeId[0:obj.TypeId.find("::")]
|
|
shape = obj.TypeId[obj.TypeId.find("::")+2:]
|
|
#print wb + "---" + shape
|
|
placementString = ""
|
|
if obj.TypeId == "Sketcher::SketchObject":
|
|
printList.append(formatPrintLine("Sketch", "", str(obj.Label)))
|
|
if showSketcherSegmentsFlag:
|
|
for i in obj.Geometry:
|
|
printList.append(formatPrintLine("", " -segment", str(i)))
|
|
elif wb == "Part":
|
|
if showPlacementFlag:
|
|
placementString = str(obj.Placement)
|
|
if shape in ("Cylinder", "Cut", "Box", "Fuse", "Loft", "Feature", "FeaturePython", "Part2DObjectPython"):
|
|
printList.append(formatPrintLine(wb, shape, str(obj.Label), str(obj.Name)))
|
|
else: # print shapes not in list above
|
|
printList.append(formatPrintLine(str(obj.TypeId), "", str(obj.Label), str(obj.Name)))
|
|
elif wb == "PartDesign":
|
|
if showPlacementFlag:
|
|
placementString = str(obj.Placement)
|
|
if shape in ("Pad", "Feature", "Fillet", "Part2DObjectPython"):
|
|
printList.append(formatPrintLine(wb, shape, str(obj.Label), str(obj.Name)))
|
|
else: # print shapes not in list above
|
|
printList.append(formatPrintLine(str(obj.TypeId), "", str(obj.Label), str(obj.Name)))
|
|
elif obj.TypeId == "App::DocumentObjectGroup":
|
|
printList.append(formatPrintLine("Group", "", str(obj.Label)))
|
|
elif obj.TypeId == "Image::ImagePlane":
|
|
printList.append(formatPrintLine(wb, shape, str(obj.Label), str(obj.Name)))
|
|
else: # print workbench shapes not in lists above
|
|
printList.append(formatPrintLine(str(obj.TypeId), str(obj.Label), str(obj.Name)))
|
|
if showPlacementFlag and len(placementString)!=0:
|
|
printList.append(formatPrintLineMax("", " -placement", placementString))
|
|
|
|
printList.append("")
|
|
printList.append(summarySeparator)
|
|
from collections import OrderedDict
|
|
sortedByTags = OrderedDict(sorted(objectTypeTable.items(), key=lambda x: x[1], reverse=True))
|
|
for k, v in sortedByTags.items():
|
|
printList.append(formatPrintLineSum(k,v))
|
|
printList.append("")
|
|
objectClassCount = 0; objectTotalCount = 0
|
|
for i in objectTypeTable:
|
|
objectTotalCount = objectTotalCount + objectTypeTable[i]
|
|
objectCLassCount = len(objectTypeTable)
|
|
printList.append(formatPrintLineSum("Object Class Total is ", str(objectCLassCount)))
|
|
printList.append(formatPrintLineSum("Object Total is ", str(objectTotalCount)))
|
|
printList.append(summarySeparator)
|
|
return printList
|
|
|
|
def formatPrintLineSum(a,b):
|
|
return printLineFormatter(2, a, str(b), "", "")
|
|
|
|
def formatPrintLineMax(a,b,c):
|
|
return printLineFormatter(1, a, b, "", "")
|
|
|
|
def formatPrintLine(a,b,c, *args):
|
|
d = ""
|
|
if len(args)==1:
|
|
d = args[0]
|
|
return printLineFormatter(0, a, b, c, d)
|
|
|
|
def printLineFormatter(flag,a,b,c,d):
|
|
# flag = 0standard print, spread values over 4 columns
|
|
# flag = 1printing verbose things like Sketch details or Placements, combine columns 3 & 4
|
|
# flag = 2printing the summary lines, combine columns 1 & 2
|
|
suffix = ""
|
|
if csvFlag:
|
|
pfs2 = printFormatString2csv
|
|
pfs3 = printFormatString3csv
|
|
pfs4 = printFormatString4csv
|
|
else:
|
|
pfs2 = printFormatString2
|
|
pfs3 = printFormatString3
|
|
pfs4 = printFormatString4
|
|
if flag==0:
|
|
aa = a[:f1]
|
|
bb = b[:f2]
|
|
cc = c[:f3]
|
|
dd = d[:f4]
|
|
return pfs4.format(aa,bb,cc,dd)
|
|
elif flag==1:
|
|
aa = a[:f1]
|
|
bb = b[:f2]
|
|
cc = c[:f3+f4]
|
|
dd = d[:f4]
|
|
return pfs3.format(aa,bb,cc)
|
|
else:
|
|
aa = a[:f1+f2]
|
|
bb = b[:f3+f4]
|
|
return pfs2.format(aa,bb)
|
|
|
|
# Constant definitions
|
|
# set some field widths
|
|
screenWidth = QtGui.QDesktopWidget().screenGeometry().width()
|
|
global f1, f2, f3, f4
|
|
# f1 = 15; f2 = 25; f3 = 45; f4 = 25 # 110 columns in 1000 pixels
|
|
f1 = 15*screenWidth/1000; f2 = 25*screenWidth/1000; f3 = 45*screenWidth/1000; f4 = 25*screenWidth/1000
|
|
# and some print format strings
|
|
global printFormatString2, printFormatString3, printFormatString4
|
|
global printFormatString2csv, printFormatString3csv, printFormatString4csv
|
|
printFormatString2 = "{0:<"+str(f1+f2)+"} {1:<"+str(f3)+"}"
|
|
printFormatString2csv = "{0}, {1}"
|
|
printFormatString3 = "{0:<"+str(f1)+"} {1:<"+str(f2)+"} {2:<"+str(f3+f4)+"}"
|
|
printFormatString3csv = "{0}, {1}, {2}"
|
|
printFormatString4 = "{0:<"+str(f1)+"} {1:<"+str(f2)+"} {2:<"+str(f3)+"} {3:<"+str(f4)+"}"
|
|
printFormatString4csv = "{0}, {1}, {2}, {3}"
|
|
# some button labels that are checked in the code
|
|
global choice1, choice2, choice3, csvFlag
|
|
choice1 = "Report View"; choice2 = "CSV File"; choice3 = "Window"
|
|
csvFlag = False
|
|
summarySeparator = "======================================================="
|
|
summarySeparatorCsv = "-------------------------------------------------------"
|
|
# code ***********************************************************************************
|
|
if FreeCAD.ActiveDocument != None:
|
|
# ask if to window or to Report View...
|
|
form = configureMacro()
|
|
form.exec_()
|
|
showSketcherSegmentsFlag = False
|
|
if form.cbss.isChecked():
|
|
showSketcherSegmentsFlag = True
|
|
showPlacementFlag = False
|
|
if form.cbp.isChecked():
|
|
showPlacementFlag = True
|
|
if form.result == choice2:
|
|
csvFlag = True
|
|
showSketcherSegmentsFlag = False
|
|
showPlacementFlag = False
|
|
summarySeparator = summarySeparatorCsv
|
|
printList = countObjects()
|
|
if form.result == choice1: # report to Report View
|
|
mainWindow = FreeCADGui.getMainWindow()
|
|
dockWidgets = mainWindow.findChildren(QtGui.QDockWidget)
|
|
reportViewFlag = False
|
|
for dw in dockWidgets:
|
|
if dw.objectName() == "Report view":
|
|
reportViewFlag = True
|
|
if reportViewFlag:
|
|
print printFormatString4.format("", "", "(User Supplied)", "")
|
|
print printFormatString4.format("Type", "Shape", "Label", "Name")
|
|
print ""
|
|
for line in printList:
|
|
print line + "\n"
|
|
else:
|
|
QtGui.QMessageBox.information(None,"","Please use 'Menu->View->Views->Report view' to open the 'Report view'")
|
|
if form.result == choice2: # report to CSV file
|
|
filePath = QtGui.QFileDialog.getSaveFileName(parent=None,caption="Save CSV file as",dir=expanduser("~"),filter="*.csv")
|
|
file = open(filePath[0],"w")
|
|
for line in printList:
|
|
file.write(line + "\n")
|
|
file.close()
|
|
if form.result == choice3: # report to window
|
|
#----------------------------------------------------------------------
|
|
longPrintLine = ""
|
|
for line in printList:
|
|
longPrintLine = longPrintLine + line + "\n"
|
|
form = DisplayText(longPrintLine)
|
|
#
|
|
#OS: Mac OS X
|
|
#Word size: 64-bit
|
|
#Version: 0.14.3703 (Git)
|
|
#Branch: releases/FreeCAD-0-14
|
|
#Hash: c6edd47334a3e6f209e493773093db2b9b4f0e40
|
|
#Python version: 2.7.5
|
|
#Qt version: 4.8.6
|
|
#Coin version: 3.1.3
|
|
#SoQt version: 1.5.0
|
|
#OCC version: 6.7.0
|
|
#
|
|
#thus ends the macro... </pre>
|
|
<div style="clear:both"></div>
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div><div class="printfooter">
|
|
Online version: "<a dir="ltr" href="https://www.freecadweb.org/wiki/index.php?title=Macro_Dump_Objects/fr&oldid=240511">http://www.freecadweb.org/wiki/index.php?title=Macro_Dump_Objects/fr&oldid=240511</a>"</div>
|
|
<div id="catlinks" class="catlinks" data-mw="interface"></div><div class="visualClear"></div>
|
|
</div>
|
|
</div>
|
|
<div id="mw-navigation">
|
|
<h2>Navigation menu</h2>
|
|
|
|
</body></html> |