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(); } }
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; } } } } }
/// <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; } } } }