mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-21 10:53:46 +00:00
Handle null Styles when loading surface styles
An IfcSurfaceStyle with a NULL Styles set raised a TypeError when loading a project. Guard the iterations, matching the existing defensive pattern in import_presentation_styles. Generated with the assistance of an AI coding tool.
This commit is contained in:
@@ -190,7 +190,7 @@ class Style(bonsai.core.tool.Style):
|
|||||||
else:
|
else:
|
||||||
style = blender_material_or_style
|
style = blender_material_or_style
|
||||||
style_elements = {}
|
style_elements = {}
|
||||||
for style_ in style.Styles:
|
for style_ in style.Styles or []:
|
||||||
style_elements[style_.is_a()] = style_
|
style_elements[style_.is_a()] = style_
|
||||||
return style_elements
|
return style_elements
|
||||||
|
|
||||||
@@ -516,14 +516,14 @@ class Style(bonsai.core.tool.Style):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def get_surface_shading_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
|
def get_surface_shading_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
if style := tool.Ifc.get_entity(obj):
|
if style := tool.Ifc.get_entity(obj):
|
||||||
items = [s for s in style.Styles if s.is_a() == "IfcSurfaceStyleShading"]
|
items = [s for s in (style.Styles or []) if s.is_a() == "IfcSurfaceStyleShading"]
|
||||||
if items:
|
if items:
|
||||||
return items[0]
|
return items[0]
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_surface_texture_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
|
def get_surface_texture_style(cls, obj: bpy.types.Material) -> Union[ifcopenshell.entity_instance, None]:
|
||||||
if style := tool.Ifc.get_entity(obj):
|
if style := tool.Ifc.get_entity(obj):
|
||||||
items = [s for s in style.Styles if s.is_a("IfcSurfaceStyleWithTextures")]
|
items = [s for s in (style.Styles or []) if s.is_a("IfcSurfaceStyleWithTextures")]
|
||||||
if items:
|
if items:
|
||||||
return items[0]
|
return items[0]
|
||||||
|
|
||||||
|
|||||||
@@ -393,6 +393,19 @@ class TestGetUVMaps(NewFile):
|
|||||||
assert subject.get_uv_maps(representation) == [uv_map]
|
assert subject.get_uv_maps(representation) == [uv_map]
|
||||||
|
|
||||||
|
|
||||||
|
class TestGetStyleElements(NewFile):
|
||||||
|
def test_style_with_null_styles(self):
|
||||||
|
style = ifcopenshell.file().create_entity("IfcSurfaceStyle", "Name", "BOTH", None)
|
||||||
|
assert subject.get_style_elements(style) == {}
|
||||||
|
|
||||||
|
def test_material_with_null_styles(self):
|
||||||
|
tool.Ifc.set(ifc := ifcopenshell.file())
|
||||||
|
style = ifc.create_entity("IfcSurfaceStyle", "Name", "BOTH", None)
|
||||||
|
material = bpy.data.materials.new("Material")
|
||||||
|
tool.Ifc.link(style, material)
|
||||||
|
assert subject.get_style_elements(material) == {}
|
||||||
|
|
||||||
|
|
||||||
class TestImportSurfaceAttributes(NewFile):
|
class TestImportSurfaceAttributes(NewFile):
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
tool.Ifc.set(ifc := ifcopenshell.file())
|
tool.Ifc.set(ifc := ifcopenshell.file())
|
||||||
|
|||||||
Reference in New Issue
Block a user