Bring focus to graphical view

Bring focus to graphical view

j.buijs
Enthusiast Enthusiast
1,340 Views
5 Replies
Message 1 of 6

Bring focus to graphical view

j.buijs
Enthusiast
Enthusiast

Hello,

 

This question is very similar to this one from 2015.

I was hoping there would be a solution to this problem by now.

The problem is gone in Revit 2019 as Autodesk seems to have changed the way dockable panes behave, but it's still there in previous version which my company still uses.

 

The problem is that I have a dockable pane that users can use to place families in their project.

This all works seamlessly now, but there is one thing that I get annoyed about and that's when people click in the pane but don't place anything in their project. If they do so, the dockable pane is focused and they can't click anything on the ribbon until they click in the main graphical window first. I want to set focus to that view myself by code but I can't seem to get it working.

 

I tried to use the P/Invoke SetForegroundWindow function with both the Process.GetCurrentProcess().MainWindowHandle and the handle for the graphical view itself.

 

Also I tried to set the uidoc.ActiveView to the same view that is open but that doesn't do anything.

It does work if you open a new view but that's not what I want to do. And opening a new view and switching back works but looks stupid (user can see it, it's not instant).

 

Is there something else I can try? Maybe some way to 'unfocus' my dockable pane?

1,341 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

OpenAndActivateDocument?

 

https://apidocs.co/apps/revit/2019/5018fbdb-e7c3-6e32-7ca3-ee5c20dbc56f.htm

 

Zoom to an element?

 

http://thebuildingcoder.typepad.com/blog/2018/03/switch-view-or-document-by-showing-elements.html

 

Looking forward to hearing how you end up solving this.

 

Good luck!

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 6

j.buijs
Enthusiast
Enthusiast

Hey Jeremy,

 

Both those solutions don't do the trick.

In case of the zoom to element, if there is nothing selected it won't work.

I also tried to zoom the UIView with different methods but that just zooms it without activating it.

 

As for the OpenAndActivateDocument, I tried the following external event to activate it.

Don't know if this was the way you meant it, but it doesn't work this way.

 

public class ActivateMainWindowEvent : IExternalEventHandler
{
        public void Execute(UIApplication uiapp)
	{
            if (uiapp != null)
            {
                string path = uiapp.ActiveUIDocument.Document.PathName;
                if (path != "")
                    uiapp.OpenAndActivateDocument(path);
            }
        }

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

I think Revit recognizes that it already has this document active and does nothing because of that.

 

0 Likes
Message 4 of 6

jeremytammik
Autodesk
Autodesk

Oh dear, very sorry to hear that.

 

I hope someone else has a better suggestion, then.

 

Good luck!

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 5 of 6

j.buijs
Enthusiast
Enthusiast

It seems like nobody else knows a solution. Too bad.

Good thing is that it's not a problem in R2019 anymore, but some of our partners still insist on using R2017 or R2018 so it will still annoy me for some time unfortunately.

0 Likes
Message 6 of 6

ahmadeltobshy
Contributor
Contributor

in Revit 2022 I still have the same issue as i have a button on a dock-able pane the make the user select an object from the model but the cursor doesn't change and elements don't get hovered until i click once in the main graphical area to make things work fine. I have also tried the same technique using SetForegroundWindow Function but it makes the whole main window of Revit itself focused which already is.