// Step 1. protected override void BeforeSolveInstance() { if (TransactionalStrategy != TransactionStrategy.PerComponent) { return; } BeginTransaction(Revit.ActiveDBDocument); OnAfterStart(Revit.ActiveDBDocument, CurrentTransaction.GetName()); }
protected void CommitTransaction(DB.Document doc, DB.Transaction transaction) { var options = transaction.GetFailureHandlingOptions(); #if !DEBUG options = options.SetClearAfterRollback(true); #endif options = options.SetDelayedMiniWarnings(true); options = options.SetForcedModalHandling(true); options = options.SetFailuresPreprocessor(this); options = options.SetTransactionFinalizer(this); // Disable Rhino UI if any warning-error dialog popup { External.EditScope editScope = null; EventHandler <DialogBoxShowingEventArgs> _ = null; try { Revit.ApplicationUI.DialogBoxShowing += _ = (sender, args) => { if (editScope is null) { editScope = new External.EditScope(); } }; if (transaction.GetStatus() == DB.TransactionStatus.Started) { OnBeforeCommit(doc, transaction.GetName()); transaction.Commit(options); } else { transaction.RollBack(options); } } finally { Revit.ApplicationUI.DialogBoxShowing -= _; if (editScope is IDisposable disposable) { disposable.Dispose(); } } } }