SelectedChangedCommand.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /*-------------------------------------------------------------------------
  2. * 功能描述:SelectedChangedCommand
  3. * 作者:xulisong
  4. * 创建时间: 2019/5/31 16:03:04
  5. * 版本号:v1.0
  6. * -------------------------------------------------------------------------*/
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using Autodesk.Revit.UI.Events;
  13. using Autodesk.Revit.DB;
  14. using Autodesk.Revit.UI;
  15. namespace FWindSoft.Revit
  16. {
  17. public class SelectedChangedCommand: SingleIdingCommand
  18. {
  19. private HashSet<ElementId> m_OldIds;
  20. protected override void ApplicaionIdling(object sender, IdlingEventArgs e)
  21. {
  22. if (!Enable)
  23. {
  24. return;
  25. }
  26. var application = sender as UIApplication;
  27. var ids = application.ActiveUIDocument.Selection.GetElementIds();
  28. //if (ids.Count == 0)
  29. //{
  30. // return;
  31. //}
  32. if (m_OldIds == null || ids.Count != m_OldIds.Count || ids.Any(id => !m_OldIds.Contains(id)))
  33. {
  34. base.ApplicaionIdling(sender, e);
  35. m_OldIds = new HashSet<ElementId>(ids);
  36. }
  37. }
  38. }
  39. }