TransactionGroupAssimilate Method

Assimilates all inner transactions by merging them into a single undo item.

Namespace: Autodesk.Revit.DB
Assembly: RevitAPI (in RevitAPI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntax
public TransactionStatus Assimilate()

Return Value

TransactionStatus
If finished successfully, this method returns TransactionStatus.Committed.
Exceptions
ExceptionCondition
InvalidOperationException The Transaction group has not been started (its status is not 'Started').. -or- The transaction's document is currently in failure mode. Transaction groups cannot be closed until failure handling is finished. You may use a transaction finalizer to close a group after the failure handling ends.
Remarks

After a successful assimilation the transaction group is committed.

All transactions committed inside this group will be merged into one single transaction. The resulting undo item will bear this group's name.

Assimilate can be called only when all inner transaction groups and transactions are finished, i.e. after they were either committed or rolled back.

Example
public void CompoundOperation(Autodesk.Revit.DB.Document document)
{
   // All and any transaction group should be enclosed in a 'using' block or guarded within 
   // a try-catch-finally blocks to guarantee that the group does not out-live its scope.
   using (TransactionGroup transGroup = new TransactionGroup(document, "Level and Grid"))
    {
       if (transGroup.Start() == TransactionStatus.Started)
       {
          // We are going to call two methods, each having its own local transaction.
          // For our compound operation to be considered successful, both the individual
          // transactions must succeed. If either one fails, we will roll our group back,
          // regardless of what transactions might have already been committed.

          if (CreateLevel(document, 25.0) && CreateGrid(document, new XYZ(0,0,0), new XYZ(10,0,0)))
          {
             // The process of assimilating will merge the two (or any number of) committed
             // transaction together and will assign the grid's name to the one resulting transaction,
             // which will become the only item from this compound operation appearing in the undo menu.
             transGroup.Assimilate();
          }
          else
          {
             // Since we could not successfully finish at least one of the individual
             // operation, we are going to roll the entire group back, which will
             // undo any transaction already committed while this group was open.
             transGroup.RollBack();
          }
       }
    }
}
See Also