Macro Manage Navigational Style

Description
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.

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.

Installation
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.

Usage
Select the document you wish to dump objects for, then start the macro from one of:
 * the Macro menu
 * from the Python console
 * from a Toolbar

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:


 * irregularities in object names (e.g. spelling errors or default names generated by FreeCAD)
 * duplicate objects
 * objects with duplicate names (where FreeCAD has had to make the second object name unique)
 * unexpected objects
 * unexpected object Placements (when the Show Positions option is selected)
 * unexpected segments in the Sketch Geometry (when the Show Sketcher Segments option is selected)

User Interface
The first window will take input which configures the Object Dump:



The second window will be the report on the objects in the current document:



Options

 * output may be directed to one of:
 * the Report view
 * a non-modal window
 * segments in the Geometry for each Sketch may be listed
 * Placement specifics may be listed for objects

Remarks
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.

Links
none (so far)

Script
{{Code|code=
 * 1) 			Dump Object
 * 2) routine to dump object space for Geometric model in the currently active file
 * 1) routine to dump object space for Geometric model in the currently active file
 * 1) routine to dump object space for Geometric model in the currently active file
 * 1) routine to dump object space for Geometric model in the currently active file

from PySide import QtGui, QtCore from datetime import datetime


 * 1) 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(275, 100) # define window		xLoc,yLoc,xDim,yDim self.setGeometry(	250, 250, 400, 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

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) 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 window		xLoc,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
 * 1) class DisplayText(QtGui.QMainWindow):


 * 1) define functions

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:] 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", "Part2DObjectPython"): printList.append(formatPrintLine(wb, shape, str(obj.Label), str(obj.Name))) elif obj.TypeId == "Part::Feature": printList.append(formatPrintLine(str(obj.TypeId), "", str(obj.Label), str(obj.Name))) elif obj.TypeId == "Part::Part2DObjectPython": 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", "Fillet"): printList.append(formatPrintLine(wb, shape, str(obj.Label), str(obj.Name))) elif obj.TypeId == "Part::Feature": printList.append(formatPrintLine(str(obj.TypeId), "", str(obj.Label), str(obj.Name))) elif obj.TypeId == "Part::Part2DObjectPython": 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: printList.append(formatPr