Skip to content

Commit ee8fa67

Browse files
committed
v2 stuff
1 parent 7bd633c commit ee8fa67

File tree

4 files changed

+145
-4
lines changed

4 files changed

+145
-4
lines changed

__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"author" : "bii",
1717
"description" : "",
1818
"blender" : (2, 80, 0),
19-
"version" : (0, 0, 1),
19+
"version" : (0, 0, 2),
2020
"location" : "",
2121
"warning" : "",
2222
"category" : "BII Tools"
@@ -27,20 +27,26 @@
2727
from . import bulk_assign_ifc_class
2828
from . import bulk_material_dropdown
2929
from . import add_ifc_property
30+
from . import clean_reduce_ifc
31+
from . import upgrade_to_IFC4
3032

3133
def register():
3234
close_mesh_holes.register()
3335
bii_functions_panel.register()
3436
bulk_assign_ifc_class.register()
3537
bulk_material_dropdown.register()
3638
add_ifc_property.register()
39+
clean_reduce_ifc.register()
40+
# upgrade_to_IFC4.register()
3741

3842
def unregister():
3943
close_mesh_holes.unregister()
4044
bii_functions_panel.unregister()
4145
bulk_assign_ifc_class.unregister()
4246
bulk_material_dropdown.unregister()
4347
add_ifc_property.unregister()
48+
clean_reduce_ifc.unregister()
49+
# upgrade_to_IFC4.unregister()
4450

4551
if __name__ == "__main__":
4652
register()

bii_functions_panel.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,27 @@ def draw(self, context):
1919
layout.operator("object.close_mesh_holes_operator")
2020

2121
layout.prop(context.scene, "bulk_material", text="Bulk Material")
22-
2322
layout.operator("object.set_ifc_class_for_bulk_operator")
24-
2523
layout.operator("object.set_ifc_group_property_operator")
2624

25+
layout.label(text="Clean and reduce IFC")
26+
27+
# layout.operator("object.upgrade_ifc_operator")
28+
29+
layout.prop(context.window_manager, "decimate_ratio", text="Decimate Ratio")
30+
layout.operator("object.clean_reduce_ifc_operator")
31+
layout.label(text="Progress:")
32+
layout.label(text=context.scene.clean_progress)
33+
2734

2835
def register():
2936
bpy.utils.register_class(BiiFunctionsPanel)
37+
bpy.types.WindowManager.decimate_ratio = bpy.props.FloatProperty(
38+
name="Decimate Ratio",
39+
default=1.0, min=0.1, max=1.0)
40+
bpy.types.Scene.clean_progress = bpy.props.StringProperty(default="Ready to clean and reduce IFC")
3041

3142
def unregister():
32-
bpy.utils.unregister_class(BiiFunctionsPanel)
43+
bpy.utils.unregister_class(BiiFunctionsPanel)
44+
del bpy.types.WindowManager.decimate_ratio
45+
del bpy.types.Scene.clean_progress

clean_reduce_ifc.py

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import bpy
2+
3+
class CleanReduceIfcOperator(bpy.types.Operator):
4+
"""Clean and reduce IFC"""
5+
bl_idname = "object.clean_reduce_ifc_operator"
6+
bl_label = "Clean and Reduce IFC"
7+
bl_options = {'REGISTER', 'UNDO'}
8+
9+
def execute(self, context):
10+
clean_reduce_ifc(self, context)
11+
self.report({'INFO'}, "IFC Clean and Reduce Completed")
12+
return {'FINISHED'}
13+
14+
def clean_and_link_mesh_data(context):
15+
# Check if there are selected objects
16+
if not context.selected_objects:
17+
print("No objects selected. Exiting function.")
18+
return # Exit the function if no objects are selected
19+
20+
# Check if there's an active object; if not, set the first selected object as active
21+
if not context.active_object or context.active_object not in context.selected_objects:
22+
context.view_layer.objects.active = context.selected_objects[0]
23+
24+
# A dictionary to track original mesh data and their objects
25+
mesh_to_objects = {}
26+
for obj in bpy.context.selected_objects:
27+
if obj.type == 'MESH':
28+
if obj.data not in mesh_to_objects:
29+
mesh_to_objects[obj.data] = [obj]
30+
else:
31+
mesh_to_objects[obj.data].append(obj)
32+
33+
total_objects = len(context.selected_objects)
34+
processed_objects = 0
35+
36+
# Ensure we're in object mode to start
37+
bpy.ops.object.mode_set(mode='OBJECT')
38+
39+
# Process each unique mesh data block
40+
for mesh_data, objects in mesh_to_objects.items():
41+
original_object = objects[0] # Select the first object for modification
42+
43+
# Ensure the object has a unique mesh data block
44+
original_object.data = original_object.data.copy()
45+
46+
# Make the original object active
47+
bpy.context.view_layer.objects.active = original_object
48+
49+
# Ensure all objects are deselected before selecting the active object
50+
bpy.ops.object.select_all(action='DESELECT')
51+
original_object.select_set(True)
52+
53+
# Enter Edit mode and select all vertices
54+
bpy.ops.object.mode_set(mode='EDIT')
55+
bpy.ops.mesh.select_all(action='SELECT')
56+
57+
# Apply the necessary mesh operations
58+
bpy.ops.mesh.remove_doubles()
59+
bpy.ops.mesh.dissolve_limited(angle_limit=0.0872665) # Example angle limit
60+
61+
# Go back to Object mode
62+
bpy.ops.object.mode_set(mode='OBJECT')
63+
64+
# Add and apply the Decimate modifier
65+
mod = original_object.modifiers.new(name="DecimateMod", type='DECIMATE')
66+
mod.ratio = context.window_manager.decimate_ratio
67+
bpy.ops.object.modifier_apply(modifier=mod.name)
68+
69+
# Link the modified mesh data to the other objects
70+
for other_object in objects[1:]: # Skip the first object since it's already modified
71+
other_object.data = original_object.data
72+
73+
processed_objects += 1
74+
75+
# Update progress message every 10 objects
76+
if processed_objects % 15 == 0 or processed_objects == total_objects:
77+
progress_message = f"Processing {processed_objects} of {total_objects} objects..."
78+
context.scene.clean_progress = progress_message
79+
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
80+
81+
# Clear the status text when done
82+
context.scene.clean_progress = "Ready to clean and reduce IFC"
83+
bpy.context.workspace.status_text_set(None)
84+
85+
def clean_reduce_ifc(self, context):
86+
clean_and_link_mesh_data(context)
87+
88+
def register():
89+
bpy.utils.register_class(CleanReduceIfcOperator)
90+
91+
def unregister():
92+
bpy.utils.unregister_class(CleanReduceIfcOperator)
93+
94+
if __name__ == "__main__":
95+
register()

upgrade_to_IFC4.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import bpy
2+
from blenderbim.bim.ifc import IfcStore
3+
import ifcpatch
4+
import ifcopenshell
5+
6+
def upgrade_IFC4(self, context):
7+
# Upgrade the IFC file to IFC4
8+
# Get the active IFC file
9+
ifc_file = IfcStore.get_file()
10+
if not ifc_file:
11+
print("No IFC file found. Ensure you're working in a BlenderBIM project.")
12+
return
13+
ifc_file.upgrade("IFC4")
14+
15+
class UpgradeIFC4Operator(bpy.types.Operator):
16+
bl_idname = "object.upgrade_ifc_operator"
17+
bl_label = "Upgrade to IFC4"
18+
19+
def execute(self, context):
20+
upgrade_IFC4(self, context)
21+
return {'FINISHED'}
22+
23+
def register():
24+
bpy.utils.register_class(UpgradeIFC4Operator)
25+
26+
def unregister():
27+
bpy.utils.unregister_class(UpgradeIFC4Operator)

0 commit comments

Comments
 (0)