How do I continue after PostCommand with its JournalData?

How do I continue after PostCommand with its JournalData?

structure1EKNKU
Enthusiast Enthusiast
375 Views
4 Replies
Message 1 of 5

How do I continue after PostCommand with its JournalData?

structure1EKNKU
Enthusiast
Enthusiast

Hi!

 

I need to read the JournalData written by the PostCommand without interrupting it right after it ends executing.

 

I am familiar with this topic: Solved: Re: How do I continue after postcommand? - Autodesk Community - Revit Products

 

However, it only allows me continuing after the command and access those of the EventArgs I've copied from the BeforeExceutedEventArgs handler (a question aside: how can I easily copy this object and not only create a reference to it, so that I could hold it in a variable accessible long after the event execution is gone?). What I need is an access to the ExecutedEventArgs object which I would have received by the handler assigned to AddInCommandBinding.Executed without this assignment because it causes executing my function instead of the actual command while I need something to be executed after it but using its execution data.

 

Long story short: I need an upgrade of ricaun's solution so that its line 62 contains an object of an ExecutedEventArgs class instead of EventArgs.Empty but all the crude attempts seem to fail.

0 Likes
Accepted solutions (1)
376 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

Tricky to answer, not being ricaun myself. However, please be aware that PostCommand adds things for Revit to do in a queue. When Revit has finished processing the queue, it will call the Idling event, if you have subscribed to that. That would enable you to proceed with your next step, which might include adding another call to PostCommand or some other action:

  

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 5

structure1EKNKU
Enthusiast
Enthusiast

But what kind of action could I possibly do to get what I need? If I subscribe to and unsubscribe from the IdlingEvent correctly I am able to handle the fact that Revit had finished processing the PostCommand queue once and only once if I need to. And okay, this looks a good moment to look at the journal and collect some data, preferably without the need of myself manually filtering which ones are related with the just ended PostCommand.

 

But how do I access it? I can't bind AddInCommandBinding.Executed to avoid interrupting the original command (let's so far assume that I want to work with the built-in command which collects some data, for example right after  executing PostableCommand.CreateGroup I want to know the name assigned by the user to the newly created group) so where can I catch the ExecutedEventArgs object or where else can I access the journal data Dictionary?

0 Likes
Message 4 of 5

jeremy_tammik
Alumni
Alumni
Accepted solution

You can subscribe to the DocumentChanged event before calling PostCommand, and unsubscribe from it afterwards, e.g., in the Idling event handler. That gives you access to all new and modified elements, so you can grab the modified name from those:

 

https://www.revitapidocs.com/2023/f7acc5b4-a1b4-12ca-802b-0ee78942589e.htm

 

Here are some related articles from The Building Coder:

 

 

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

structure1EKNKU
Enthusiast
Enthusiast

Thanks!

0 Likes