Run ExternalEvent when some element is selected.

Run ExternalEvent when some element is selected.

qoreodlf37
Enthusiast Enthusiast
222 Views
2 Replies
Message 1 of 3

Run ExternalEvent when some element is selected.

qoreodlf37
Enthusiast
Enthusiast

Hi.

 

I know that I should use ExternalEvent to do somthing with Transaction in window that opened by Show() not ShowDialog().

 

This is my sample code.

////This code is run in window by Show()
////externalEventHandeler is custom handler with ExternalEvent and IExternalEventHandler

externalEventHandeler.Event += (s, arg) => {
          //Do something with Transaction.
};
externalEventHandeler.Run();

 

It usually works well. But when element is selected, the event doesn't run. But the event run when I unselect element.

I searched and understand the reason is Revit UI thread holding 'Element select'.

 

I want to know run event withoue unselecting element.

How can I do? 

 

 

 

 

0 Likes
223 Views
2 Replies
Replies (2)
Message 2 of 3

scgq425
Advocate
Advocate

Hi @qoreodlf37 :

this error likely push by the thread changed and the external cant notify .

you can try this step : 

1. run code 

2. click revit main window and check that :select element 

3. also you can use this code to set window be revit child 

wpf :

 LoginWindow window = new LoginWindow();
            System.Windows.Interop.WindowInteropHelper mainUi = new System.Windows.Interop.WindowInteropHelper(window)
                {
                    Owner = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle
                };
            window.ShowDialog();

winform:

var uiView = uiDoc.GetOpenUIViews().First(x => x.ViewId == uiDoc.ActiveView.Id);
            var rec = uiView.GetWindowRectangle();
            var handler = new FindForm.ExecuteEventHandler();
            var externalEvent = ExternalEvent.Create(handler);
            var rvtPtr = Process.GetCurrentProcess().MainWindowHandle;
            FindForm ff = new FindForm(handler,externalEvent,new Point(rec.Left,rec.Top));
            ff.Show(new Command.WindowHandle(rvtPtr));

 public class WindowHandle : IWin32Window
        {
            private IntPtr _handle;

            public WindowHandle(IntPtr h)
            {
                Debug.Assert(IntPtr.Zero != h, "expected non-null window handle");
                LogUtility.Error("expected non-null window handle");
                _handle = h;
            }
            public IntPtr Handle => _handle;
        }

4. if this all null , using the idling + external to select element ,  make the thread to revit 

 

LanHui Xu 徐兰辉
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

Blog
LinkedIn
Revit/CAD Development | Steel Product Manager

EESignature

0 Likes
Message 3 of 3

ricaun
Advisor
Advisor

What do you mean by element is selected?

 

Are you selection a element and than click in a button to run the externalEventHandeler?

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes