IfcOpenShell style not applied to material
Hi! I'm trying to apply colours to elements in an ifc model. In BlenderBIM the relevant material appears to be correctly assigned to each element, however the style does not appear in the viewport.
When I click to edit the material of an element and then apply it the correct style appears. Presumably there is some step I have missed in python which BlenderBIM is carrying out when I do this - it seems as if all of the information is there, it's just not being applied properly.
When I do the editing and applying in BB, the original material is removed from the element, but I would have thought this should already have been done if the material was correctly assigned in python.
Tagged:
Comments
Hi @ds026 I'm currently trying to learn materials in ifc and BB, and stumbled on this https://standards.buildingsmart.org/IFC/DEV/IFC4_2/FINAL/HTML/schema/ifcrepresentationresource/lexical/ifcmaterialdefinitionrepresentation.htm
"Entity definition
IfcMaterialDefinitionRepresentation defines presentation information relating to IfcMaterial. It allows for multiple presentations of the same material for different geometric representation contexts."
It looks like you're ahead of me on the materials learning curve, so if the above helps, any notes/pointers on it, or materials in general, would be greatly welcomed.
Thanks, I've looked at that and looked more at my ifc file and have figured that for whatever reason the IfcStyledItem for each element still refers to the IfcPresentationStyleAssignment of the original material rather than the new ones. Although I am no closer to working out how to fix this apart from manually changing the reference on each IfcStyledItem.
For learning how to do materials, there's a lot of examples within the code for ifcopenshell which I hadn't realised initially: https://github.com/IfcOpenShell/IfcOpenShell/blob/v0.7.0/src/ifcopenshell-python/ifcopenshell/api/material/assign_material.py
Not sure, code-wise, how to do it, but maybe the following could give you a clue:
video: https://www.dropbox.com/scl/fi/8qjhc2pj64863r65b5zvy/2024-05-01_12-15-36_blender_-Unsaved-_-_Blender_4.1blender.mp4?rlkey=nglzkbw5tth996p1jl4kuxzux&dl=0
I think basically what's going on in the video, is that the 'Frame' material is applied to the instance and the 'Unknown' material is applied to the type definition. The instance material overrides the type's material. If you delete the instance material, the type's material comes through.
And you never know, maybe's @Andrej730 recent commit fixed some things as well.
https://github.com/IfcOpenShell/IfcOpenShell/commit/bef5d3cca514db9d7346e15b15357fa1445606bb
Very helpful, many thanks
Can you please try to reproduce it in the current buld from github releases? Yesterday I've fixed an issue when assigning a material to the element would remove blender materials with styles that were asigned to the element's representation items (styles assigned to item element should take the priority over the material style). What you describe sounds very similar.

Thanks! I've managed to sort it now from this. Seems like the original style was still applied to the representation item, similarly to what you've suggested. I've deleted the unwanted styles associated with each representation like this:
ifcopenshell.api.run("style.remove_style", bim_model, style=bim_model.by_guid(element).Representation.Representations[0].Items[0].StyledByItem[0].Styles[0].Styles[0])