From 7bd633c0fc2192f78c4efd81134891af80c94fb4 Mon Sep 17 00:00:00 2001 From: Jonas Date: Fri, 15 Mar 2024 10:13:16 +0100 Subject: [PATCH] Added function to create IFC Attribute groupings to be used in dProB in inport grouping --- __init__.py | 3 +++ add_ifc_property.py | 61 ++++++++++++++++++++++++++++++++++++++++++ bii_functions_panel.py | 2 ++ 3 files changed, 66 insertions(+) create mode 100644 add_ifc_property.py diff --git a/__init__.py b/__init__.py index 12c14bf..9326c16 100644 --- a/__init__.py +++ b/__init__.py @@ -26,18 +26,21 @@ from . import bii_functions_panel from . import bulk_assign_ifc_class from . import bulk_material_dropdown +from . import add_ifc_property def register(): close_mesh_holes.register() bii_functions_panel.register() bulk_assign_ifc_class.register() bulk_material_dropdown.register() + add_ifc_property.register() def unregister(): close_mesh_holes.unregister() bii_functions_panel.unregister() bulk_assign_ifc_class.unregister() bulk_material_dropdown.unregister() + add_ifc_property.unregister() if __name__ == "__main__": register() \ No newline at end of file diff --git a/add_ifc_property.py b/add_ifc_property.py new file mode 100644 index 0000000..8fc8dcb --- /dev/null +++ b/add_ifc_property.py @@ -0,0 +1,61 @@ +import bpy +import ifcopenshell +import blenderbim +from blenderbim.bim.ifc import IfcStore +import blenderbim.tool as tool +from blenderbim.bim.module.pset.data import Data as PsetData +import bmesh + +# Global counter for group naming +group_counter = 0 + +def set_ifc_property(self, context, property_name): + + global group_counter # Reference the global counter + + # Increment the group counter + group_counter += 1 + property_name = f"Group#{group_counter}" # Update property_name with incremented counter + + # Get the active IFC file + ifc_file = IfcStore.get_file() + if not ifc_file: + print("No IFC file found. Ensure you're working in a BlenderBIM project.") + return + + # Loop through all selected objects + for obj in bpy.context.selected_objects: + if obj.type == 'MESH': + + # Set the active object + bpy.context.view_layer.objects.active = obj + # get the ifc object + ifc_obj = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id) + # check if the object is valid + if not ifc_obj: + print(f"Object {obj.name} has no IFC object.") + continue + pset = ifcopenshell.api.run("pset.add_pset", ifc_file, product=ifc_obj, name="Custom_dProB_Grouping") + + # Set the properties of the Pset + new_values = { + "Grouping": property_name, + } + ifcopenshell.api.run("pset.edit_pset", ifc_file, pset=pset, properties=new_values) + + +class SetIfcPropForGroup(bpy.types.Operator): + """Set custom ifc property for grouping""" + bl_idname = "object.set_ifc_group_property_operator" + bl_label = "Set Group Property for selected" + + def execute(self, context): + set_ifc_property(self, context, None) + return {'FINISHED'} + + +def register(): + bpy.utils.register_class(SetIfcPropForGroup) + +def unregister(): + bpy.utils.unregister_class(SetIfcPropForGroup) \ No newline at end of file diff --git a/bii_functions_panel.py b/bii_functions_panel.py index 9f90670..9ef58f7 100644 --- a/bii_functions_panel.py +++ b/bii_functions_panel.py @@ -22,6 +22,8 @@ def draw(self, context): layout.operator("object.set_ifc_class_for_bulk_operator") + layout.operator("object.set_ifc_group_property_operator") + def register(): bpy.utils.register_class(BiiFunctionsPanel)