Unexpected behavior IExternalEventHandler - Revit API - C#

Unexpected behavior IExternalEventHandler - Revit API - C#

samuel.cailletMDQ7N
Enthusiast Enthusiast
1,129 Views
3 Replies
Message 1 of 4

Unexpected behavior IExternalEventHandler - Revit API - C#

samuel.cailletMDQ7N
Enthusiast
Enthusiast

Hello, I created a DockPanel panel to add buttons and therefore functions.

In one of the functions I want the user to click to choose a point.

 

First, here is the code for the panel

 

public partial class ManagerMainPage : Page, IDisposable, IDockablePaneProvider
    {
        Action myAction;
        ExternalEvent myActionExternalEvent;

        #region constructor
        public ManagerMainPage()
        {
            InitializeComponent();
            myAction = new Action();
            myActionExternalEvent = ExternalEvent.Create(myAction);
        }
        #endregion

        private void ListBoxItem_Action_Selected(object sender, RoutedEventArgs e)
        {
            myActionExternalEvent.Raise();
        }
    }

 

The code of my action 

 

public partial class ManagerMainPage
    {
        public class Action : IExternalEventHandler
        {
            public void Execute(UIApplication a)
            {
                UIDocument uidoc = a.ActiveUIDocument;
                Document doc = uidoc.Document;
                
                FamilySymbol FamilySymbol = null;

                using (Transaction t = new Transaction(doc, "PickPoint"))
                {
                    Plane plane = Plane.CreateByNormalAndOrigin(doc.ActiveView.ViewDirection, doc.ActiveView.Origin);

                    // create a sketch plane using Geometry.Plane
                    t.Start();
                    SketchPlane sp = SketchPlane.Create(doc, plane);
                    doc.ActiveView.SketchPlane = sp;
                    t.Commit();

                    //blocage ICI dans cette action de selection
                    XYZ point = uidoc.Selection.PickPoint("Please select point");

                    //DO SOMETHING
                }
                return;
            }

            public string GetName()
            {
                return "External Event Action";
            }
        }
    }

 

 When selecting a point, Revit freezes completely and displays at the bottom left "Ready" ...

2021-12-02_10h09_38.png

The strangest thing is that if I switch to another window (Windows) and go back to Revit + one click in the window, I can finally click to select the point ... (and the message "Please select a dot "is displayed instead of" Ready "... I do not understand the behavior of Revit in relation to this user action within an external control.

 

There is surely something that I do not control https://thebuildingcoder.typepad.com/files/external_events_knowledgebase.html

@jeremytammik  

 

I don't know if it's clear enough but any help would be welcome!

Thank you in advance 😊

 

I'm french please excuse the mistakes and clumsiness.

 

Cheers, Samuel Caillet

0 Likes
Accepted solutions (1)
1,130 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni
Accepted solution

If I were you, I would simply take (another?) close look at the Revit SDK samples ModelessDialog/ModelessForm_ExternalEvent and DockableDialogs/CS/ExternalEvents.  

 

They demonstrate all that you need, so why fight with an error when you can just grab the correct working code?

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

aa2827
Explorer
Explorer

Hi @jeremy_tammik  please, put the link.

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Search for Revit developer centre:

  

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open