Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switching active documents is not allowed during API event handling

11 REPLIES 11
SOLVED
Reply
Message 1 of 12
Anonymous
4020 Views, 11 Replies

Switching active documents is not allowed during API event handling

This really self explaing exception is thrown when i try to do an Application.OpenandActivateDocument, the second time (when i have no active documents it works),
The point is the event i'm trying to do this from, is: application.Idling ...
I really expected to be allowed from there do do that.

11 REPLIES 11
Message 2 of 12
jeremytammik
in reply to: Anonymous

Dear Luigi,

 

Does this help in any way?

 

http://thebuildingcoder.typepad.com/blog/2012/12/closing-the-active-document.html

 

Cheers,

 

Jeremy



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

Message 3 of 12
Anonymous
in reply to: jeremytammik

Hello Jeremy i went through your blog thorougly before posting and that article has been read.

I tried to close the document but i get another error, i think process start can help, but i dislike that option since i don't get any reference to the document ... (maybe i can get throug open documents and find the one with that filename ...
First cal works from second on it doesn't

I made a solution to investigate the problem with the comunity:

https://github.com/LiFeleSs/RevitOpenAndActivateDuringIdle

 

ALSO i can't access this forum using google chrome anymore

Message 4 of 12
Anonymous
in reply to: jeremytammik

I've implemented the process start workaround and found a way to realiably get the opened document, unfortunately not the UiDocument.
I still think this should be considered a bug in revit API...

Message 5 of 12
arnostlobel
in reply to: Anonymous

Naturally, I have to step in, for I do not like Jeremy’s suggested solution all that much (and he knows it 🙂

Although opening a new active document is not allowed from event handlers when there already is a document open in Revit, there may be an alternative. I believe we have implemented External Events so they do not share this restriction with events. Thus, for the user who otherwise used the Idling event, switching to an External Event could be a suitable solution. And it is both supported and safe.

 

Thank you

Arnošt Löbel
Message 6 of 12
arnostlobel
in reply to: Anonymous

Luigi,

You’ve posted seconds before me.
Of course, opening a DB document has no restrictions. You should be always able to do it in virtually any situations.
Arnošt Löbel
Message 7 of 12
Anonymous
in reply to: arnostlobel

*Opens the chm* *search for it ...* Tnx!
Message 8 of 12
arnostlobel
in reply to: Anonymous

I am not sure what your last comment means, but, yes, I guess.
If you are referring to finding some help for using External Event, I recommend searching through the samples in the SDK. There is at least one.

Arnošt Löbel
Message 9 of 12
Anonymous
in reply to: arnostlobel

Oh that is a bad habit from when i used to just write on forums for fun, not for relevant things, putting an action between asterisks means i'm actually doing that actions ...

I've found an axample about that on Jeremy blog, my source for inspiration (thanks Jeremy) and updated my solution to not use the idling event but to raise my shiny new external event, and it works like a charm!
I didn't realized external events purpose, i thougth it was a way to leverage idling handling ...
So! thanks for pointing me in the right direction!

Arnost there is some other aspects of the API i'd like to discuss (like button availability) is this the right place ?

 

P.s. i've updated the git hub repository, if you want to include it in the samples ...

Message 10 of 12
jeremytammik
in reply to: Anonymous

Dear Luigi,

 

Congratulations on resolving your problem, and thank you for sharing the result.

 

I would love to share your sample with the rest of the Revit add-in developer community...

 

Could you be a bit more specific about what it actually demonstrates and how, now that all the issues you were encountering are resolved and you are clear about the use of external events?

 

Thank you!

 

Cheers,

 

Jeremy



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

Message 11 of 12
arnostlobel
in reply to: jeremytammik

Helllo Luigi,

 

I suggest you take Jeremy's offer for possibly sharing your sample on his blog. That is the right platform for showing custom samples. Here at Revit R&D we can only use SDK samples we develop ourselves, becasue we need to include them as part of our builds to ensure their build-ability (if that is a word.)

 

As for your question, this forum is totally the right place for your posting questions about button ability etc., assuming your question is about the progamming aspect of such a task. Naturally, not all questions get always answered - after all this is still but a peer-to-peer forum. Most questions do get aswered, however,  and we (at Revit R&D) do pay atttention to all posts even when we do not directly participate.

 

Thank you

Arnošt Löbel
Message 12 of 12
Anonymous
in reply to: arnostlobel

Very good! you can share my example as long as you want, in fact is publicily available on gitHub.
The last version of it demostrate how using an ExternalEvent solve getting the "Switching active documents is not allowed during API event handling" exception trying to open a document (or more than one) during a call from a command or an event such the idling.
And also it demostrate how to declare and call the external event.

 

the previous versions could be also quite usefull to some revit users because it shows how to get a task executed during the idling event. but need some arrangement because it was built to demonstrate the other issue.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report