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: 

ExternalEvent.Raise() don't execute immediately mothod "Excute"

12 REPLIES 12
Reply
Message 1 of 13
quangnhubk
1637 Views, 12 Replies

ExternalEvent.Raise() don't execute immediately mothod "Excute"

Hi everybody,

I have a problem, I call ExternalEvent.Raise() but it doesn't execute immediately method "Execute" in ExternalEventHandler. In fact, RelayCommand complete, then "Execute" in ExternalEventHandler execute. Is there any way call Raise () and then immediately execute method "Execute"? Thank you.A.PNGB.PNGC.PNG

 

12 REPLIES 12
Message 2 of 13
Moustafa_K
in reply to: quangnhubk

Hi,

Please have a look on this link, some useful information and things to consider while useing external events.

https://thebuildingcoder.typepad.com/blog/2013/12/triggering-immediate-external-event-execute.html

 

Hope that helps

 

 

Moustafa Khalil
Cropped-Sharp-Bim-500x125-Autodesk-1
Message 3 of 13
quangnhubk
in reply to: Moustafa_K

Thank you for your help. I followed the following tutorial link

https://thebuildingcoder.typepad.com/blog/2016/03/implementing-the-trackchangescloud-external-event....

, but the result of "Execute" still did not execute after Raise (). Please, helps me.

A.png

Message 4 of 13
jeremytammik
in reply to: quangnhubk

You ask: Is there any way call Raise and then immediately execute method Execute?

 

I would say the answer is No.

 

Cheers,

 

Jeremy

 



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

Message 5 of 13
quangnhubk
in reply to: Moustafa_K

I checked with a simple example like the image, the result is count = 0, not count = 1

AutoJoin.png

 

Message 6 of 13
quangnhubk
in reply to: jeremytammik

Thank Jeremy,

So, do you have a way to use transactions outside of IExternalCommand, which works in order?

Message 7 of 13
SamBerk
in reply to: jeremytammik

Hi @jeremytammik and @quangnhubk 

 

Here is how I solved it:

  • When the first command to open the window is executed, I save a reference to the UIApplication in a static class from the commandData 
  • And every time when I want to raise the event instead of using the event.Raise() I use eventHandler.Execute and I pass the UIApplication from the static class 
eventHandler.Execute(StaticClass.UIApplication)

        and it works successfully. 

 

@jeremytammik do you think this is a safe way to go?

 

 

Message 8 of 13
jeremytammik
in reply to: SamBerk

That sounds fine to me. Congratulations on solving it!

 



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

Message 9 of 13
SamBerk
in reply to: jeremytammik

Message 10 of 13
jeremytammik
in reply to: SamBerk

If it works reliably for you under all circumstances, then not, obviously.

 

Please let us know, and I can add a note to that old post pointing out that there is a better way.

 

Thank you!

 



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

Message 11 of 13
SamBerk
in reply to: jeremytammik

Hi @jeremytammik and @quangnhubk 

 

I realized that this is not a complete solution, because it only works with read-only events, but if you want to use a transaction in the event it will throw an exception that "Starting a transaction from an external application running outside of API context is not allowed", it only works with event.Raise().

 

But in fact, if you wanna do a read-only event, you don't need an IExternalEventHandler and call eventHandler.Execute() at all, you just need to save a reference to the UIApplication in a static field from the commandData when the first command to open the window is executed, and then you can use the UIApplication wherever in your code you want to read data from Revit.

 

Thanks

Message 12 of 13
jeremytammik
in reply to: SamBerk

You can also shoot yourself in the foot.

 

Making calls to the Revit API outside of a valid Revit API context can corrupt your data and crash Revit.

 

You cannot "use the UIApplication wherever in your code you want to read data from Revit".

 

You can only make calls from within a valid Revit API context:

 

http://thebuildingcoder.typepad.com/blog/2015/08/revit-api-context-and-form-creation-errors.html#2

 



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

Message 13 of 13
434977268
in reply to: quangnhubk

Hi,I want to ask if you have solved this problem now?

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

Post to forums  

Rail Community


Autodesk Design & Make Report