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
NhuTruong_BeyCons
1695 Views, 12 Replies

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

NhuTruong_BeyCons
Contributor
Contributor

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

 

0 Likes

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
Collaborator
Collaborator

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
0 Likes

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

NhuTruong_BeyCons
Contributor
Contributor

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

0 Likes

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
Autodesk
Autodesk

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

0 Likes

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

NhuTruong_BeyCons
Contributor
Contributor

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

AutoJoin.png

 

0 Likes

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

AutoJoin.png

 

Message 6 of 13

NhuTruong_BeyCons
Contributor
Contributor

Thank Jeremy,

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

0 Likes

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

SamBerk
Advocate
Advocate

Hi @jeremytammik and @NhuTruong_BeyCons 

 

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?

 

 

0 Likes

Hi @jeremytammik and @NhuTruong_BeyCons 

 

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

jeremytammik
Autodesk
Autodesk

That sounds fine to me. Congratulations on solving it!

 



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

0 Likes

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

SamBerk
Advocate
Advocate
0 Likes

Message 10 of 13
jeremytammik
in reply to: SamBerk

jeremytammik
Autodesk
Autodesk

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

0 Likes

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

SamBerk
Advocate
Advocate

Hi @jeremytammik and @NhuTruong_BeyCons 

 

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

0 Likes

Hi @jeremytammik and @NhuTruong_BeyCons 

 

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

jeremytammik
Autodesk
Autodesk

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

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
Participant
Participant

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

0 Likes

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  

Autodesk Design & Make Report