FreeCAD Document Transaction System Explained
The FreeCAD document transaction system is an underlying architectural mechanism designed to track and manage state changes within a project, primarily powering reliable undo and redo functionality while preserving model integrity. By grouping parametric modifications, object creations, and property edits into discrete units of work, this system prevents data corruption, facilitates predictable script automation, and provides fail-safe rollback capabilities whenever modeling operations fail.
Reliable Undo and Redo Management
The primary user-facing purpose of the transaction system is to provide robust undo and redo capabilities. FreeCAD projects rely on complex, interdependent parametric dependency graphs. Modifying a single feature often alters multiple downstream objects. The transaction system records state differences as a unified event rather than isolated property updates. When a user invokes an undo command, FreeCAD reverses the entire batch of associated changes simultaneously, restoring the dependency tree to its exact prior state without leaving orphaned references or broken dependencies.
Document Integrity and Atomic Operations
In 3D CAD workflows, an operation such as a boolean cut, fillet, or loft can fail midway due to invalid geometry or algorithmic errors. The transaction system enforces atomicity—often referred to as an "all-or-nothing" approach. If an operation encounters an error during execution, the transaction can be aborted. Aborting a transaction automatically rolls the document back to the state it was in before the operation began, preventing the file from settling into an unstable, partially computed, or corrupted state.
Scripting and Macro Control
For developers and users writing Python scripts, the transaction
system provides explicit programmatic boundaries. Through methods like
openTransaction(), commitTransaction(), and
abortTransaction(), scripts can wrap multi-step procedures
into a single operation. When a complex script finishes, the user can
undo the entire script execution with a single keystroke, rather than
having to manually step back through dozens of individual object
creation steps.
Performance and Recomputation Optimization
Beyond tracking changes, transactions help streamline performance. Constantly updating the 3D view and recomputing the document graph for every individual property change creates significant computational overhead. By encapsulating related modifications inside a transaction, FreeCAD can defer costly recomputations and visual refreshes until the transaction is committed, ensuring smoother performance during intensive modeling tasks.