DocumentOpened Event question

DocumentOpened Event question

PhillipM
Advocate Advocate
442 Views
3 Replies
Message 1 of 4

DocumentOpened Event question

PhillipM
Advocate
Advocate

HI Guys.

 

My api app subscribes to the DocumentOpened event to do some work at that point and works as expected.  This needs to happen for both project and family documents.  

 

The problem we are seeing though is a slowdown in the running of another api app that does a lot of opening and closing family documents in memory which our app does not need to be monitoring.

 

My question is there any way for us to tell in the DocumentOpened event if the document is visable in the UI or has just been opened in memory?

 

Cheers

 

Phillip

0 Likes
443 Views
3 Replies
Replies (3)
Message 2 of 4

Aaron.Lu
Autodesk
Autodesk

Dear,

 

I don't think there is a direct API to do that, maybe Document.ActiveView property is a workaround: if it is null then it might indicate the document is inactive. would you please have a try?

thanks.



Aaron Lu
Developer Technical Services
Autodesk Developer Network
0 Likes
Message 3 of 4

arnostlobel
Alumni
Alumni

I kind if disagree with the suggested workaround, though I must admit it may work, for documents opened via the API indeed do not have active views. However, what I do not like about the suggested approach is using the ActiveView property of the Document  class. Documents represents DB (model database) objects, which, technically, do not have active views at all - I mean, ever!  Active view can only be associated with a UIDocument. The fact that Document also has the ActiveView property as a legacy issue. We have been keeping it around for backward compatibility only and it will be removed in some future release.

 

That being said, I have not yet tried finding a "proper" solution (or workaround) for the problem in question. However, here is what I would try (and will try, if time permits):

 

  • I'd try to construct an UIDocument from the Document object I get in the event.
  • I'd expect the construction to fail with an exception. I am not sure if it is what actually happens, but if it does, it would be my solution.
  • If the creation of UIDocument does not throw, I'd then test either the ActiveView or VisibleViews on that acquired UI object. For documents that aren't visible those properties should have associated no data.
Arnošt Löbel
0 Likes
Message 4 of 4

PhillipM
Advocate
Advocate

Thanks guys for your suggestions.  I have a busy day today but will try these and report back my findings tomorrow.

 

Cheers

 

Phillip Miller

Kiwi Codes Solutions Ltd

0 Likes