IExternalCommand Interface |
An interface that should be implemented to provide the implementation for a Revit add-in External Command.
Namespace: Autodesk.Revit.UIAssembly: RevitAPIUI (in RevitAPIUI.dll) Version: 25.0.0.0 (25.0.0.0)
Syntaxpublic interface IExternalCommand
Public Interface IExternalCommand
public interface class IExternalCommand
type IExternalCommand = interface end
The IExternalCommand type exposes the following members.
Methods | Name | Description |
---|
 | Execute | Overload this method to implement and external command within Revit. |
Top
RemarksTo add an external command to Autodesk Revit the developer should implement an object
that supports the IExternalCommand interface.
Examplepublic Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData,
ref string message, ElementSet elements)
{
try
{
Document doc = commandData.Application.ActiveUIDocument.Document;
UIDocument uidoc = commandData.Application.ActiveUIDocument;
ICollection<Autodesk.Revit.DB.ElementId> ids =
doc.Delete(uidoc.Selection.GetElementIds());
TaskDialog taskDialog = new TaskDialog("Revit");
taskDialog.MainContent =
("Click Yes to return Succeeded. Selected members will be deleted.\n" +
"Click No to return Failed. Selected members will not be deleted.\n" +
"Click Cancel to return Cancelled. Selected members will not be deleted.");
TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Yes |
TaskDialogCommonButtons.No | TaskDialogCommonButtons.Cancel;
taskDialog.CommonButtons = buttons;
TaskDialogResult taskDialogResult = taskDialog.Show();
if (taskDialogResult == TaskDialogResult.Yes)
{
return Autodesk.Revit.UI.Result.Succeeded;
}
else if (taskDialogResult == TaskDialogResult.No)
{
ICollection<ElementId> selectedElementIds = uidoc.Selection.GetElementIds();
foreach (ElementId id in selectedElementIds)
{
elements.Insert( doc.GetElement(id) );
}
message = "Failed to delete selection.";
return Autodesk.Revit.UI.Result.Failed;
}
else
{
return Autodesk.Revit.UI.Result.Cancelled;
}
}
catch
{
message = "Unexpected Exception thrown.";
return Autodesk.Revit.UI.Result.Failed;
}
}
Public Function Execute(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Autodesk.Revit.UI.Result Implements IExternalCommand.Execute
Try
Dim doc As Document = commandData.Application.ActiveUIDocument.Document
Dim uidoc As UIDocument = commandData.Application.ActiveUIDocument
Dim ids As ICollection(Of Autodesk.Revit.DB.ElementId) = doc.Delete(uidoc.Selection.GetElementIds())
Dim taskDialog As New TaskDialog("Revit")
taskDialog.MainContent = ("Click Yes to return Succeeded. Selected members will be deleted." & vbLf & "Click No to return Failed. Selected members will not be deleted." & vbLf & "Click Cancel to return Cancelled. Selected members will not be deleted.")
Dim buttons As TaskDialogCommonButtons = TaskDialogCommonButtons.Yes Or TaskDialogCommonButtons.No Or TaskDialogCommonButtons.Cancel
taskDialog.CommonButtons = buttons
Dim taskDialogResult__1 As TaskDialogResult = taskDialog.Show()
If taskDialogResult__1 = TaskDialogResult.Yes Then
Return Autodesk.Revit.UI.Result.Succeeded
ElseIf taskDialogResult__1 = TaskDialogResult.No Then
Dim selectedElementIds As ICollection(Of ElementId) = uidoc.Selection.GetElementIds()
For Each id As ElementId In selectedElementIds
elements.Insert(doc.GetElement(id))
Next
message = "Failed to delete selection."
Return Autodesk.Revit.UI.Result.Failed
Else
Return Autodesk.Revit.UI.Result.Cancelled
End If
Catch
message = "Unexpected Exception thrown."
Return Autodesk.Revit.UI.Result.Failed
End Try
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also