ExternalEvent raised during DocumentChanged from a Paste operation does not execute

ExternalEvent raised during DocumentChanged from a Paste operation does not execute

boostyourbim
Advocate Advocate
814 Views
5 Replies
Message 1 of 6

ExternalEvent raised during DocumentChanged from a Paste operation does not execute

boostyourbim
Advocate
Advocate

In the sample code, ControlledApplication_DocumentChanged calls Raise() for each Id in GetAddedElementIds()

 

If you invoke the wall tool and click twice to create a straight wall, 1 element is added and Raise() is called once. When you end the Wall editor (hit ESC twice), the Raise code is executed. Everything is good.

 

If you copy/paste this wall (select it, CTRL-C, CTRL-V, click to place the new wall), then 4 elements are added and Raise() is called 4 times. Push ESC or Finish Paste to complete the Paste command. The Raise code is only executed one time. What happened to the other 3 calls to Raise()?

 

I have try/catch blocks around all the relevant code and there are no exceptions. The Raise code is only showing a Task Dialog (for debugging purposes).

 

Relevant code is in https://bitbucket.org/BoostYourBIM/boostyourbimterrifictools/src/master/BoostYourBIMTerrificTools/Ri... lines 130-151

0 Likes
815 Views
5 Replies
Replies (5)
Message 2 of 6

jeremytammik
Autodesk
Autodesk

Dear Harry,

 

Thank you for your report.

 

Can you extract the relevant code snippets and put them together into a minimal reproducible case that can be shared with and analysed by the development team?

 

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

 

Thank you!

 

Cheers,

 

Jeremy

 



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

0 Likes
Message 3 of 6

boostyourbim
Advocate
Advocate

@jeremytammik please see attached

0 Likes
Message 4 of 6

RPTHOMAS108
Mentor
Mentor

You may be able to find out what happened to the other three by checking result of:

Utils.testExternalEvent.Raise() if not already done so.

 

Each one should get a return of either: Accepted, Pending, Denied or TimedOut (with only 'Accepted' being a good result).

 

ExternalEventRequest Enum in RevitAPI.chm provides summary of these values. Perhaps sounds like a 'Pending' circumstance i.e. subsequent requests rejected if pending ones your event has already requested are still to be processed.

 

Moral of the tale may be to raise one event with an argument of four ids rather than raising one event for each item.

0 Likes
Message 5 of 6

boostyourbim
Advocate
Advocate

The first call to Raise() is "Accepted". Then the next 3 are "Pending". I will give a try to handling all 4 ids in a single Raise().

0 Likes
Message 6 of 6

RPTHOMAS108
Mentor
Mentor

Yes the 'Pending' terminology is a bit misleading because it could give the impression that it will eventually be executed and it will not. They should probably have named it 'DuplicateRejected' or something similar. I suppose however they are speaking of the state of the item that will be executed and that state being why the subsequent ones will not be.

 

Probably when you do copy and paste it is all happening almost instantaneously so Revit doesn't have the required time to get the first one done before the next arrives.

 

The best practice for ExternalEvent is in the name 'External' I guess i.e. not getting Revit to trigger itself (although I've been guilty of this too). I suspect the intention for the ExternalEvent was for it to be triggered by a human interaction or that of another program.

0 Likes