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:
- Go to the Revit Macro Manager
- Start a Module/Macro
- Start C# File.
- Paste your C# Code.
- Tools > Convert Code To > Python
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…