Tuesday, November 20, 2012

Part 1 - Scripting with RevitPythonShell Software


For many years, the Revit Application Programming Interface (API) has provided a compiled method for programmers to communicate with Revit using .NET languages, whether it's VB.net, C# or C++. However, the process is still quite cumbersome and it does not allow direct interaction with Revit. Thanks to Daren Thomas, who created the RevitPythonShell which exposes Revit API to python scripting. Now Revit users can create simple scripts in python to create and manipulate objects in their Revit database.
When I first started exploring Revit Python, I was somewhat skeptical about how useful this will be for me, in fact, I was downright reluctant to learn yet another programming language. But as I got more and more familiar with Python, I gradually learned to appreciate the simplicity and elegance of python programming. A task that would have taken pages of codes in VB.net or C#, is now, simplified into a handful of lines in python, and I don't even have to stop and reload my Revit to test any of my python codes!
Before we get started, let's review the software that we will need to have installed.

Software Installation

The following software should be installed.
·         IronPython-2.7.3.msi  
·         Setup_RevitPythonShell_2013_r155.msi
·         Install RevitLookUp.dll  (see RevitPython\RevitAPI\RevitLookup)
Copy RevitLookup.dll  and RevitLookup.addin to your local ProgramData folder                  (C:\ProgramData\Autodesk\Revit\Addins\2013)


Now that you have everything installed, let's see how this all work together!


  • Revit Architecture 2013  (or  Vasari Beta) 
  • Revit API   
  • IronPython (Python) 
  • RevitPythonShell

Our primary environment will be Revit Architecture 2013.  If you would like to use Vasari Beta, it basically functions similarly to Revit’s Conceptual Massing Family Editor. We will be using Revit Architecture 2013 in both Project and Family Editor mode. 
The Revit API is the Application Programming interface which allows you to communicate with the Revit program using programming language, as opposed to the familiar user interface.  The Revit Python Shell is installed on top of Revit as an addin tool, and it basically provides a scripting window allowing the user to type in python scripts and run the scripts interactively. So what is the difference between Python and IronPython, you might ask? Well, IronPython is just a sub-dialect of Python, that is implemented so python can integrate with the Microsoft world of the .NET DLLs and other assemblies and libraries. Since Revit API is based on the .NET framework, we will be using IronPython instead of the standard Python or C-Python.




2 comments:

  1. Thks for the sharing! I am a revit user, currently looking into scripting tool for facade development in revit

    ReplyDelete
  2. Hi,
    Thanks for sharing. But we ran into a problem.
    We have installed as instructed 1 week ago but Revit stopped working when we installed the RevitPythonShell.
    After we uninstalled RevitPythonShell Revit stated to work again.
    Any idea, why this happened?
    Any tricks we should know?

    Thanks a lot,
    Stefan

    ReplyDelete