IfcOpenShell examples

As a way to thank the growing community of Open Source users and developers in the AEC domain, I have started to collect some of my personal learning journey into a Github repository. I am focusing on sharing a few smaller scripts using Python and IfcOpenShell libraries. Right now, I started with very simple but complete examples that are useful when you first start using these libraries. The kind of examples I lacked when I started my own journey.
https://github.com/stefkeB/ifcopenshell_examples

  1. Console examples are very simple and have no dependencies but the IfcOpenShell library.
  2. GUI examples use Qt5 libraries (PyQt5 but PySide2 would not require any significant changes).

For each example, I also added a separate page in the Wiki with my explanation of how things work.

I have some more advanced working examples that I intend to share as well: a more complete display of the whole IFC structure (following all attributes recursively, although not endlessly), some basic editing of strings and other single values and adding a 3D view using Qt3d.

P.S. Coming from C++ and C# in Unity, I'm not entirely sure if my coding style is "pythonic" enough, but I think the code is fairly straightforward, compact and hopefully clear. The wiki is the type of textual explanation of code that I always hope to find when I look for examples (but too often people claim that the "code is the docs"). If you think you have ways to improve it, I guess I'll have to start learning how to deal with pull requests (which I haven't completely figured out yet).

CyrilMoultbrunopostletlangJesusbillMassimohtlcnn

Comments

  • This is a great resource! Thanks for sharing!

    You may also already know of, but just in case you haven't seen it, this might help: https://wiki.osarch.org/index.php?title=IfcOpenShell_code_examples - for example, your advanced example sounds a bit like traverse().

    A lot of your code is with extracting data. If you'd like to learn about manipulating data, you may be interested in reading code snippets in the evolving ifcopenshell.api :) https://github.com/IfcOpenShell/IfcOpenShell/tree/v0.6.0/src/ifcopenshell-python/ifcopenshell/api

  • Thank you for your comments. It seems that the different APIs are evolving quickly and many online code examples are thus getting outdated. That is probably the price to pay to try to stay on the bleeding edge. Your BlenderBIM work is amazing, but it may be too much to get into for beginners (on the coding level, I mean). I'll look at the new API and the traverse.

    One of the "issues" I sometimes have with ways to simplify data extraction is that you may receive small "dictionaries" and "lists" of string data which can display nicely, but you loose the link to the underlying data in the model quickly. So I'm hoping to get an editable tree implemented, where I can actually change values in the model directly. I can rename objects in a Tree View already, but I have troubles with finding the right way to change a value from an enumeration (where you'd want to display a combo-box to the user to choose from).

    One intention is to display the tree as-is (meaning: no 'interpretation' or simplification, which is what you see in Solibri or BIMcollab Zoom of BIMvision). They are very good viewers, but you don't see it as it actually is. E.g. there is no "Ceiling" in IFC, but there is a Covering with type CEILING. I understand this as being more accessible to end users, but it confuses when you need to dig deeper.

  • @StefanBoeykens that is a great intention. I have designed the BlenderBIM Add-on around this intention, that we should not mangle the spec.

    Here is code snippet as a hint on how you can implement changing values for an enumeration.

    import ifcopenshell
    import ifcopenshell.util.attribute
    
    f = ifcopenshell.file()
    w = f.createIfcWall() # Example entity
    schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(f.schema)
    wall_attributes = schema.declaration_by_name(w.is_a()).all_attributes()
    for attribute in wall_attributes:
        data_type = ifcopenshell.util.attribute.get_primitive_type(attribute)
        if data_type == "enum":
            print(ifcopenshell.util.attribute.get_enum_items(attribute))
    
    StefanBoeykens
  • I don't have a full viewer with editable fields yet, but I did update the Wiki on the Github page.
    https://github.com/stefkeB/ifcopenshell_examples/wiki
    I've succeeded in setting a basic Tree widget for the Spatial Structure, another one for all properties and attributes and quantities and a 3D window using the Qt3d module from the Qt toolkit. The wiki is a tutorial for the basic versions of the code. The next step will be to further elaborate this to a viewer and (basic) editor. There is so much left to do, so it may take a while.

    stephen_lhtlcnn
  • This looks great @StefanBoeykens ! Do you have plans to distribute binaries for a cross platform viewer? I think many people are looking for an open source cross platform lightweight view-only system. Right now, the IfcOpenShell Qt app is a bit difficult for users to get started with, and the IfcPlusPlus viewer also isn't really straightforward.

  • I'll try that. I played with pyinstaller yesterday, and apparently, I was able to make a standalone app from it (tested on macOS and Windows). I'm now collecting all my partial versions and try to merge them into one application. In general, for pure tree widgets, IfcOpenShell is more than powerful enough. But it can still take a long time to load geometry. And the 3D viewer navigation right now is too simplistic to be of any real value, alas.

    Moult
  • FWIW, I've updated my own PyQt IFC viewer the last few days. It's still very simple, but it can show the full IFC structure, by recursively following attributes (it goes really deep... but I had to add a max depth to avoid infinite recursion). And you can edit STRING, INT, DOUBLE and ENUMERATION attributes.

    My custom IFC viewer

    Jesusbill
  • @StefanBoeykens fantastic! I see you have direct and indirect attributes in there. Might I also recommend adding inverse references? (ifc_file.get_inverse(element)) Most of the time these overlap with indirect attributes, but sometimes they don't when buildingSMART missed some attributes, and it becomes really useful to know 100% what is using an element. Perhaps see the IFC Debug panel in Blender to see what I mean :)

    Any chance of bundling a binary? Perhaps py2exe can make it "just work"?

Sign In or Register to comment.