private void PostErrorAndResolveInFaliuresProcessingEvent(Level level1) { //m_revitApp.FailuresProcessing += new EventHandler<Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing); Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent"); transaction.Start(); Line line = Line.CreateBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0)); Wall wall = Wall.Create(m_doc, line, level1.Id, false); m_doc.Regenerate(); FailureMessage fm = new FailureMessage(m_idError); FailureResolution fr = DeleteElements.Create(m_doc, wall.Id); fm.AddResolution(FailureResolutionType.DeleteElements, fr); m_doc.PostFailure(fm); transaction.Commit(); }
private void PostErrorAndResolveInFailuresProcessor(Level level1) { FailuresProcessor processor = new FailuresProcessor(); Application.RegisterFailuresProcessor(processor); Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessor"); transaction.Start(); Line line = Line.CreateBound(new XYZ(0, 20, 0), new XYZ(20, 20, 0)); Wall wall = Wall.Create(m_doc, line, level1.Id, false); m_doc.Regenerate(); FailureMessage fm = new FailureMessage(m_idError); FailureResolution fr = DeleteElements.Create(m_doc, wall.Id); fm.AddResolution(FailureResolutionType.DeleteElements, fr); m_doc.PostFailure(fm); transaction.Commit(); }
/// <summary> /// Implement this method as an external command for Revit. /// </summary> /// <param name="commandData">An object that is passed to the external application /// which contains data related to the command, /// such as the application object and active view.</param> /// <param name="message">A message that can be set by the external application /// which will be displayed if a failure or cancellation is returned by /// the external command.</param> /// <param name="elements">A set of elements to which the external application /// can add elements that are to be highlighted in case of failure or cancellation.</param> /// <returns>Return the status of the external command. /// A result of Succeeded means that the API external method functioned as expected. /// Cancelled can be used to signify that the user cancelled the external operation /// at some point. Failure should be returned if the application is unable to proceed with /// the operation.</returns> public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { m_revitApp = commandData.Application.Application; m_doc = commandData.Application.ActiveUIDocument.Document; Level level1 = GetLevel(); if (level1 == null) { throw new Exception("[ERROR] Failed to get level 1"); } try { // // Post a warning and resolve it in FailurePreproccessor try { Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor"); FailureHandlingOptions options = transaction.GetFailureHandlingOptions(); FailurePreproccessor preproccessor = new FailurePreproccessor(); options.SetFailuresPreprocessor(preproccessor); transaction.SetFailureHandlingOptions(options); transaction.Start(); FailureMessage fm = new FailureMessage(m_idWarning); m_doc.PostFailure(fm); transaction.Commit(); } catch (System.Exception) { message = "Failed to commit transaction Warning_FailurePreproccessor"; return(Result.Failed); } // // Dismiss the overlapped wall warning in FailurePreproccessor try { Transaction transaction = new Transaction(m_doc, "Warning_FailurePreproccessor_OverlappedWall"); FailureHandlingOptions options = transaction.GetFailureHandlingOptions(); FailurePreproccessor preproccessor = new FailurePreproccessor(); options.SetFailuresPreprocessor(preproccessor); transaction.SetFailureHandlingOptions(options); transaction.Start(); Line line = Line.CreateBound(new XYZ(-10, 0, 0), new XYZ(-20, 0, 0)); Wall wall1 = Wall.Create(m_doc, line, level1.Id, false); Wall wall2 = Wall.Create(m_doc, line, level1.Id, false); m_doc.Regenerate(); transaction.Commit(); } catch (System.Exception) { message = "Failed to commit transaction Warning_FailurePreproccessor_OverlappedWall"; return(Result.Failed); } // // Post an error and resolve it in FailuresProcessingEvent try { m_revitApp.FailuresProcessing += new EventHandler <Autodesk.Revit.DB.Events.FailuresProcessingEventArgs>(FailuresProcessing); Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessingEvent"); transaction.Start(); Line line = Line.CreateBound(new XYZ(0, 10, 0), new XYZ(20, 10, 0)); Wall wall = Wall.Create(m_doc, line, level1.Id, false); m_doc.Regenerate(); FailureMessage fm = new FailureMessage(m_idError); FailureResolution fr = DeleteElements.Create(m_doc, wall.Id); fm.AddResolution(FailureResolutionType.DeleteElements, fr); m_doc.PostFailure(fm); transaction.Commit(); } catch (System.Exception) { message = "Failed to commit transaction Error_FailuresProcessingEvent"; return(Result.Failed); } // // Post an error and resolve it in FailuresProcessor try { FailuresProcessor processor = new FailuresProcessor(); Application.RegisterFailuresProcessor(processor); Transaction transaction = new Transaction(m_doc, "Error_FailuresProcessor"); transaction.Start(); Line line = Line.CreateBound(new XYZ(0, 20, 0), new XYZ(20, 20, 0)); Wall wall = Wall.Create(m_doc, line, level1.Id, false); m_doc.Regenerate(); FailureMessage fm = new FailureMessage(m_idError); FailureResolution fr = DeleteElements.Create(m_doc, wall.Id); fm.AddResolution(FailureResolutionType.DeleteElements, fr); m_doc.PostFailure(fm); transaction.Commit(); } catch (System.Exception) { message = "Failed to commit transaction Error_FailuresProcessor"; return(Result.Failed); } } catch (Exception ex) { message = ex.Message; return(Result.Failed); } return(Result.Succeeded); }
private void ChangeButtonColors() { //powrót wszystkich przycisków do default AddVertex.ClearValue(BackgroundProperty); AddEdge.ClearValue(BackgroundProperty); DeleteElements.ClearValue(BackgroundProperty); MoveElements.ClearValue(BackgroundProperty); //zmiana koloru odpowiedniego przycisku oraz typu kursora nad poszczególnymi obiektami if (vertexFlag) { AddVertex.Background = Brushes.LightGreen; DrawSpace.Cursor = Cursors.Pen; foreach (var item in graph.Edges) { item.Cursor = Cursors.Arrow; } foreach (var item in graph.Vertices) { item.Cursor = Cursors.Arrow; } } if (edgeFlag) { AddEdge.Background = Brushes.LightGreen; DrawSpace.Cursor = Cursors.Arrow; foreach (var item in graph.Edges) { item.Cursor = Cursors.Arrow; } foreach (var item in graph.Vertices) { item.Cursor = Cursors.Hand; } } if (deleteFlag) { DeleteElements.Background = Brushes.LightGreen; DrawSpace.Cursor = Cursors.Arrow; foreach (var item in graph.Edges) { item.Cursor = Cursors.No; } foreach (var item in graph.Vertices) { item.Cursor = Cursors.No; } } if (moveFlag) { MoveElements.Background = Brushes.LightGreen; DrawSpace.Cursor = Cursors.Arrow; foreach (var item in graph.Edges) { item.Cursor = Cursors.Arrow; } foreach (var item in graph.Vertices) { item.Cursor = Cursors.SizeAll; } } }