Category Archives: Non classé

python-materialsdb 0.2

It has been five years since my last article on this library. Back then it was an alpha: a thin wrapper to convert materialsdb.org data into an IFC project library. Since then the library grew into a complete materials workflow: an indexed catalogue, a web GUI to browse and compose constructions, and a two-way integration with Bonsai (the BlenderBIM add-on) — shipped as a Blender extension you can install and update like any other.

What’s new ?

An indexed catalogue

The library keeps a local sqlite index of everything cached from materialsdb.org producers (more than 2 000 materials). Filtering by company, category, λ range, thickness or usage is instant, and parsing got 3.9-4.7x faster along the way:

from materialsdb import query

query.refresh()                                # update the index from cached xml
rows = query.search("isolant", sort="lambda")  # filtered, sorted summaries
material = query.get_material(rows[0].id)      # full material dataclass

A web application: materialsdb-gui

A dependency-free (stdlib) local web application, started with materialsdb-gui. The picker lets you browse every cached material, sort and facet-filter by company/category/conductivity, pick whole materials or specific manufacturer thicknesses, and either export a standalone .ifc library or append into the IFC file open in your session.

A construction maker

Compose thermal constructions layer by layer, with live U-value computation (ISO 6946 / SIA 180 surface-resistance presets), a scaled stack preview, saved constructions in your cache directory, and export as IfcMaterialLayerSet.

And now: straight into Bonsai

The part I wanted the most. python-materialsdb now ships a Blender extension, installable and updatable from inside Blender through an extension repository:

Preferences ▸ Get Extensions ▸ ⌄ ▸ Add Remote Repository — add https://cyrilwaechter.github.io/python-materialsdb/index.json, then install materialsdb listener.

Once installed, the panel in the 3D-view sidebar can start the GUI server for you, open the picker in your browser, and receive whatever you send:

  • Materials: pick them in the browser, one click sends them into the
    open IFC model — with their materialsdb identity property set (so Lesosai
    or any materialsdb-aware software can retrieve the full data later),
    per-layer property sets and surface colours. Undoable, of course.
  • Constructions: the construction maker pushes a construction as an
    IfcWallType / IfcSlabType / IfcRoofType (per its design usage) with
    its IfcMaterialLayerSet, visible in the outliner.
  • Round-trip: select a wall in your model (or its type), send it back to
    the composer, adjust thicknesses — even layers whose material is not a
    materialsdb object are kept as “model material” placeholders — and push it
    back into the same layer set. Ctrl+Z rewinds it with a titled undo step.

Everything talks over a small localhost HTTP API, so FreeCAD, Revit or whatever-you-use listeners can reuse the exact same channel later.

Installing

pip install python-materialsdb

For the Bonsai integration: add the extension repository URL in Blender, set your Python interpreter in the add-on preferences (it needs pip install python-materialsdb), and you are set. Detailled instructions in the README.

What’s next ?

  • Local/project materials file: promote the “model material” placeholders
    into a project-specific materialsdb file, so foreign materials can live
    across projects and still compute U-values.
  • Listeners beyond Bonsai (FreeCAD, Revit) — the protocol is already
    host-agnostic.
  • More of the materialsdb data mapped into IFC property sets.

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 !