OSArch Community

Visualize IfcRelSpaceboundaries

  1. M

    I have a model with a number of IfcSpaces with Physical 2ndLevel IfcRelSpaceBoundaries and would like to visualize them in BlenderBIM as External or Internal with different color and wonder if anybody knows how to do this?

    /Max

  2. T

    Chatgpt to the rescue... not vetted

    
    import bpy
    
    import ifcopenshell
    
    
    # Load the IFC file
    
    filename = "path/to/your/ifc/file.ifc"
    
    ifc_file = ifcopenshell.open(filename)
    
    
    # Get all IfcSpaces with Physical 2ndLevel IfcRelSpaceBoundaries
    
    spaces = ifc_file.by_type("IfcSpace")
    
    physical_spaces = []
    
    for space in spaces:
    
        if space.Representation:
    
            for rep in space.Representation.Representations:
    
                if rep.RepresentationIdentifier == "Body" and rep.RepresentationType == "SweptSolid":
    
                    if space.is_a("IfcSpace") and space.ElementType and space.ElementType.is_a("IfcSpaceType") and space.ElementType.PredefinedType == "INTERNAL":
    
                        physical_spaces.append(space)
    
                    elif space.is_a("IfcSpace") and space.ElementType and space.ElementType.is_a("IfcSpaceType") and space.ElementType.PredefinedType == "EXTERNAL":
    
                        physical_spaces.append(space)
    
    
    # Create two materials for internal and external spaces
    
    internal_material = bpy.data.materials.new("Internal")
    
    external_material = bpy.data.materials.new("External")
    
    
    # Set the diffuse colors for the materials
    
    internal_material.diffuse_color = (0.8, 0.8, 0.8)  # gray
    
    external_material.diffuse_color = (0.0, 0.0, 1.0)  # blue
    
    
    # Assign materials to IfcSpaces based on their InternalOrExternalBoundary property
    
    for space in physical_spaces:
    
        if space.InternalOrExternalBoundary == "INTERNAL":
    
            space_object = bpy.data.objects[space.GlobalId]
    
            space_object.data.materials.append(internal_material)
    
        elif space.InternalOrExternalBoundary == "EXTERNAL":
    
            space_object = bpy.data.objects[space.GlobalId]
    
            space_object.data.materials.append(external_material)
    
    
  3. C
  4. C

    Would like to see an IFC which has IfcSpace boundaries, I don't think Schependomlaam.ifc has them?

  5. M

    I got the same error for an IFC2x3.

    AttributeError: entity instance of type 'IFC2X3.IfcSpace' has no attribute 'ElementType'

  6. C

    @Max

    Is it possible to share your IFC or maybe some similar example?

  7. T
  8. M
  9. C

    wow!, I just discovered you can select them with blenderBIM:

  10. C

    @Max I totally missed this topic… yes you can using IfcSelection

    Do not hesitate to tag me next time you have a question on this topic.

  11. M

    I need to export the IfcSpaces as 3D CAD-objects (3DS) with unique colors for each face based upon IfcRelSpaceboundary (and if possible wall/slabtype) , prefarable using Python and wonder if anybody could point me in the right direction?

  12. M

    @Max have you looked at https://docs.blender.org/manual/en/dev/addons/import_export/scene_3ds.html ?

    I'd recommend looping through each IfcRelSpaceBoundary, finding its Blender object, then clearing its material slots, adding a new material with a random colour, then assigning it as the only material slot.

    
    f = blenderbim.tool.Ifc.get()
    
    boundaries = f.by_type("IfcRelSpaceBoundary")
    
    for boundary in boundaries:
    
        obj = blenderbim.tool.Ifc.get_object(boundary)
    
        if not obj:
    
            pass # load it in, or ignore? What's your usecase?
    
        while obj.material_slots:
    
            bpy.ops.object.material_slot_remove()
    
        mat = bpy.data.materials.new('Foo')
    
        mat.diffuse_color = (1,0,0,1) # Or random colour, or cycled colours, etc
    
        obj.data.materials.append(mat)
    
  13. M
  14. M

    @Max the obj variable is probably none because it isn't loaded into Blender yet. By default space boundaries are not loaded and only loaded on demand.

    The loader is in a bit of a weird place (it should be moved to a tool function) so it's a bit awkward but you can do this to load in all space boundaries (alternatively you can choose which ones you're interested in):

    
    import blenderbim.bim.module.boundary.operator
    
    loader = blenderbim.bim.module.boundary.operator.Loader()
    
    for rel in tool.Ifc.get().by_type("IfcRelSpaceBoundary"):
    
        loader.load_boundary(rel, tool.Ifc.get_object(rel.RelatingSpace))
    
  15. M

    Thanks a lot @Moult , that explained a lot and now the code works perfectly. While I am at it I would like to add some more color features, preferable color IfcRelSpaceBoundaries according to InternalOrExternalBoundary, PhysicalOrVirtual, RelatingSpace and RelatedBuildingElement (IfcWindow, IfcWall, IfcSlab...) and wonder if you know how to do this.

  16. M

    @Max what's the issue? You can create your own colour map based on those properties via a dictionary and using a cycle to create the keys.

  17. M

    The main issue is that I am still trying to learn Python, Blender, BlenderBIM, IFC and IfcOpenShell.

Login or Register to reply.