Following what I have set forth in my previous post about what programming language to choose first, I will show you some benefits of Python. Well, technically it is IronPython, an implementation of Python for the .NET platform, but the syntax is basically the same.
Revit Python Shell, RPS, is a useful, a really useful tool to test Python scripts live. You can run what you type in the console to see the results and debug in a terminal as if it is in a Python console. To use RPS we need to install it, the installer is available at the author’s website:
After its installation, the tool should appear in the Add-Ins tab:
Click Interactive Python Shell and a window like the following one will appear. To start scripting, we need to import Revit’s API and the clr, common language runtime, which is the virtual machine that provides a line of communication with Revit’s API in Python even though it is written in C:
So after importing, we can proceed to check for use cases of this live console. In the example, we collect all the sheets in the project and print their names in the console. There is a live preview of what is being collected!
This is a game-changer in terms of debugging, if you have tried Python scripts inside Dynamo you will definitely understand why, if not, try that for a bit and you will surely come back here!
All the code is standard Python, the first four written lines import the Revit API. The collector is a class inside the API, you can read more about its methods here:
The LookupParameter method retrieves the named parameter. AsString() returns it as string. It is described concisely here:
I cannot wait to show you a full example of the possibilities of this tool! Jump to the next post!