Run ExternalCommand from Dockable Pane Button without Registering in External Tools

Run ExternalCommand from Dockable Pane Button without Registering in External Tools

DesignGroup01
Enthusiast Enthusiast
333 Views
4 Replies
Message 1 of 5

Run ExternalCommand from Dockable Pane Button without Registering in External Tools

DesignGroup01
Enthusiast
Enthusiast

Hello All,

I have a dockable pane in my Revit add-in that contains a button. When this button is clicked, I want to execute a specific ExternalCommand. Currently, for the ExternalCommand to run, I have to register it in the AddInManifest. However, this also makes the command visible in the "External Tools" menu in Revit, which I do not want.

My requirements are:

  1. I want the ExternalCommand to run directly when clicking the button in the dockable pane.
  2. I do not want the ExternalCommand to be listed in the "External Tools" menu.
  3. If possible, I would prefer to avoid registering the command in the AddInManifest.

Is there a way to achieve this behavior in Revit API? Any guidance or best practices would be appreciated.

Thanks in advance!

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

jeremy_tammik
Autodesk
Autodesk

Yes. This can ba achieved using an external event. Please refer to the official ModelessDialog/ModelessForm_ExternalEvent Revit SDK sample. 

      

The dockable panel is modeless. Therefore, it lives outside the valid Revit API context. The external event enables you to switch from the modeless external context to a valid Revit API context in which external commands and other Revit API interaction can take place. 

   

Read all about it in The Building Coder topic group 5.28 on Idling and External Events for Modeless Access and Driving Revit from Outside:

  

  

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

DesignGroup01
Enthusiast
Enthusiast

Thank you for the information!

I understand that the dockable pane is modeless and exists outside of the valid Revit API context. The external event is used to switch between the modeless context and the Revit API context, allowing interactions with Revit via external commands.

My question is:

Can I show the dockable pane via a dialog launcher, and then trigger an external command from within the dockable pane (using a button inside the pane) without manually registering the command? Essentially, I would like to run the external command from the dockable pane, but avoid the need for the usual registration process that is required for external commands. Is this achievable through the Revit API?

Thank you!

0 Likes
Message 4 of 5

jeremy_tammik
Autodesk
Autodesk

Basically, yes, absolutely. Whether the command is listed in external tools menu or not depends on whether it is listed in the add-in manifest file *.addin. You may happily implement an external command in your add in and not list it in the add-in manifest. Then it can be launched by other means and is not seen by the user. Basically, an external event handler and an external command Execute method are completely equivalent. They both (and others) are simply Revit API event handler called by Revit under certain circumstances and equipped with a valid Revit API context when called.

   

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

DesignGroup01
Enthusiast
Enthusiast

"Yes, you're absolutely right! The ability to list an external command in the external tools menu depends on whether it's included in the add-in manifest file (*.addin). However, it's completely possible to implement an external command without listing it in the manifest file. When done this way, it won't be visible to the user, but can still be triggered by other means.

Regarding the event handler issue, an ExternalEventHandler and an ExternalCommand.Execute method serve similar purposes in the Revit API. Both are event handlers that Revit calls under specific conditions and come with a valid Revit API context. The main difference lies in how and when they are invoked. For example, the ExternalEventHandler is ideal for more asynchronous operations or interactions within the Revit environment, especially when you need to handle multiple operations concurrently or via UI elements like WPF forms.

In your case, the transaction issue when using an event handler could stem from how the Revit context is being accessed. Make sure you're properly managing the transaction scope and context when switching from the ExternalCommand to ExternalEventHandler."

Let me know if you need more adjustments to this!

0 Likes