Document.ActiveView is null

Document.ActiveView is null

Anonymous
Not applicable
2,239 Views
5 Replies
Message 1 of 6

Document.ActiveView is null

Anonymous
Not applicable

Hi,

 

My problem is describe in the title.

I need to get only visible catagories in my external command, I can edit that in the panel "Visibility / Graphic Override for 3D View".

But to get this information I need a View. The only one I have is the Document.ActiveView but it is null.

 

Do somebody know how to know if a category is hidden ? or how to get this default 3d view ?

Thanks a lot.

0 Likes
Accepted solutions (1)
2,240 Views
5 Replies
Replies (5)
Message 2 of 6

ollikat
Collaborator
Collaborator

Think it's quite odd that your ActiveView is null...API documentation says this:

 

"The active view is the view that last had focus in the UI. Null reference (Nothing in Visual Basic) if no view is considered active."

 

But shouldn't this be quite rare...?

 

Anyway, you can get all views with ElementClassFilter. After you have the correct view, you can use View::getVisibility(), as you propably have noticed.

 

0 Likes
Message 3 of 6

Anonymous
Not applicable
Accepted solution

Hi ollikat,

 

Thanks for your help. Actually I try your idea to get all view with the ElementClassFilter, and in the collection I found the one I want, so I decide to debug when I lost this Document.Active.

 

And the reason is when I try to access it, the execution is in a BackgoundWorker...

Mystery is resolved, thank you again.

0 Likes
Message 4 of 6

arnostlobel
Alumni
Alumni

May I ask you what you meant by "the execution is in a BackgroudWorker"? Is it your background worker or someone else's? And one more question: From what place in your application you tried to access the UIDocument.ActiveView property when it returned NULL? I assume it was from not from an external command (not directly, anyway). Can you confirm that?

Thank you

Arnošt Löbel

Arnošt Löbel
0 Likes
Message 5 of 6

Anonymous
Not applicable

Hi Arnost,

 

I mean I used BackgroundWorker from System.dll for a long process.

And I accessed UIDocument.ActiveView from this class, who was created from an external command.

 

Hope those precisions help you.

0 Likes
Message 6 of 6

arnostlobel
Alumni
Alumni

Hello NGOC:

 

Calling the Revit API from other than the main thread is prohibited. Your application is supposed to finish all calls while it is still in the external command (or event, or updater, etc.). You can start a working thread from the command, but if you do, you cannot call the API back from that thread. Such calls have unexpected behavior and could (and as likely as not they would) cause Revit to throw exceptions.

 

Arnošt Löbel

Arnošt Löbel
0 Likes