Public Function Execute(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result Implements IExternalCommand.Execute
Dim app As Autodesk.Revit.UI.UIApplication = commandData.Application
Dim uiDoc As UIDocument = app.ActiveUIDocument
Dim doc As Document = uiDoc.Document
Dim inLevel As ElementId
Dim collector As New FilteredElementCollector(doc)
Dim collection As ICollection(Of Element) = collector.OfClass(GetType(Level)).ToElements()
For Each e As Element In collection
Dim level As Level = TryCast(e, Level)
If level IsNot Nothing Then
If level.Name.Equals("Level 1") Then
inLevel = level.Id
End If
End If
Next
Using T As New Transaction(doc, "Make Stuff")
If T.Start() = TransactionStatus.Started Then
CreateWall(doc, inLevel)
' Ask the end user whether the changes are to be committed or not
Dim taskDialog__1 As New TaskDialog("Revit")
taskDialog__1.MainContent = "Click either [OK] to Commit, or [Cancel] to Roll back the transaction."
Dim buttons As TaskDialogCommonButtons = TaskDialogCommonButtons.Ok Or TaskDialogCommonButtons.Cancel
taskDialog__1.CommonButtons = buttons
If TaskDialogResult.Ok = taskDialog__1.Show() Then
' For many various reasons, a transaction may not be committed
' if the changes made during the transaction do not result a valid model.
' If committing a transaction fails or is canceled by the end user,
' the resulting status would be RolledBack instead of Committed.
If TransactionStatus.Committed <> T.Commit() Then
TaskDialog.Show("Failure", "Transaction could not be committed")
End If
Else
T.RollBack()
End If
End If
End Using
Return Autodesk.Revit.UI.Result.Succeeded
End Function
Here's the code in text 😅