Skip to content

Commit 7bd633c

Browse files
committed
Added function to create IFC Attribute groupings to be used in dProB in inport grouping
1 parent 47f1a9b commit 7bd633c

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,21 @@
2626
from . import bii_functions_panel
2727
from . import bulk_assign_ifc_class
2828
from . import bulk_material_dropdown
29+
from . import add_ifc_property
2930

3031
def register():
3132
close_mesh_holes.register()
3233
bii_functions_panel.register()
3334
bulk_assign_ifc_class.register()
3435
bulk_material_dropdown.register()
36+
add_ifc_property.register()
3537

3638
def unregister():
3739
close_mesh_holes.unregister()
3840
bii_functions_panel.unregister()
3941
bulk_assign_ifc_class.unregister()
4042
bulk_material_dropdown.unregister()
43+
add_ifc_property.unregister()
4144

4245
if __name__ == "__main__":
4346
register()

add_ifc_property.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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)

bii_functions_panel.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ def draw(self, context):
2222

2323
layout.operator("object.set_ifc_class_for_bulk_operator")
2424

25+
layout.operator("object.set_ifc_group_property_operator")
26+
2527

2628
def register():
2729
bpy.utils.register_class(BiiFunctionsPanel)

0 commit comments

Comments
 (0)