Message 1 of 6
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am curious to know why my event keeps firing?
In my command I show how I am registering and unregistering.
My event keeps firing after the unregister, If I close the document the event stops. But I want to stop the event with a command in my current open document.
Thanks
// ----------------------------------------------------------------------------------------
// | Test Function Command |
// ----------------------------------------------------------------------------------------
[Transaction(TransactionMode.Manual)]
internal class Cmd_RefreshFreeSize : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiapp = commandData.Application;
Application app = commandData.Application.Application;
Document doc = commandData.Application.ActiveUIDocument.Document;
// To Register Event
commandData.Application.ViewActivated += new EventHandler<Autodesk.Revit.UI.Events.ViewActivatedEventArgs>(Assembly.OnViewActivated);
// To UnRegister Event
commandData.Application.ViewActivated -= Assembly.OnViewActivated;
return Result.Succeeded;
}
}
// ----------------------------------------------------------------------------------------
// | Function |
// ----------------------------------------------------------------------------------------
//
internal static class Assembly
{
internal static void OnViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
{
UIApplication uiapp = sender as UIApplication;
View view = uiapp.ActiveUIDocument.ActiveView;
if (view.IsAssemblyView)
{
Assembly.MessageBox(view.IsAssemblyView.ToString());
}
else
{
MessageBox("not an assembly");
}
}
// ----------------------------------------------------------------------------------------
// | Task Dialog |
// ----------------------------------------------------------------------------------------
//
internal static TaskDialogResult MessageBox(string str)
{
return TaskDialog.Show("Task", str);
}
// ----------------------------------------------------------------------------------------
internal static TaskDialogResult MessageBox(object obj)
{
return TaskDialog.Show("Task", $"{obj}");
}
// ----------------------------------------------------------------------------------------
}
Solved! Go to Solution.