I'm still learning python. Today it struck me, that python's with statement and transactions are friends.
Start with this:
Code: Select all
class Transaction(object):
def __init__(self, title, doc= None):
if doc is None:
doc = App.ActiveDocument
self.title = title
self.document = doc
def __enter__(self):
self.document.openTransaction(self.title)
def __exit__(self, exc_type, exc_value, exc_traceback):
if exc_value is None:
self.document.commitTransaction()
else:
self.document.abortTransaction()
Code: Select all
with Transaction("Create Cube"):
App.ActiveDocument.addObject("Part::Box")
Isn't it nice? Shouldn't we integrate this into FC?