Assign / Unassign Material executes on all selected objects

This commit is contained in:
Gorgious
2021-08-24 13:39:50 +02:00
parent eb9d75c403
commit b149e8c218
@@ -124,9 +124,12 @@ class AssignMaterial(bpy.types.Operator):
return IfcStore.execute_ifc_operator(self, context) return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context): def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
material_type = self.material_type or obj.BIMObjectMaterialProperties.material_type
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
for obj in objs:
if not obj.BIMObjectProperties.ifc_definition_id:
continue
material_type = self.material_type or obj.BIMObjectMaterialProperties.material_type
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
ifcopenshell.api.run( ifcopenshell.api.run(
"material.assign_material", "material.assign_material",
@@ -152,8 +155,11 @@ class UnassignMaterial(bpy.types.Operator):
return IfcStore.execute_ifc_operator(self, context) return IfcStore.execute_ifc_operator(self, context)
def _execute(self, context): def _execute(self, context):
obj = bpy.data.objects.get(self.obj) if self.obj else context.active_object
self.file = IfcStore.get_file() self.file = IfcStore.get_file()
objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
for obj in objs:
if not obj.BIMObjectProperties.ifc_definition_id:
continue
ifcopenshell.api.run( ifcopenshell.api.run(
"material.unassign_material", "material.unassign_material",
self.file, self.file,