11import bpy
22import numpy as np
33import ifcopenshell
4- import blenderbim .bim .module .root .assign_class as assign_class
4+ import blenderbim .bim .module .root .create_product as create_product
5+ import blenderbim .bim .module .root .remove_product as remove_product
6+ import blenderbim .bim .module .root .reassign_class as reassign_class
57import blenderbim .bim .module .geometry .add_representation as add_representation
68import blenderbim .bim .module .geometry .assign_styles as assign_styles
79import blenderbim .bim .module .geometry .assign_representation as assign_representation
1113# from blenderbim.bim.module.geometry.data import Data
1214
1315
14- class ReassignClass (bpy .types .Operator ):
15- bl_idname = "bim.reassign_class "
16- bl_label = "Reassign IFC Class"
16+ class EnableReassignClass (bpy .types .Operator ):
17+ bl_idname = "bim.enable_reassign_class "
18+ bl_label = "Enable Reassign IFC Class"
1719
1820 def execute (self , context ):
1921 obj = bpy .context .active_object
@@ -40,6 +42,40 @@ def execute(self, context):
4042 return {"FINISHED" }
4143
4244
45+ class DisableReassignClass (bpy .types .Operator ):
46+ bl_idname = "bim.disable_reassign_class"
47+ bl_label = "Disable Reassign IFC Class"
48+
49+ def execute (self , context ):
50+ bpy .context .active_object .BIMObjectProperties .is_reassigning_class = False
51+ return {"FINISHED" }
52+
53+
54+ class ReassignClass (bpy .types .Operator ):
55+ bl_idname = "bim.reassign_class"
56+ bl_label = "Reassign IFC Class"
57+
58+ def execute (self , context ):
59+ obj = bpy .context .active_object
60+ self .file = IfcStore .get_file ()
61+ predefined_type = bpy .context .scene .BIMProperties .ifc_predefined_type
62+ if predefined_type == "USERDEFINED" :
63+ predefined_type = bpy .context .scene .BIMProperties .ifc_userdefined_type
64+ usecase = reassign_class .Usecase (
65+ self .file ,
66+ {
67+ "product" : self .file .by_id (obj .BIMObjectProperties .ifc_definition_id ),
68+ "ifc_class" : bpy .context .scene .BIMProperties .ifc_class ,
69+ "predefined_type" : predefined_type ,
70+ },
71+ )
72+ product = usecase .execute ()
73+ obj .name = "{}/{}" .format (product .is_a (), "/" .join (obj .name .split ("/" )[1 :]))
74+ obj .BIMObjectProperties .ifc_definition_id = int (product .id ())
75+ bpy .context .active_object .BIMObjectProperties .is_reassigning_class = False
76+ return {"FINISHED" }
77+
78+
4379class AssignClass (bpy .types .Operator ):
4480 bl_idname = "bim.assign_class"
4581 bl_label = "Assign IFC Class"
@@ -51,11 +87,14 @@ def execute(self, context):
5187 for obj in objects :
5288 if obj .BIMObjectProperties .ifc_definition_id :
5389 continue
54- usecase = assign_class .Usecase (
90+ predefined_type = bpy .context .scene .BIMProperties .ifc_predefined_type
91+ if predefined_type == "USERDEFINED" :
92+ predefined_type = bpy .context .scene .BIMProperties .ifc_userdefined_type
93+ usecase = create_product .Usecase (
5594 self .file ,
5695 {
5796 "ifc_class" : bpy .context .scene .BIMProperties .ifc_class ,
58- "predefined_type" : bpy . context . scene . BIMProperties . ifc_predefined_type ,
97+ "predefined_type" : predefined_type ,
5998 "name" : obj .name ,
6099 },
61100 )
@@ -124,12 +163,20 @@ class UnassignClass(bpy.types.Operator):
124163 object_name : bpy .props .StringProperty ()
125164
126165 def execute (self , context ):
166+ self .file = IfcStore .get_file ()
127167 if self .object_name :
128168 objects = [bpy .data .objects .get (self .object_name )]
129169 else :
130170 objects = bpy .context .selected_objects
131171 for obj in objects :
132- existing_class = None
172+ if not obj .BIMObjectProperties .ifc_definition_id :
173+ continue
174+ usecase = remove_product .Usecase (
175+ self .file ,
176+ {"product" : self .file .by_id (obj .BIMObjectProperties .ifc_definition_id )},
177+ )
178+ usecase .execute ()
179+ obj .BIMObjectProperties .ifc_definition_id = 0
133180 if "/" in obj .name and obj .name [0 :3 ] == "Ifc" :
134181 obj .name = "/" .join (obj .name .split ("/" )[1 :])
135182 return {"FINISHED" }
0 commit comments