@@ -174,67 +174,7 @@ class AssignMaterial(bpy.types.Operator, tool.Ifc.Operator):
174174
175175 def _execute (self , context ):
176176 objects = [bpy .data .objects .get (self .obj )] if self .obj else tool .Blender .get_selected_objects ()
177- active_obj = context .active_object
178- active_object_material_type = self .material_type or active_obj .BIMObjectMaterialProperties .material_type
179- material = tool .Ifc .get ().by_id (int (active_obj .BIMObjectMaterialProperties .material ))
180- for obj in objects :
181- element = tool .Ifc .get_entity (obj )
182- if not element :
183- continue
184- ifcopenshell .api .run (
185- "material.assign_material" ,
186- tool .Ifc .get (),
187- product = element ,
188- type = active_object_material_type ,
189- material = material ,
190- )
191- assigned_material = ifcopenshell .util .element .get_material (element )
192- if assigned_material .is_a ("IfcMaterialConstituentSet" ):
193- if not assigned_material .MaterialConstituents :
194- ifcopenshell .api .run (
195- "material.add_constituent" ,
196- tool .Ifc .get (),
197- constituent_set = assigned_material ,
198- material = material ,
199- )
200- elif assigned_material .is_a () == "IfcMaterialLayerSet" :
201- if not assigned_material .MaterialLayers :
202- unit_scale = ifcopenshell .util .unit .calculate_unit_scale (tool .Ifc .get ())
203- layer = ifcopenshell .api .run (
204- "material.add_layer" ,
205- tool .Ifc .get (),
206- layer_set = assigned_material ,
207- material = material ,
208- )
209- thickness = 0.1 # Arbitrary metric thickness for now
210- layer .LayerThickness = thickness / unit_scale
211- elif assigned_material .is_a ("IfcMaterialProfileSet" ):
212- if not assigned_material .MaterialProfiles :
213- named_profiles = [p for p in tool .Ifc .get ().by_type ("IfcProfileDef" ) if p .ProfileName ]
214- if named_profiles :
215- profile = named_profiles [0 ]
216- else :
217- unit_scale = ifcopenshell .util .unit .calculate_unit_scale (tool .Ifc .get ())
218- size = 0.5 / unit_scale
219- profile = tool .Ifc .get ().create_entity (
220- "IfcRectangleProfileDef" ,
221- ProfileName = "New Profile" ,
222- ProfileType = "AREA" ,
223- XDim = size ,
224- YDim = size ,
225- )
226- material_profile = ifcopenshell .api .run (
227- "material.add_profile" ,
228- tool .Ifc .get (),
229- profile_set = assigned_material ,
230- material = tool .Ifc .get ().by_type ("IfcMaterial" )[0 ],
231- )
232- ifcopenshell .api .run (
233- "material.assign_profile" ,
234- tool .Ifc .get (),
235- material_profile = material_profile ,
236- profile = profile ,
237- )
177+ core .assign_material (tool .Ifc , tool .Material , material_type = self .material_type , objects = objects )
238178
239179
240180class UnassignMaterial (bpy .types .Operator , tool .Ifc .Operator ):
@@ -245,20 +185,7 @@ class UnassignMaterial(bpy.types.Operator, tool.Ifc.Operator):
245185
246186 def _execute (self , context ):
247187 objects = [bpy .data .objects .get (self .obj )] if self .obj else tool .Blender .get_selected_objects ()
248- for obj in objects :
249- element = tool .Ifc .get_entity (obj )
250- if element :
251- material = ifcopenshell .util .element .get_material (element , should_inherit = False )
252- inherited_material = ifcopenshell .util .element .get_material (element , should_inherit = True )
253- print (material , inherited_material )
254- if material and "Usage" in material .is_a ():
255- element_type = ifcopenshell .util .element .get_type (element )
256- ifcopenshell .api .run ("material.unassign_material" , tool .Ifc .get (), product = element_type )
257- elif not material and inherited_material :
258- element_type = ifcopenshell .util .element .get_type (element )
259- ifcopenshell .api .run ("material.unassign_material" , tool .Ifc .get (), product = element_type )
260- elif material :
261- ifcopenshell .api .run ("material.unassign_material" , tool .Ifc .get (), product = element )
188+ core .unassign_material (tool .Ifc , tool .Material , objects = objects )
262189
263190
264191class AddConstituent (bpy .types .Operator , tool .Ifc .Operator ):
0 commit comments