This python code reads the atributes and psets for the selected IFC element from the BlenderBIM active view and displays them in a Blender tab.
Blender 3.6 has been used.
import bpy
import ifcopenshell
import blenderbim.tool as tool
class OBJECT_PT_IFCPropertiesPanel(bpy.types.Panel):
bl_label = "IFC Properties"
bl_idname = "OBJECT_PT_ifc_properties_panel"
bl_space_type = 'VIEW_3D'
bl_region_type = 'UI'
bl_category = 'IFC Properties'
def draw(self, context):
layout = self.layout
# Obținem fișierul IFC activ folosind BlenderBIM
model = tool.Ifc.get()
# Obținem obiectul IFC selectat în Blender (presupunând că este un singur obiect selectat)
selected_objects = bpy.context.selected_objects
if len(selected_objects) == 1:
selected_object = selected_objects[0]
name = selected_object.name
bpy.data.objects[name].select_set(True)
global_id = bpy.data.objects[name].BIMAttributeProperties.attributes[0].string_value
# Căutăm obiectul IFC în fișierul activ după GlobalId
ifc_object = model.by_id(global_id)
layout.label(text=f"Selected Object: {ifc_object.Name}")
layout.separator()
# Afișăm atributele obiectului IFC
layout.label(text="Attributes:")
row = layout.row()
row.label(text="Name")
row.label(text="Value")
self.add_properties_to_layout(layout, ifc_object.get_info())
layout.separator()
# Afișăm proprietățile (Psets) obiectului IFC
layout.label(text="Properties (Psets):")
row = layout.row()
row.label(text="Name")
row.label(text="Value")
psets = ifcopenshell.util.element.get_psets(ifc_object)
for pset_name, pset_props in psets.items():
layout.label(text=f"Pset: {pset_name}")
self.add_properties_to_layout(layout, pset_props)
layout.separator()
else:
layout.label(text="Select one IFC object before displaying properties.")
def add_properties_to_layout(self, layout, properties):
for name, value in properties.items():
if isinstance(value, dict):
row = layout.row()
row.label(text=f"{name}:")
row.label(text="Complex")
self.add_properties_to_layout(layout, value)
else:
row = layout.row()
row.label(text=name)
row.label(text=str(value))
def register():
bpy.utils.register_class(OBJECT_PT_IFCPropertiesPanel)
def unregister():
bpy.utils.unregister_class(OBJECT_PT_IFCPropertiesPanel)
if __name__ == "__main__":
register()