Waiting for API Methods to end before continuing?

Waiting for API Methods to end before continuing?

tomerFUNPJ
Enthusiast Enthusiast
1,127 Views
2 Replies
Message 1 of 3

Waiting for API Methods to end before continuing?

tomerFUNPJ
Enthusiast
Enthusiast

Hello!

 

I have a problem which seems complicated to me, hope you can help 🙂

My goal is to create some views by duplicating existing views (using view.Duplicate()).

After creating the views I'm showing a 'report' window so that the user will know what happened.

This is all wrapped in an external event because it's being called from a UI I made.

 

Everything works fine, it's just that the report comes up before the views are finished being created. From what it seems, view.Duplicate returns the new ElementId immediately and only then creating the view..

So my first method that creates the views "Finishes" and then my report comes up. Although it came up - Revit is still busy creating my views.

 

It's important to me that the report will only be displayed after the views are done being created, because right now the users are getting a report with a still "frozen busy" Revit and have to wait for Revit to really end.

 

Thanks in advance!

0 Likes
Accepted solutions (1)
1,128 Views
2 Replies
Replies (2)
Message 2 of 3

jeremy_tammik
Alumni
Alumni
Accepted solution

This can probably easily be solved using the Idling event:

  

https://www.revitapidocs.com/2022/e233027b-ba8c-0bd1-37b7-93a066efa5a3.htm

  

It is raised when Revit has finished processing. 

  

You might be able to use it like this:

  

  • Your external command subscribes to a one-time call of the Idling event with an event handler H
  • Your external command launches Duplicate and stores a list of the future view element ids
  • Your external command terminates, returning control to Revit
  • Revit does whatever it likes for as long as it likes; be patient with it
  • Revit finishes doing its thing and raises the Idling event
  • H is called, and you can display the list you stored

 

You could also subscribe to the DocumentChanged event as well; that would enable you to capture a list of all newly added element ids; that list should be a superset of the future view element ids.

   

Your external command launches Duplicate and stores a list of the future view element ids.

 

For more on the Idling event, check out The Building Coder on modeless:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.28

  

 

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 3

tomerFUNPJ
Enthusiast
Enthusiast

That did it. Thank you!

0 Likes