- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm facing a problem with the usage of UIView class.
There are several useful instance method in this class, and only 2 instance properties: IsValidObject & ViewID.
An instance must be got ahead of anything I want to do, so I packed the following lines into an extension method:
/// <summary> /// 获取 UIDocument 的 UIView,用于控制视图显示。 /// </summary> public static UIView ActiveUIView(this UIDocument uiDoc) { // var uiViews = uiDoc?.GetOpenUIViews(); return uiDoc?.GetOpenUIViews()?.FirstOrDefault(item => item.ViewId == uiDoc.ActiveView.Id); }
It looks good ... for now. I have some codes in an external command. In this command, I use an UIDocument instance which is provided by commandData, to get the CURRENT ACTIVE UIView.
But, If I click the project browser dock pane ahead of triggering my external command, like this:
You can see now the focus is at Project Browser pane, and my cursor is pointing at my own command PushButton, without clicking it(focus still at Project Browser). I Click my own command which calls the above mentioned method. It will return null. 😞
I'll show you the debugging status:
You can see the ActiveView property is an object of type View, but usually an meaningful view should be of Type View3D, ViewPlan, ViewSection, and so on.
It's name is "Project View", it has an ID that reads 230, but most element ID a programmer should be dealing with is an integer with six numbers.
And let's see more:
Title is "Project Browser", no ViewName (meaning less).
I do understand that the browser is also a View element in Revit. But under this circumstance (user click Project Browser ahead of triggering an external command), how can I still keep tracking THE view that the user want to work in ?
Think about this circumstance:
- There are 2 doc views opened, both of which are plan views
- Then he clicks Project Browser, which means focus now is at Project Browser pane
- Then he clicks an add-in command, which works in a plan view
- Now, how can I track WHICH plan view he wants to work in???
- Further thinking, if two plan views opened, for 2 different .rvt documents???
I was thinking that when DocumentOpened, a default view will be ALWAYS opened, But I cannot get UI Views, because DocumentOpened is an App level event.
I was also thinking about using Idling event, but it is still not strict enough. Because after opening a document, and before the user triggers any add-in command, I am not able to get a CommandData instance, which helps me tracking opened UIViews, or any other useful things.
Any solution or workaround for this? Within API, or with the help of some windows programming workaround?
thanks!
===============
Another small user story here:
When I was testing with Revit 2018.3, I found an interesting behavior.
If I click somewhere in the Property dock pane, the Property pane gets focused. Then if I move mouse cursor outside the pane, the FORMER view will gets focused immediately.
For example, I click Project Browser first; Second, I click Property pane; Then I move mouse cursor out from Properties pane, the Project Browser pane gets focused. This happens even if I move mouse cursor directly into an opened UI View. Where ever I move mouse, the former view gets focused.
If I click in a ViewPlan(commonly working view), the click Properties pane, then move out cursor, ViewPlan gets focused, because I can see the Properties pane flashed to update all properties, also, this movement triggers ExternalCommandAvailibility.Excute() method.
Like the above illustration, Focus stays in Properties pane. 🙂
A short user story, not quite big deal but interesting.
Solved! Go to Solution.