You might be aware that you can use CPython script inside pyRevit using #! python3 at the beginning of your script file. The library which allow this is pythonnet. I encountered some issues:
pathlib module was not working because it was using ironpython version from pyrevitlib. Why ? python path. CPython site-packages path came after ironpython sites-packages path. Workaround: put pathlib.pyc in your <extension_path>\lib folder but it might be an issue if another script uses ironpython version. See issue #1287.
I have not found yet how to make a GUI inside Revit inside a CPython script. tkinter is not packaged with embedded python interpreter. wpf does not work the same way with pythonnet. Windows Forms might work.
What the script does at the moment is creating a .rvt file for each producer. It creates materials including main thermal properties. It also create hatches and apply colors based on a .json template produced with ExportMaterialsGraphics script which serialize all this parameters. Doing so I discovered how complex hatch are stored with in a list of FillGrid. Whatever the shape of your hatch, it is stored as a list of segments.
Source code is available here. I made a short video (in French) to explain how to use it currently.
Woaw! It’s been a while since my last article. More than a year.
I am happy to present you my new library for materialsdb.org. Consider as an alpha, see below in what’s next.
What’s materialsdb.org ?
In short it is an open standard to store material data. More details on official website. I have used it throughout my career for thermal analysis through Lesosai. It can store thermal conductivity, thermal capacity etc… but also data for other trades like structural analysis, acoustic analysis, like cycle analysis, fire behaviour. Names, description can be stored in multiple languages. Materials data can be stored for a specific country if material vary from a country to another. These materials data are directly updated by manufacturers themselves. It works great.
What’s new ?
This library have a tool to convert materials data to IFC. IFC schema contains an IfcProjectLibrary entity which allow your store element types like IfcWallType, IfcSlabType etc… These project libraries can be read by BlenderBIM Add-on which means that you can then use it directly in your project to create wall with accurate materials data. Materials contains a custom property set to store materialsdb.org id which means Lesosai and other softwares using materialsdb.org can retrieve all material data with this id which have not be stored in IFC like translations in other languages. Default language is french and default country is Switzerland but you can easily modify your config as described in README.
If you are a manufacturer you can eventually also use it to create your own materials.
Some very simple script can help you achieve tasks of missing features in Revit. As much as I know there is no way to accurately place a label to origin manually. A way to place it as well as possible is to put 0 as sample value and try to align it as well as possible by zooming. Sometimes when you activate a leader your line isn’t straight even if your annotation is perfectly perpendicular to your object just because your annotation family is not perfectly aligned on 0,0. The following very simple script will solve it your annotation family will be perfectly aligned on 0,0 :
# coding: utf8
from rpw import DB
__doc__ = "Designed for annotation families. It moves selected annotation to center (set 0,0,0 coordinates)"
__title__ = "Center Text"
__author__ = "Cyril Waechter"
__context__ = 'Selection'
for text_element in rpw.ui.Selection():
text_element.Coord = DB.XYZ()
The tool is available in pyRevitMEP. Just update it from pyRevit tab.
pyRevitMEP philosophy : encourage MEP people to group-up and develop common tools. You want to contribute by coding : send a pull request on github or more (do not hesitate to contact me). If you prefer to manage your own extension, add your tools in the /pyRevitMEP.tab/ and follow instructions on pyRevit blog to add it to extensions manager. You want to contribute but don’t know how, check FAQ page. License is and will remain open source. It is currently under GNU GPL v3.0 License.
Some Revit addins and extensions are adding many parameters to you project. Some are not even visible to the user. It means that you have to use API to remove it. In most common case you’ll never see it unless you use Revit Lookup. But when you export your model or do a duct pressure loss report it appears on it. So I made a script to get quickly rid of unwanted parameters (hidden or not).
from Autodesk.Revit.DB import *
from System import Guid
uidoc = __revit__.ActiveUIDocument
doc = __revit__.ActiveUIDocument.Document
app = __revit__.Application
#Retrieve all parameters in the document
params = FilteredElementCollector(doc).OfClass(ParameterElement)
filteredparams = 
#Store parameters which has a name starting with "magi" or "MC"
for param in params:
if param.Name.startswith(("magi", "MC")): #startswith method accept tuple
print param.Name #To check if a parameter in the list is not supposed to be deleted
#Delete all parameters in the list
t = Transaction(doc, "Delete parameters")
for param in filteredparams: