Back to all essays
C# / .NETJun 15, 20264 min read

Modern C# Scripting in BIM Automation

How compiler-as-a-service (Roslyn) is changing the developer lifecycle for Revit extensions.

Modern C# Scripting in BIM Automation

Modern C# scripting brings compiler-as-a-service capability directly to Autodesk Revit. Using Roslyn, developers can execute arbitrary C# code dynamically inside the active Revit application context.

The Roslyn Advantage

By utilizing Microsoft's Roslyn compiler API, we can bypass the slow dev-loop of traditional Revit add-in development:

  • Instant Compilation: Read a C# script from a web editor and compile it in memory in a fraction of a second.
  • Access to Active Transaction: Dynamically open, edit, and commit Revit database transactions.
  • Isolated Script Runner: Wrap execution in exception-handling sandboxes to prevent crashing the host Revit threads.
// Example dynamic script transaction
using (Transaction tx = new Transaction(doc, "Dynamic Parameter Update")) {
    tx.Start();
    // Update elements dynamically
    tx.Commit();
}

This flexibility allows automation teams to maintain scripts in a central database or repository, delivering fixes and features instantly without requiring end-users to install new DLLs.