Assign IfcSurfaceStyle by property - more automated way?
Hello,
So I recently started learning Bonsai and one of the first things I wanted to do was assigning IfcSurfaceStyle by property and saving it back to the IFC file. It all started with inability to do it in Revit - it does not have the functionality to assign IfcSurfaceStyle/colors, it only assigns an IfcSurfaceStyle corresponding to the IfcMaterial during IFC export so the only way to "color" elements by property/type or whatever so they get the right colors in IFC viewers, is to set materials for them. But obviously it's just a workaround and not a proper way to do it.
I found these 2 tutorials, which led me to figuring out how to it in Bonsai:
1) How to Set Custom Colors for IFC Elements: https://www.youtube.com/watch?v=-HFPTWxVP_o
2) how to use color by property in bonsaibim (without getting stuck): https://www.youtube.com/watch?v=OusGMhCJGeo - this is close to what I wanted to do, but it's about assigning colors in the Blender view, not in the IFC file itself
I didn't find any tutorials showing how to it from start to finish, but I used the following method:
- go to Project Overview, Grouping and Filtering, Search, Add Search Group, Add Filter based on property, Search
- assign IfcSurfaceStyle to the selected group of elements, as shown in tutorial 1.
It works, but the problem is that is has to be done for each group of elements manually. So, for example, if we want to colour elements based on whether they are load bearing or not, it doesn't take much time because we only have 2 groups. But in case of e. g. coloring by type, it would take a huge amount of time since there would tens or hunderds of groups.
So here's my question - is there a more automated way to do it? If not in current version of Bonsai itself, would it be possible to write a script/plugin/extension that would be doing it? I'm also a programmer, I haven't tried to play with Blender API or IfcOpenShell yet, but I know Python and write Revit plugins so maybe I could try to do it myself?
I'm also thinking about making a tutorial on this topic, but first I wanted to see if there isn't a better way to do it.
Any hints will be much appreciated!
Comments
@MagdaCejrowska
did you check this?
AI's pretty good at helping you along, as well...
https://claude.ai/share/54c88c20-818f-4673-a762-82b1172e7eaf
Thanks for the replies, I spent a couple of evenings to write it myself :) Here's a simple console app in Python for assigning IfcSurfaceStyle inside IFC files. It applies colours to elements by property from a specific Pset or by type:
https://github.com/MagdalenaCejrowska/ifccolours
I haven't looked into how contributions to Bonsai work yet, but maybe it could come in handy? Otherwise I'm just sharing it in case anybody had the same problem. I will also make the tutorial about how to do it in Bonsai manually and automatically with my app.
@MagdaCejrowska Very nice!
If you have not, please take a look https://docs.bonsaibim.org/guides/development/index.html it will give you a good understanding on how to setup a dev environment for you to contribute.
Thanks!