Revit Python Shell Image

Introducing Revit Python Shell

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:

https://github.com/architecture-building-systems/revitpythonshell

After its installation, the tool should appear in the Add-Ins tab:

Revit Python Sheel in Toolbar

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:

Collect Sheets Number RPS image

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:

http://www.revitapidocs.com/2018.2/263cf06b-98be-6f91-c4da-fb47d01688f3.htm

The LookupParameter method retrieves the named parameter. AsString() returns it as string. It is described concisely here:

http://www.revitapidocs.com/2018.2/4400b9f8-3787-0947-5113-2522ff5e5de2.htm

I cannot wait to show you a full example of the possibilities of this tool! Jump to the next post!


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *