Skip to content

Commit

Permalink
Added function to create IFC Attribute groupings to be used in dProB …
Browse files Browse the repository at this point in the history
…in inport grouping
  • Loading branch information
JoWolp committed Mar 15, 2024
1 parent 47f1a9b commit 7bd633c
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
3 changes: 3 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
61 changes: 61 additions & 0 deletions add_ifc_property.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions bii_functions_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7bd633c

Please sign in to comment.