<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/dbdc83d9-6863-4e22-859f-a6426cd47d5c/alert.png" width="40px" /> Take a look at the Create Your First Command for information about setting up your first extension. This article explains how to create a .NET script in pyRevit. The rest is the same.
</aside>
pyRevit supports C# or VB.Net for .NET bundles. Create a .cs
or .vb
script inside your bundle. The .NET bundles are a bit more strict so a little scaffolding is necessary to make the script work.
Specifically, we need to define a class that implements IExternalCommand interface. Return any of the Result options from your command depending on the outcome. You can use the examples below as templates. The Execute
method can contain your .NET code. Every time the script code changes, pyRevit will automatically recompile and runs the new version.
See the page below for detailed information on pyRevit features available to .NET bundles.
Anatomy of .NET (C#, VB) Scripts
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
namespace HelloWorld {
public class Test2 : IExternalCommand {
public Result Execute(ExternalCommandData revit,
ref string message, ElementSet elements) {
return Result.Succeeded;
}
}
}
Imports System
Imports Microsoft.VisualBasic
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Public Class HelloWorld
Implements IExternalCommand
Public Function Execute(ByVal revit As ExternalCommandData, _
ByRef message As String, _
ByVal elements As ElementSet) As Autodesk.Revit.UI.Result _
Implements IExternalCommand.Execute
Return Autodesk.Revit.UI.Result.Succeeded
End Function
End Class
<aside> <img src="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/663f6be5-40f9-4611-9f81-252f934825f3/ic_01_idea.png" alt="https://s3-us-west-2.amazonaws.com/secure.notion-static.com/663f6be5-40f9-4611-9f81-252f934825f3/ic_01_idea.png" width="40px" /> See Anatomy of .NET (C#, VB) Scripts
</aside>