I definitly need to figure out ab better IDE setup and maybe actually read functions exposed by FreeCADs API.
Anyhow, a little Macro:
Code: Select all
import FreeCAD
from PySide import QtGui
def _is_a_part(element):
return (element is not None) and hasattr(element,'sourceFile')
def _update_parts(parts, name):
App = FreeCAD
for part in parts:
was_open = False
if part.sourceFile in [ d.FileName for d in FreeCAD.listDocuments().values() ]:
doc = [ d for d in FreeCAD.listDocuments().values() if d.FileName == part.sourceFile][0]
App.setActiveDocument(doc.Label)
was_open = True
else:
doc = App.openDocument(part.sourceFile)
App.setActiveDocument(doc.Label)
App.ActiveDocument=App.getDocument(doc.Label)
_update_parts(filter(_is_a_part, App.ActiveDocument.Objects), doc.Label)
App.ActiveDocument.save()
if not was_open:
App.closeDocument(doc.Label)
App.setActiveDocument(name)
App.ActiveDocument=App.getDocument(name)
for obj in App.ActiveDocument.Objects:
obj.touch()
App.ActiveDocument.recompute()
App.ActiveDocument.save()
_update_parts(filter(_is_a_part, FreeCAD.ActiveDocument.Objects), FreeCAD.ActiveDocument.Label)
For each of those parts, it's checked (and preserved), if they are already opened or must be opened. These parts are then opened/switched to (recursive), and done the same thing. After that all Objects are marked "dirty", the document gets recomputed, saved and then closed/switched.
After running this Macro it is required to use the reload function of the assembly2 bench to reload the parts.
Background:
For my small projects I like to be able to switch materials like they are availible, without having to hussle calculating new dimensions due to different thicknesses. Creating an Assembly file inside my project folder, with a spreadsheet next to the assembly provides me with that freedom, but updating the sub parts, which rely on the Assembly is a pain by hand.