UIApplication.Idling event is not invoked when selecting special elements

UIApplication.Idling event is not invoked when selecting special elements

t.kuehn
Explorer Explorer
940 Views
3 Replies
Message 1 of 4

UIApplication.Idling event is not invoked when selecting special elements

t.kuehn
Explorer
Explorer

Hi,

I'm using the UIApplication.Idling event to track selection changes. This works very well. But in very rare cases the Idling event is never raised if a (special) element is selected.

 

Steps to reproduce the behavior (Revit 2017):

 

  1. load sample project "rme_advanced_sample_project.rvt"
  2. select one of the lighting
  3. the Idling event is not raised as long as the element is selected
  4. selecting another element, i.e. a ventilation element
  5. the Idling event is raised

 

A good indicator are the menu entries in the help menu. These entries are disabled if the Idling event is not raised (i.e. if a lighting is selected). The entries are enabled if another element is selected.

 

What's the reason for this behavior?

Is there another way to track the current selection?

 

Thank you!

 

Regards,

Thommy

0 Likes
941 Views
3 Replies
Replies (3)
Message 2 of 4

FAIR59
Advisor
Advisor

I don't know why this happens, but I can suggest an alternative:

 

In response to selection changes the Modify-Tab gets activated/updated. So you can track the current selection via the Autodesk.Windows.RibbonTab.Activated event.

 

using System;
using Autodesk.Revit.UI;
using adWin = Autodesk.Windows;

namespace FAIR_Space
{
    [Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
    public class ExternalApplication : IExternalApplication
    {
        static Autodesk.Revit.ApplicationServices.Application m_ServicesApplication;
        public Autodesk.Revit.UI.Result OnStartup(UIControlledApplication application)
        {
            application.ControlledApplication.ApplicationInitialized += ControlledApplication_ApplicationInitialized;
            return Result.Succeeded;
        }

        void ControlledApplication_ApplicationInitialized(object sender, Autodesk.Revit.DB.Events.ApplicationInitializedEventArgs e)
        {
            m_ServicesApplication = sender as Autodesk.Revit.ApplicationServices.Application;

            adWin.RibbonControl ribbon = adWin.ComponentManager.Ribbon;
            adWin.RibbonTab ModifyTab = null;
            foreach (var tab in ribbon.Tabs)
            {
                if (tab.Id == "Modify")
                {
                    ModifyTab = tab;
                    ModifyTab.Activated += ModifyTab_Activated;
                    ModifyTab.Deactivated += ModifyTab_Deactivated;
                }
            }
        }

       void ModifyTab_Deactivated(object sender, EventArgs e)
       {
           adWin.RibbonTab tab = sender as adWin.RibbonTab;
           if (tab == null) return;
           Autodesk.Revit.UI.UIApplication uiApp = new Autodesk.Revit.UI.UIApplication(m_ServicesApplication);
           Autodesk.Revit.UI.Selection.Selection sel =  uiApp.ActiveUIDocument.Selection;
           // your code goes here
       }

       void ModifyTab_Activated(object sender, EventArgs e)
       {
           adWin.RibbonTab tab = sender as adWin.RibbonTab;
           if (tab == null) return;
           Autodesk.Revit.UI.UIApplication uiApp = new Autodesk.Revit.UI.UIApplication(m_ServicesApplication);
           Autodesk.Revit.UI.Selection.Selection sel = uiApp.ActiveUIDocument.Selection;
           // your code goes here
       }

        public Autodesk.Revit.UI.Result OnShutdown(UIControlledApplication application)
        {
            return Result.Succeeded;
        }
    }
}

 

 

0 Likes
Message 3 of 4

thannaingoo.api
Advocate
Advocate

Dear @FAIR59;

 

Thanks for your code.

Please let me know, How should be done selection event in the same category?

 

Regards,

Naing Oo

 

 

 

 

0 Likes
Message 4 of 4

thannaingoo.api
Advocate
Advocate
0 Likes