Capturing Screenshot After Exploding a DWG/CAD

Capturing Screenshot After Exploding a DWG/CAD

structure1EKNKU
Enthusiast Enthusiast
414 Views
4 Replies
Message 1 of 5

Capturing Screenshot After Exploding a DWG/CAD

structure1EKNKU
Enthusiast
Enthusiast

Hi!

 

I need to capture a screenshot right after the user had exploded a DWG/CAD file.

 

What event should I subscribe to and under which conditions? I assume this should be an Idling event like described here:

 

Solved: How do I continue after postcommand? - Autodesk Community - Revit Products

 

and maybe to DocumentChanged event to read stuff from the data like described here:

 

Solved: How do I continue after PostCommand with its JournalData? - Autodesk Community - Revit Produ...

 

But I have no idea where should I bind this subscription (with creating group I subscribed to the events Idling and DocumentChanged in BeforeExecuted bound to PostableCommand.CreateGroup, here I see no equivalent to the latter).

0 Likes
415 Views
4 Replies
Replies (4)
Message 2 of 5

jeremy_tammik
Alumni
Alumni

I wonder whether you are seeing more complication than necessary.

  

Use of the Idling method is very simple and straightforward, actually. You subscribe to the event, providing the event handler. The event handler is called when appropriate. For a one-off call, such as in your case, presumably, you can unsubscribe from the event directly in the event handler itself. Nothing more than that.

  

So, in the Idling event handler, you could unsubscribe and also capture your screen snapshot. 

  

You con't mention how you want to capture it, so I can't suggest anything further. Will you be using the Windows API directly, some .NET library, something provided by the Revit API, or maybe a built-in Revit command?

  

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

structure1EKNKU
Enthusiast
Enthusiast

Yes, now I see I should have been more specific, thank you.

 

I want to write a plugin in C#. And my problem is not how to use the Idling event because I have already successfully done it with other commands, like CreateGroup.

 

Simplyfying, I have a code with the lines like following:

 

RevitCommandId revitCommandId = RevitCommandId.LookupPostableCommandId(PostableCommand.CreateGroup);

AddInCommandBinding commandBinding = uIControlledApplication.CreateAddInCommandBinding(revitCommandId);

commandBinding.BeforeExecuted += BindCommandEventBeforeExecuted;

 

In BindCommandEventBeforeExecuted I subscribe to the Idling event, assign another function to it, then I handle the event it and unsubscribe from it in this another function and it all works all right.

 

My question is: if I want to do the same with Exploding a DWG/CAD, how do I change the first line of the code snippet above?

Message 4 of 5

jeremy_tammik
Alumni
Alumni

Yes, indeed. looks like a different question. It seems that you are simply searching for the RevitCommandId of the built-in Revit command Explode DWG/CAD. I don't see the term 'explode' anywhere in the PostableCommand enumeration:

 

https://www.revitapidocs.com/2023/f6ccdc1b-6ac3-9c49-d0bb-8a7d1877eab0.htm

 

One effective place to look for Revit command ids is the journal file. Simply execute the desired explode command manually and look in the journal file what it logs. This approach was frequently used to determine the command ids to pass in to the PostCommand method:

  

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

  

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

jeremy_tammik
Alumni
Alumni

Well, seeing as use of the journal file is completely unsupported, I would say there is no guarantee of anything whatsoever. That is often the case in all customisation and programming areas, as far as I can tell. And even if documentation and guarantees are provided, I recommend not trusting them blindly, ever. I do believe that the chances are good enough for you to try it out, test it, and integrate it in you automated unit tests to ensure that whatever functionality you and your users rely on continues working as expected over time.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open