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).

CyrilMoultbrunopostletlangJesusbillMassimo

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
Sign In or Register to comment.