Start an ExternalEvent on interaction within docked WPF form

Start an ExternalEvent on interaction within docked WPF form

Anonymous
Not applicable
789 Views
1 Reply
Message 1 of 2

Start an ExternalEvent on interaction within docked WPF form

Anonymous
Not applicable

I intend to create an ExternalEvent when the user clicks on a button within a docked WPF form within revit. But, revit throws an error:

 

Autodesk.Revit.Exceptions.InvalidOperationException: 'Attempting to create an ExternalEvent outside of a standard API execution'

 

I have used the same method to start ExternalEvents from a modless windows form previously and it worked.

 

Here is the code:

 

public partial class Page1 : Page
    {
        public Page1()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            //NavigationService.Navigate(new Page2());
            ExternalEventHandlerGetSelection ex = new ExternalEventHandlerGetSelection();
            ExternalEvent exev = ExternalEvent.Create(ex);
            exev.Raise();       
        }
    }

 

 

0 Likes
Accepted solutions (1)
790 Views
1 Reply
Reply (1)
Message 2 of 2

swfaust
Advocate
Advocate
Accepted solution

I believe you have to be in a valid API context to actually register the event.  That would mean that Revit has to have handed you control via an external command or application.  Once the event is registered you can raise it from anywhere you like.  So you would need to register your event prior to showing your dialog in whatever context you first show it, or in the application startup method on an external application.  Then you can call the Raise() event from the dialog code to actually make Revit call your handler.