Reload IFC data in Bonsai

edited August 2025 in General

I have a simple python script that assigns properties to IFC objects loaded in Blender. I am using Bonsai 0.8.4.
I do this using the ifcopenshell package. After assigning the properties, I'd like to load these changes in Blender from the script. I have tried using "load_ifc_automatically" suggested in https://community.osarch.org/discussion/comment/22078#Comment_22078
but this results in an error (attempt to free illegal pointer).

I would like to use these scripts in an UI that operates on the IFC data (assigning numbers to objects).

My script is now of this form:

import ifcopenshell

ifc_file = ifcopenshell.open("path/to/file.ifc")

#Assigning properties to elements
elements = ifc_file.by_type("IfcWall")
for (i, element) in enumerate(elements):
     if hasattr(element, 'Tag'):
        element.Tag = str(i)

ifc_file.write("path/to/file_new.ifc")

#Now I want to load this altered IFC file in Blender
load_ifc(ifc_file_path_new)

Any suggestions how to do this?

Comments

  • If you are operating inside Bonsai you can change the loaded objects directly like this:

    import bpy
    import bonsai.tool as tool
    
    wall_elements = []
    for obj in bpy.context.scene.objects:
        element = tool.Ifc.get_entity(obj)
        if element.is_a("IfcWall"):
            wall_elements.append(element)
    
    for (i, element) in enumerate(wall_elements):
        if hasattr(element, 'Tag'):
            element.Tag = str(i)
    
    steverugiMassimowalpatheoryshawBjornFidderDimitris
Sign In or Register to comment.