Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everybody
I'm new to developing with Revit API, I have some requests where I need to detect when the user is drawing or edit a pipe. I have an approach using externalEventHandler to detect if there is new pipe; however, this is not working. this is my code
public class UpdatePipeSlopeHandler : IExternalEventHandler
{
public List<ElementId> ElementIdsToUpdate { get; set; } = new List<ElementId>();
public void Execute(UIApplication app)
{
try
{
Document doc = app.ActiveUIDocument.Document;
PipeHandler.HandlePipes(doc, ElementIdsToUpdate, "A pipe has been modified.");
}
catch (Exception ex)
{
TaskDialog.Show("Error", $"An error occurred: {ex.Message}");
}
}
public string GetName() => "Update Pipe Slope Handler";
}
///The principal class
[Transaction(TransactionMode.Manual)]
public class Class1 : IExternalApplication
{
private UIApplication _uiApp;
private UpdatePipeSlopeHandler _handler;
private ExternalEvent _externalEvent;
public Result OnStartup(UIControlledApplication application)
{
_handler = new UpdatePipeSlopeHandler();
_externalEvent = ExternalEvent.Create(_handler);
application.ControlledApplication.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);
return Result.Succeeded;
}
///documentChancge
private void OnDocumentChanged(object sender, Autodesk.Revit.DB.Events.DocumentChangedEventArgs e)
{
Document doc = e.GetDocument();
ICollection<ElementId> addedElementIds = e.GetAddedElementIds();
_handler.ElementIdsToUpdate = addedElementIds.ToList();
foreach (ElementId id in addedElementIds)
{
Element element = doc.GetElement(id);
if (element is Pipe)
{
TaskDialog.Show("raiseeven", "event raise");
_externalEvent.Raise();
}
}
}
As you can see i try to raise the externalEvenHandler when the user drawing new pipe and document change, the line 48 is executed however the externalevenHandler in this case (UpdatePipeSlopeHandler) never doesn't lunch.
Have you some ideas what Im missing or somethin wrong in my code.
Thank you for you help
Jose Loaiza
Solved! Go to Solution.