Fix bug where empty material slots caused errors

This commit is contained in:
Dion Moult
2021-05-08 08:57:33 +10:00
parent f9b79b4beb
commit 46bc688f26
2 changed files with 2 additions and 6 deletions
@@ -122,7 +122,7 @@ class AddRepresentation(bpy.types.Operator):
[
bpy.ops.bim.add_style(material=s.material.name)
for s in obj.material_slots
if not s.material.BIMMaterialProperties.ifc_style_id
if s.material and not s.material.BIMMaterialProperties.ifc_style_id
]
ifcopenshell.api.run(
@@ -76,7 +76,7 @@ class ReassignClass(bpy.types.Operator):
class AssignClass(bpy.types.Operator):
bl_idname = "bim.assign_class"
bl_label = "Assign IFC Class"
bl_options = {'REGISTER', 'UNDO'}
bl_options = {"REGISTER", "UNDO"}
obj: bpy.props.StringProperty()
ifc_class: bpy.props.StringProperty()
predefined_type: bpy.props.StringProperty()
@@ -92,10 +92,6 @@ class AssignClass(bpy.types.Operator):
elif self.predefined_type == "":
predefined_type = None
for obj in objects:
if obj.data and hasattr(obj.data, "materials"):
for material in obj.data.materials:
if not material.BIMMaterialProperties.ifc_style_id:
bpy.ops.bim.add_style(material=material.name)
self.assign_class(context, obj)
return {"FINISHED"}