The interface use for external command

IExternalCommand interface calling
IExternalCommand interface calling

The IExternalCommand Interface

  • To introduce your Revit plugin as an external command you have to use the "IExternalCommand" interface to your command class

  • Click on the implement interface to implement it

  • After implementing the external command interface it will be look like below snap

Execute method of IExternalCommand interface of Revit API
Execute method of IExternalCommand interface of Revit API
  • Whatever you want to perform, that logic shoould be now in this Execute method.

  • You can call method from another class inside this execute method to maintain code standard.

Write the body of the Execute method
Write the body of the Execute method
  • Let us see an exmaple of a external command which will show a text message "Hello World" which clicked.

Write<?xml version="1.0" encoding="utf-8"?>

<RevitAddIns>

<AddIn Type="Command">

<Name>CommandClass</Name>

<FullClassName>ClassLibrary1.MyTool</FullClassName>

<Text>CommandClass</Text>

<Description>My Tool</Description>

<VisibilityMode>AlwaysVisible</VisibilityMode>

<Assembly>C:\Users\CHAYAN\OneDrive\Desktop\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll</Assembly>

<AddInId>e726af91-fcd6-4a6c-ae30-114af22c602f</AddInId>

<VendorId>ADSK</VendorId>

<VendorDescription>Autodesk, Inc, www.autodesk.com</VendorDescription>

</AddIn>

</RevitAddIns> your text here...

  • Below is the corresponding example of the manifest file.

  • See the Bold lines.

  • The first one that is <FullClassName>Your namespace.Your class name</FullClassName>

  • The second highlighted entry is about the assembly location, means the location of your dll.

  • C:\Users\CHAYAN\OneDrive\Desktop\ClassLibrary1\ClassLibrary1\bin\Debug\ClassLibrary1.dll copy the dll location from the visual studio output section.

  • To get the dll and location you have to build the solution.

  • To Build just right click on the solution and choose Build option.

Load the tool in Revit

  • After opening the Revit a pop will come like below snap

  • Click on "Load once" to load the add ins.

Snap to describe how to load the Revit tool
Snap to describe how to load the Revit tool

[TransactionAttribute(TransactionMode.Manual)]

It means that the external command is responsible for managing database transactions explicitly. The command will need to start, commit, or roll back transactions as needed, rather than relying on automatic transaction management.

[RegenerationAttribute(RegenerationOption.Manual)]

This can be useful when the command needs to perform specific actions to regenerate parts of the application or data, rather than relying on automatic regeneration mechanisms.

Step to represent the build method for the solution
Step to represent the build method for the solution
Note :
This snaps represent how the Revit tools present in the external tool button
This snaps represent how the Revit tools present in the external tool button
The Hello World Text print under the external command
The Hello World Text print under the external command

Here is the output "Hello World" we got!!