Use pyRevit
Use pyRevit KCTangNote
21/2/2025: Created.
Intro
pyRevit is an application helping use of Python to develop programming scripts to manage Revit.
The default language used by Revit is C#.
Revit also comes with Dynamo, a graphical programming tool which also uses Python scripts to supplement.
Install Python
Go to our usual installation source folder.
Click this filename under that file to install Cpython:
- python-3.13.2-amd64.exe
Click to use admin privileges and add python.exe to PATH, then click Install Now to install using the default settings:
pyRevit comes with Cpython and Ironpython, which will be used when executing python scripts through pyRevit.
Cpython installed separately is not really used to execute scripts through pyRevit, but there are additional python packages to be used to extend the functions of pyRevit.
Cpython installed separately can also be used on its own when not using pyRevit.
Open Command Prompt window:
The prompt will be: C:\Users\<your username> instead of Admin.
Enter the following lines but after ">" to install additional packages:
> py -m pip install clr
> py -m pip install openpyxl
It may prompt you to update pip. Do it according to the instruction on the screen.
clr is used to add additional library when running scripts.
openpyxl is used to write and read Excel files without the need to have Excel installed.
The additional packages are stored under:
- C:\Users\Admin\AppData\Local\Programs\Python\Python313\Lib\site-packages
The python scripts should point to this folder before importing the packages in the folder to the scripts for use.
Install pyRevit
Go to our usual installation source folder.
Click this filename under that file to install pyRevit V4.8.16:
- pyRevit_4.8.16.24121_admin_signed.exe
Alternatively, download from: https://github.com/pyrevitlabs/pyRevit/releases.
Note that the latest release when writing this page is pyRevit v5.0.0, but it is better to use pyRevit v4.8.16 for now.
Open Revit.
Use Revit 2024 for now.
A menu item for pyRevit should appear.
Click it:
Click pyRevit on the left:
Click Settings on the right:
Click add folder to browse to add the file: Z:\Data\PythonApps\PyRevitExtensions\MyExtension.extension, which contains the scripts written by us:
Click Reload to effect the changes:
Reload is required whenever the settings or the scripts have been changed.
Close and re-open Revit if Reload is not effective.
The MyTools menu item will appear next to pyRevit.
Click MyTools to show the following items, clicking which can run the scripts:
Before running List Sorted Elements, copy the first file without date to the relevant Revit model job folder:
Those with dates are old versions.
The file is a template to define the elements and parameters to output to Excel file format:
Clicking List Sorted Elements can produce an Excel file with the first worksheet showing the following:
These items can be copied to our normal Excel dimension sheets as primary quantities for further adjustments to give secondary quantities for Bills of Quantities or Estimates.
There are also other more detailed worksheets generated according to the template settings.
These worksheets can replace Revit's view schedules. However, view schedule entries can be changed on-screen while seeing the model change accordingly.
Linking the Excel files to Revit model in real time is still to be done.
Install Visual Studio Code
Visual Studio Code can be used to write Python scripts.
There are other editors available such as Visual Studio (https://visualstudio.microsoft.com/), pyCharm (https://www.jetbrains.com/pycharm/) and many others which are called Integrated Development Environments or code editors.
Download Visual Studio Code for Windows from here (https://code.visualstudio.com/).
Install it:
Open it after installation to show:
Select File > Preferences > Themes > Color Theme to list and select the color theme:
Alternatively, select View > Command Pallet, and enter Color Theme to display the same list to select.
Select the 4-square icon on the left vertical menu, enter pyrevit to show pyRevit with VSCode, and click Install:
The installation will automatically install:
- Python - Python extension for Visual Studio Code
- Pylance - a fast, feature-rich language support for Python
Two pop-up messages will appear:
Since pyRevit has already been installed. Do not need to download it.
Click to download Revit API Stubs, which help to display the code syntax when writing codes.
The following folders will be added:
Select View > Command Pallet, and enter inter to filter the list to choose Select Interpreter to choose the previously installed CPython:
Enter user to filter the list to choose Open User Settings (JSON) as shown above.
Copy and paste the following codes to the Settings:
{
"workbench.colorTheme": "Default Light+",
"security.workspace.trust.untrustedFiles": "open",
"workbench.iconTheme": "vs-minimal",
"python.analysis.extraPaths": [
"C:\\Users\\<username>\\AppData\\Roaming\\RevitAPI stubs\\RVT 24",
"C:\\Program Files\\pyRevit-Master\\pyrevitlib",
"Z:\\Data\\PythonApps\\PyRevitExtensions\\MyExtension.extension",
],
"python.autoComplete.extraPaths": [
"C:\\Users\\<username>\\AppData\\Roaming\\RevitAPI stubs\\RVT 24",
"C:\\Program Files\\pyRevit-Master\\pyrevitlib",
"Z:\\Data\\PythonApps\\PyRevitExtensions\\MyExtension.extension",
],
}
Change <username> to your username on the computer.
The first line of the extraPaths refers to the location of RevitAPI stubs.
The second line refers to the location of pyrevitlib.
The third line refers to the location of the scripts supporting the menu items under Revit's MyTools.
Select File > Open Folder, and browse to select the folder containing the scripts:
- Z:\Data\PythonApps
Select the scripts to edit.