IfcOpenshell inside Bonsai: load new elements without reloading the whole file?

I have a script that creates IfcElements using IfcOpenShell. I'm running the script inside Blender.
I would like to display the new elements inside Bonsai without having to reload the whole Ifc file since this takes quite some time.

import bonsai.tool as tool

model = tool.Ifc.get()

new_members = ... # adding new element to (e.g.a wall)


tool.Ifc.set(model)

Comments

  • might be the latest, not sure
    pulled from: https://github.com/C-Claus/BlenderScripts/commit/8afe7bf5c3ecd54e1c940d589f5d845adbef8fdb

    def load_ifc_automatically():
    
        if (bool(ifc_file)) == True:
            project = ifc_file.by_type('IfcProject')
    
            if project is not None:
                for i in project:
                    collection_name = 'IfcProject/' + i.Name
    
                collection = bpy.data.collections.get(str(collection_name))
    
                if collection is not None:
                    for obj in collection.objects:
                        bpy.data.objects.remove(obj, do_unlink=True)
    
                    bpy.data.collections.remove(collection)
    
            for material in bpy.data.materials:
                material.user_clear()
                bpy.data.materials.remove(material)
    
            bpy.ops.outliner.orphans_purge(do_local_ids=True, do_linked_ids=True, do_recursive=True)         
            bpy.ops.bim.load_project(filepath=file_path)
    
  • Would it be good, to bake this function into Bonsai somehow? Quite a few have asked for it in the past.

  • Thank you, but this reloads the whole Project.
    Isn't there a way to only reload the changed elements?
    I guess if I create a element with Bonsai, It's not reloading the whole Project?

  • It's probably a rabbit hole, but IfcGit selectively reloads parts of the model that have been edited when you load the commit, it's hooked to the whole Git setup aswell though and is done through the UI, but maybe that is a start?

    steverugi
  • No, IfcGit reloads the entire model, it just uses a custom function that keeps the current view in the viewport so it looks like a partial update

    AceJohn
  • @brunopostle said:
    No, IfcGit reloads the entire model, it just uses a custom function that keeps the current view in the viewport so it looks like a partial update

    TIL, it's quite efficient at doing that, thankyou Bruno

  • @theoryshaw said:
    Would it be good, to bake this function into Bonsai somehow? Quite a few have asked for it in the past.

    Sounds like a rabbit hole of bugs, who knows what else could have changed in the file 😁

    theoryshaw
  • i've had a look how the file is reloaded in IfcGit.
    bonsai.tool.IfcGit.load_project('path/to/file.ifc') works realy well

Sign In or Register to comment.