Beispiel #1
0
        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();
                    }
                }
            }
        }
Beispiel #2
0
        public void CanCreateAndDeleteAReferencePoint()
        {
            using (var trans = new Transaction(RevitData.Document.Document, "CreateAndDeleteAreReferencePoint"))
            {
                trans.Start();

                FailureHandlingOptions fails = trans.GetFailureHandlingOptions();
                fails.SetClearAfterRollback(true);
                trans.SetFailureHandlingOptions(fails);

                ReferencePoint rp = dynRevitSettings.Doc.Document.FamilyCreate.NewReferencePoint(new XYZ());

                //make a filter for reference points.
                ElementClassFilter       ef  = new ElementClassFilter(typeof(ReferencePoint));
                FilteredElementCollector fec = new FilteredElementCollector(dynRevitSettings.Doc.Document);
                fec.WherePasses(ef);
                Assert.AreEqual(1, fec.ToElements().Count());

                RevitData.Document.Document.Delete(rp);
                trans.Commit();
            }
        }
Beispiel #3
0
        public void idleUpdate(object sender, Autodesk.Revit.UI.Events.IdlingEventArgs e)
        {
            e.SetRaiseWithoutDelay();

              UIApplication uiapp = sender as UIApplication;
              Document doc = uiapp.ActiveUIDocument.Document;
              UIDocument uidoc = uiapp.ActiveUIDocument;

              if (COVER.Instance.messageQueue.Count > 0)
              {
              using (Autodesk.Revit.DB.Transaction transaction = new Autodesk.Revit.DB.Transaction(doc))
              {
                  FailureHandlingOptions failOpt = transaction.GetFailureHandlingOptions();

                  failOpt.SetClearAfterRollback(true);
                  failOpt.SetFailuresPreprocessor( new NoWarningsAndErrors());
                  transaction.SetFailureHandlingOptions(failOpt);

                  if (transaction.Start("changeParameters") == Autodesk.Revit.DB.TransactionStatus.Started)
                  {
                      while (COVER.Instance.messageQueue.Count > 0)
                      {
                          COVERMessage m = COVER.Instance.messageQueue.Dequeue();
                          COVER.Instance.handleMessage(m.message, m.messageType,doc,uidoc);
                          if (Autodesk.Revit.DB.TransactionStatus.Committed != transaction.Commit())
                          {
                              // Autodesk.Revit.UI.TaskDialog.Show("Failure", "Transaction could not be committed");
                              //an error occured end resolution was cancled thus this change can't be committed.
                              // just ignore it and dont bug the user
                          }
                          return;
                      }
                  }
              }
              }
        }
Beispiel #4
0
            /// <summary>
            /// Execute method invoked by Revit via the 
            /// external event as a reaction to a call 
            /// to its Raise method.
            /// </summary>
            public void Execute(Autodesk.Revit.UI.UIApplication a)
            {
                // As far as I can tell, the external event
                  // should work fine even when switching between
                  // different documents. That, however, remains
                  // to be tested in more depth (or at all).

                  //Document doc = a.ActiveUIDocument.Document;

                  //Debug.Assert( doc.Title.Equals( _doc.Title ),
                  //  "oops ... different documents ... test this" );
                  UIDocument uidoc = a.ActiveUIDocument;
                  using (Autodesk.Revit.DB.Transaction transaction = new Autodesk.Revit.DB.Transaction(a.ActiveUIDocument.Document))
                  {
                  FailureHandlingOptions failOpt = transaction.GetFailureHandlingOptions();

                  failOpt.SetClearAfterRollback(true);
                  failOpt.SetFailuresPreprocessor(new NoWarningsAndErrors());
                  transaction.SetFailureHandlingOptions(failOpt);
                  if (transaction.Start("changeParameters") == Autodesk.Revit.DB.TransactionStatus.Started)
                  {
                      while (COVER.Instance.messageQueue.Count > 0)
                      {
                          COVERMessage m = COVER.Instance.messageQueue.Dequeue();
                          COVER.Instance.handleMessage(m.message, m.messageType, a.ActiveUIDocument.Document,uidoc);
                          if (Autodesk.Revit.DB.TransactionStatus.Committed != transaction.Commit())
                          {
                              // Autodesk.Revit.UI.TaskDialog.Show("Failure", "Transaction could not be committed");
                              //an error occured end resolution was cancled thus this change can't be committed.
                              // just ignore it and dont bug the user
                          }
                          return;
                      }
                  }
                  }
            }