Dockable pane focus

Dockable pane focus

Anonymous
Not applicable
2,303 Views
4 Replies
Message 1 of 5

Dockable pane focus

Anonymous
Not applicable

Hi
I created a dockable pane with some functionality.

I need to automatically change focus on the model viewer when the panel disappears from the cursor field, as it is done in properties panel. 

When you do something on properties panel
and then moves the cursor to the model then the focus will also automatically change.
Can you help me, please.

0 Likes
Accepted solutions (1)
2,304 Views
4 Replies
Replies (4)
Message 2 of 5

jlpgy
Advocate
Advocate

Hi:

Suppose inside the dockable pane, you are using a WPF Page.

  1.  Subscribe the Page.MouseLeave
  2. // Add the following lines in you own Page class
    1. public partial class YourPage : Page
          {
              [DllImport("user32.dll")]
              [return: MarshalAs(UnmanagedType.Bool)]
              public static extern bool SetForegroundWindow(IntPtr hWnd);
      
              public IntPtr RevitWindowHandle { get; set; }
      
              void Page_MouseLeave (object sender, MouseEventArgs e)
              {
                    SetForegroundWindow (RevitWindowHandle);
              }

       

  3. About how to get the correct Revit window handle, Please refer the link: revit-window-handle-and-modeless-dialogues.html  . Notice that with Revit 2018 or ealier, you can also add reference AdWindows.dll inside the Revit program folder (C:\Program Files\Autodesk\Revit201X\), and use the Autodesk.Windows.ComponentManager.ApplicationWindow to grab Revit window pointer. In Revit 2019, it's much easier, Revit API provides a property: UIApplication.MainWindowHandle.
单身狗;代码狗;健身狗;[email protected]
0 Likes
Message 3 of 5

Anonymous
Not applicable

unfortunately it does not work
debugger coming in the method
and the SetForegroundWindow return true
but the focus is always on the panel
until I myself click on the mouse in the view

 

I get RevitWindowHandle from the commandData.Application.MainWindowHandle

0 Likes
Message 4 of 5

Revitalizer
Advisor
Advisor

Hi,


there is a related thread:

https://forums.autodesk.com/t5/revit-api-forum/click-on-dock-pane-deselects-elements/m-p/5279637


As you mention the Properties palette, in the SetupDockablePane method, you may assign EditorInteractionType.KeepAlive.


RevitAPI.chm says:

Keeps the active editor alive during pane activation. This results in the current selection being kept active and available to the pane. One example built-in dockable pane that uses this mode is the Revit Property Palette.

 

Revitalizer




Rudolf Honke
Software Developer
Mensch und Maschine





0 Likes
Message 5 of 5

jlpgy
Advocate
Advocate
Accepted solution

Great!

Thanks for sharing.

 

I re-tested the "SetForegroundWindow" solution again, and it TRULY did not work.

@AnonymousOOPs for giving you the wrong answer.

单身狗;代码狗;健身狗;[email protected]