Category Archives: Non classé

python-materialsdb inside Revit

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.

python-materialsdb

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.

python-materialsdb library

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.

What’s next

Only material data from material IFC specifications property sets and basics like id are currently converted to IFC. Handling for the rest of the data can be easily added.

More tools to query material (by name, manufacturer, thermal conductivity etc…).

Testing: make sure that there is no unit mismatch. Check if ArchiCAD can use an IfcProjectLibrary in some ways.

Best wishes for 2018 and pyRevitMEP extension update for pyRevit 4.5

pyRevit 4.5 has been released on 01.01.2018 with huge improvements. Make sure to check Ehsan post if you are interested to discover main new features.

Some change breaking have required some change on pyRevitMEP but thanks to Ehsan explanation videos and docs it was a piece of cake.

On an other hand, I added many new features to pyRevitMEP (some in labs) but I lack of time to write articles on new features at the moment.

To get all updates Make sure to :

  1. Uninstall previous version of pyRevit (strongly recommended according to Ehsan post)
  2. Install pyRevit 4.5 from official installer (or manually with git if you like)
  3. Install pyRevitMEP from extension manager (or clone it from github)

I wish all the best for 2018 and hope that we’ll all get a little more open source code, engineering, agriculture etc…

Check http://opensourceecology.org/ they do great things !

[pyRevit] Move labels in annotation families to origin (0,0)

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
import rpw
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'

with rpw.db.Transaction():
 for text_element in rpw.ui.Selection():
 text_element.Coord = DB.XYZ()

The tool is available in pyRevitMEP. Just update it from pyRevit tab.

[pyRevit] pyRevitMEP is now available in pyRevit extensions manager

Thanks to his creator Ehsan Iran-Nejad and all credits we have a great tool named pyRevit. This tool allows us to easily make python scripts for Revit and distribute them via the extensions manager.

And it is exactly what I did by creating pyRevitMEP extension which has been added by Ehsan to pyRevit extensions manager last week-end :

pyRevitMEP

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.

[Revit] Delete parameters including hidden ones

In some case you need add or delete many parameters. Spiderinnet did many great articles about parameters, here are 2 of them :

Create shared parameter

Create project parameter

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
        filteredparams.append(param)
        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")
t.Start()
for param in filteredparams:
    doc.Delete(param.Id)
t.Commit()

Cheers !