Converting Revit API C# Code to Python

How do I convert this code sample to Python?

The Revit API documentation and SDK examples are all in C# (and VB). This makes it difficult for those who are just starting to learn how to use the Revit API code with Python.

Porting C# code to Python requires a good understanding of Python, and some familiarity with C#. The guide below is not comprehensive but should cover basic concepts needed to get started.

SharpDevelop Code Conversion Tool

This is helpful to speed up converting a large snippet. I have not tested this extensively, but I used on a few snippets and it seems to do the job although it does not handle imports.

Below is a quick example of how to use it:

  1. Go to the Revit Macro Manager
  2. Start a Module/Macro
  3. Start C# File.
  4. Paste your C# Code.
  5. Tools > Convert Code To > Python

SharConvert

The hard way

Manually porting code by re-writing in Python takes time, but it’s an essential skill to have considering Python is not a supported Revit API language.

Although there are some weird…

Read more