Search code examples
revit-apirevit

Why I cant Select element in DockablePane when i use IExternalEventHandler


i want select element when i click button.i use IExternalEventHandler ,but i cant use

method: pickobject/pickobjects ,i change the method to pickPoint the hander run success.

event

public class ExecuteEvent : IExternalEventHandler
    {
        public string  ElementId { get; set; }
        public void Execute(UIApplication app)
        {
            UIDocument uidoc = app.ActiveUIDocument;
            Autodesk.Revit.DB.Document doc = uidoc.Document;
            Autodesk.Revit.UI.Selection.Selection sel = uidoc.Selection;
            Autodesk.Revit.DB.Reference re = sel.PickObject(Autodesk.Revit.UI.Selection.ObjectType.Element);
            Autodesk.Revit.DB.XYZ point = sel.PickPoint("select");
            ElementId = re.GetType().Name;




        }

        public string GetName()
        {
            return "ExecuteEvent";
        }
    }


hander

 Exc = new ExecuteEvent();
            ExternalHander = ExternalEvent.Create(Exc);

button click

private void Button_Click(object sender, RoutedEventArgs e)
        {
            ExternalHander.Raise();
            SetLabelText(Exc.ElementId);
        }

Solution

  • Apparently, the external event handler does not provide you with a valid user interface context. To get such a context, you might want to subscribe to the Idling event instead. That event is called when Revit has nothing else to do and hence is free to interact with the user.