1+ import bpy
2+ import ifcopenshell
3+ import blenderbim
4+ from blenderbim .bim .ifc import IfcStore
5+ import blenderbim .tool as tool
6+ from blenderbim .bim .module .pset .data import Data as PsetData
7+ import bmesh
8+
9+ # Global counter for group naming
10+ group_counter = 0
11+
12+ def set_ifc_property (self , context , property_name ):
13+
14+ global group_counter # Reference the global counter
15+
16+ # Increment the group counter
17+ group_counter += 1
18+ property_name = f"Group#{ group_counter } " # Update property_name with incremented counter
19+
20+ # Get the active IFC file
21+ ifc_file = IfcStore .get_file ()
22+ if not ifc_file :
23+ print ("No IFC file found. Ensure you're working in a BlenderBIM project." )
24+ return
25+
26+ # Loop through all selected objects
27+ for obj in bpy .context .selected_objects :
28+ if obj .type == 'MESH' :
29+
30+ # Set the active object
31+ bpy .context .view_layer .objects .active = obj
32+ # get the ifc object
33+ ifc_obj = IfcStore .get_file ().by_id (obj .BIMObjectProperties .ifc_definition_id )
34+ # check if the object is valid
35+ if not ifc_obj :
36+ print (f"Object { obj .name } has no IFC object." )
37+ continue
38+ pset = ifcopenshell .api .run ("pset.add_pset" , ifc_file , product = ifc_obj , name = "Custom_dProB_Grouping" )
39+
40+ # Set the properties of the Pset
41+ new_values = {
42+ "Grouping" : property_name ,
43+ }
44+ ifcopenshell .api .run ("pset.edit_pset" , ifc_file , pset = pset , properties = new_values )
45+
46+
47+ class SetIfcPropForGroup (bpy .types .Operator ):
48+ """Set custom ifc property for grouping"""
49+ bl_idname = "object.set_ifc_group_property_operator"
50+ bl_label = "Set Group Property for selected"
51+
52+ def execute (self , context ):
53+ set_ifc_property (self , context , None )
54+ return {'FINISHED' }
55+
56+
57+ def register ():
58+ bpy .utils .register_class (SetIfcPropForGroup )
59+
60+ def unregister ():
61+ bpy .utils .unregister_class (SetIfcPropForGroup )
0 commit comments