2025-12-28 11:47:54 +08:00
|
|
|
|
using Autodesk.Revit.UI;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
using Autodesk.Revit.UI.Events;
|
|
|
|
|
|
|
|
|
|
|
|
namespace ShrlAlgoToolkit.Revit.Assists
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// UiApplication.PostCommand 结束事件监视器
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
///<example>
|
|
|
|
|
|
/// <c>RevitCommandEndedMonitor revitCommandEndedMonitor = new RevitCommandEndedMonitor(UiApplication);
|
|
|
|
|
|
/// revitCommandEndedMonitor.CommandEnded += OnCommandEnded;
|
|
|
|
|
|
/// var command = RevitCommandId.LookupPostableCommandId(PostableCommand.TypeProperties);
|
|
|
|
|
|
/// UiApplication.PostCommand(command);</c>
|
|
|
|
|
|
/// </example>
|
2025-12-28 11:47:54 +08:00
|
|
|
|
public class RevitCommandEndedMonitor
|
2025-07-11 09:20:23 +08:00
|
|
|
|
{
|
2025-12-28 11:47:54 +08:00
|
|
|
|
private readonly UIApplication revitUiApplication;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
|
2025-12-28 11:47:54 +08:00
|
|
|
|
private bool initializingCommandMonitor;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
|
|
|
|
|
|
public event EventHandler CommandEnded;
|
|
|
|
|
|
|
2025-12-28 11:47:54 +08:00
|
|
|
|
public RevitCommandEndedMonitor(UIApplication uIApplication)
|
2025-07-11 09:20:23 +08:00
|
|
|
|
{
|
2025-12-28 11:47:54 +08:00
|
|
|
|
revitUiApplication = uIApplication;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
|
2025-12-28 11:47:54 +08:00
|
|
|
|
initializingCommandMonitor = true;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
|
2025-12-28 11:47:54 +08:00
|
|
|
|
revitUiApplication.Idling += OnRevitUiApplicationIdling;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnRevitUiApplicationIdling(object sender, IdlingEventArgs idlingEventArgs)
|
|
|
|
|
|
{
|
2025-12-28 11:47:54 +08:00
|
|
|
|
if (initializingCommandMonitor)
|
2025-07-11 09:20:23 +08:00
|
|
|
|
{
|
2025-12-28 11:47:54 +08:00
|
|
|
|
initializingCommandMonitor = false;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-28 11:47:54 +08:00
|
|
|
|
revitUiApplication.Idling -= OnRevitUiApplicationIdling;
|
2025-07-11 09:20:23 +08:00
|
|
|
|
|
|
|
|
|
|
OnCommandEnded();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnCommandEnded()
|
|
|
|
|
|
{
|
|
|
|
|
|
CommandEnded?.Invoke(this, EventArgs.Empty);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|