Iterating over IFC scene in python for mapping attributes to blender objects

Hi,

I just started diving back into BlenderBim, and I'm strugging to find good information on how to access attributes per-object on an imported IFC scene.

I'm experimenting with a program that starts Blender headless, runs the IFC exporter, and exports a glTF scene.

This is working great! I was happy that its basically two lines in Python:
bpy.ops.bim.load_project(filepath=input_path, use_relative_path=False, should_start_fresh_session=True) bpy.ops.export_scene.gltf(filepath=output_path, export_draco_mesh_compression_enable=True)

Now I'd like to take it further and build a dictionary of metadata, mapping the actual blender 3D objects to their IFC data (any metadata that is available) and export that as a json along with the glTF file. In particular, in the Object Metadata panel > Attributes there is a Tag attribute that I'd like to associate with the actual 3D object.

I spent some time noodling around in the Python console, using the selected blender scene object as my starting point, digging around attributes to no avail. It seemed like I was only able to access general Blender data.

So after some reading I found this bit of code that almost gets what I need for this:
`
from blenderbim.bim.ifc import IfcStore

ifc_file = IfcStore.get_file()
allBuildingElements = ifc_file.by_type("IfcBuildingElement")
`
Then I can easily access .Tag and everything else directly from each element. But I still don't see how to associate this with an actual Blender object that was instantiated in the scene at import.

What is the simplest way to go about this?

John

Comments

  • edited April 20
    import blenderbim.tool as tool
    obj = context.active_object
    element = tool.Ifc.get_entity(obj) # get ifc element from blender object
    obj = tool.Ifc.get_object(element) # get blender object from ifc element
    

    If you want to learn from codebase, make sure to enable Python tooltips in Blender preferences

    This will allow you to see the internal name of the operator for each button, so you can look it up in codebase and learn new things about blender-ifc interactions.

    theoryshawroblutz
Sign In or Register to comment.