Return Focus to View for Selection

Return Focus to View for Selection

Anonymous
Not applicable
800 Views
1 Reply
Message 1 of 2

Return Focus to View for Selection

Anonymous
Not applicable

I'm working on a plugin using CefSharp on Revit 2019.2.

I created a button that on-click should select an element from the 3DView that is open and then depending on that object continue executing some internal validations.

 

My issue is that the prompt for selecting the element appears but I'm not able to select anything unless I click on the actual view.

Revit1.png

 

After I click inside the view I'm able to select items and the correct prompt status messages appear.

Revit2.png

 

 

I tried a few different things....

  • I executed the RequestViewChange in the Iddling Event and it didn't change anything
  • I executed the RequestViewChange in the function before doing the selection the result was the same as before
  • I executed the RequestViewChange in the RequestHandler before calling my internal function and it did nothing
  • I tried changing the ActiveView (didn't expect it to work) and threw an InvalidOperationException

Isn't there a function to just change the focus to the view I already have active?

 

I've been struggling with this for the last couple of days and don't find a solution.

 

Thanks,

Julio

 

801 Views
1 Reply
Reply (1)
Message 2 of 2

Moustafa_K
Collaborator
Collaborator

hi,

I think you have a mod-less dialog that you contains the button you clicking to select multiple elements.

you need to hide your window, and bring the Revit window to front view, then start your selection.

 

so add the below snippet to your library (preferred) or the class you are working from.

[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);

public static void BringWindowtoFront(IntPtr hWnd)
		{
			// Change behavior by settings the wFlags params. See http://msdn.microsoft.com/en-us/library/ms633545(VS.85).aspx
			SetWindowPos(hWnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOACTIVATE);
		}

then you can call the above like this before you start selection

mywindow.Hide();
BringWindowtoFront(Autodesk.Windows.ComponentManager.ApplicationWindow); var selectedelements = m_uidoc.Selection.PickObjects(ObjectType.Edge, "Pick an many");

hope that helps

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
0 Likes