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,21 +124,24 @@ 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()
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
ifcopenshell.api.run( for obj in objs:
"material.assign_material", if not obj.BIMObjectProperties.ifc_definition_id:
self.file, continue
**{ material_type = self.material_type or obj.BIMObjectMaterialProperties.material_type
"product": element, element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
"type": material_type, ifcopenshell.api.run(
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)), "material.assign_material",
}, self.file,
) **{
Data.load(IfcStore.get_file()) "product": element,
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id) "type": material_type,
"material": self.file.by_id(int(obj.BIMObjectMaterialProperties.material)),
},
)
Data.load(IfcStore.get_file())
Data.load(IfcStore.get_file(), obj.BIMObjectProperties.ifc_definition_id)
return {"FINISHED"} return {"FINISHED"}
@@ -152,13 +155,16 @@ 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()
ifcopenshell.api.run( objs = [bpy.data.objects.get(self.obj)] if self.obj else context.selected_objects
"material.unassign_material", for obj in objs:
self.file, if not obj.BIMObjectProperties.ifc_definition_id:
**{"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)}, continue
) ifcopenshell.api.run(
"material.unassign_material",
self.file,
**{"product": self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)},
)
Data.purge() Data.purge()
return {"FINISHED"} return {"FINISHED"}