IFC Colour Elements with IfcStyledItem in MappedRepresentations

edited November 2023 in General

Hi All,
First, thanks for everyone supporting this great community. I have been reading on and off, but never got a chance to add to it, until now, when I finally got a chance to work on IFCs.
A bit of context, some of the work we do involve exporting Space Gass files, a structural analysis tool, to IFC. What we intend to achieve, is to assign each structural column and beam some colour using IfcOpenShell. This has to be assigned to the element, not using a material as the element has its own material. Thanks to Dion, https://forums.buildingsmart.org/t/where-and-how-will-my-colors-be-saved-in-ifc/1806/12, I got to the conclusion that the element needs an IfcStyledItem.

Now the real challenge, the exported IFC has a lot of MappedRepresentations and a disconnected IfcStyledItem that I cannot retrieve with IfcOpenShell. Neither I can add a new one and assign it to the element with ifcopenshell.api.run("style.assign_representation_styles", ifc, shape_representation= representation, styles=[style_custom]), as it seems MappedRepresentations don't like it and the style remains unassigned.


Can anyone help me to check if the attached IFC file is a fully ISO complaint IFC file?
If this is the case, looking for further guidance about how to handle the colouring with IfcOpenShell. Happy and keen to contribute to the project if needed.

Tagged:
Ace

Comments

  • @BIMicon Hello!
    Added a note to wiki on IFC file validation - here.

    What do you mean "style remains unassigned"? If you're talking about "AS-CONC2009-100" showing as active material instead of "907" then it's issue of the UI... currently it's mixing materials and styles in Blender Material section which we plan to fix by moving it to "Geometry and Materials" tab (you can track it here).
    Though style is correctly assigned to the faces as you can see in the viewport.

    AceBIMicon
  • Hi @Andrej730 , thanks for your prompt answer.
    The IFC checker is great! Unfortunately had a ton of stuff not compliant, will have to spend some time to report the most important ones to SpaceGass at some point...

    Going back to my main question, yes, Blender showing "AS-CONC2009-100" is correct. My intention is to substitute 907 , or modify its Base Colour though IfcOpenShell. I have followed the code through this post:
    https://community.osarch.org/discussion/1087/ifcopenshell-python-how-do-i-change-the-color-from-an-ifc-entity
    which works great in entities that are not MappedRepresentations. But as you can see in my IFC, members are MappedRepresentations.
    If assignment of new style is not working, I though I could change the existing one. But I couldn't find a way to retrieve the IfSurfaceStyle with asset 907 through IfcOpenShell. I could parse the IFC manually but would love to know more about how someone with more experience interprets this, and if it is really something that IfcOpenShell isn't handling at the time.

    Thanks again!

  • 1) style.assign_representation_styles: Just tested with the code below - it does assigns style for MappedRepresentation (it created #1803=IFCSTYLEDITEM(#904,(#722),$);).
    Though I'm not sure we have any API to unassign the style at the moment. :\

    ifc_file = ifcopenshell.open(filepath)
    beam = ifc_file.by_id(917)
    representation = beam.Representation.Representations[0] # MappedRepresentation
    alternative_style = ifc_file.by_id(722)
    ifcopenshell.api.run("style.assign_representation_styles", ifc_file, shape_representation=representation, styles=[alternative_style])
    

    2) To change the color you can edit edit style's SurfaceColour (note that each style constists of multiple styles and you need to edit IfcSurfaceStyleShading/IfcSurfaceStyleRendering to change the color:

    ifc_file = ifcopenshell.open(filepath)
    beam = ifc_file.by_id(917)
    representation = beam.Representation.Representations[0] # MappedRepresentation
    style = ifc_file.by_id(907)
    shading_style = next(style for style in style.Styles if style.is_a("IfcSurfaceStyleShading"))
    attributes = {"SurfaceColour": {"Name": None, "Red": 255, "Green": 0, "Blue": 0}}
    ifcopenshell.api.run("style.edit_surface_style", ifc_file, style=shading_style, attributes=attributes)
    
    AceBIMicon
  • Hi Andrej, thanks so much for your code snippets, working awesomely! Spent a lot of time checking why it is not displaying properly in Navis, and oh well, Dion's had the answer all the way back in 2019!
    https://forums.buildingsmart.org/t/where-and-how-will-my-colors-be-saved-in-ifc/1806/12
    One last question if you don't mind Andrej. Suppose that I want to modify surface colour of a series of members (2,3,5...etc), how can I retrieve the IfcSurfaceStyleShading of those members? The idea is to batch process them. Sorry if it sounds silly, couldn't find a connection between the member and the surface style.

  • @BIMicon
    You can get element's IfcSurfaceStyles with ifcopenshell.util.element.get_styles() and then each IfcSurfaceStyle has Styles attribute that will contain it's IfcSurfaceStyleShading (if there is one).

    BIMicon
  • That is awesome, thanks for all your help Andrej! So much time saved if I got your help earlier hahaha

Sign In or Register to comment.