mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
fix ui error getting active styles for non IfcMaterial materials
Error was:
```
Traceback (most recent call last):
File "\blenderbim\bim\module\material\ui.py", line 43, in draw
MaterialsData.load()
File "\blenderbim\bim\module\material\data.py", line 43, in load
"active_styles": cls.active_styles(),
^^^^^^^^^^^^^^^^^^^
File "\blenderbim\bim\module\material\data.py", line 117, in active_styles
return results
File "\blenderbim\libs\site\packages\ifcopenshell\entity_instance.py", line 194, in __getattr__
raise AttributeError(
AttributeError: entity instance of type 'IFC4.IfcMaterialLayerSet' has no attribute 'HasRepresentation'
```
This commit is contained in:
@@ -110,29 +110,38 @@ class MaterialsData:
|
|||||||
def active_styles(cls):
|
def active_styles(cls):
|
||||||
props = bpy.context.scene.BIMMaterialProperties
|
props = bpy.context.scene.BIMMaterialProperties
|
||||||
results = []
|
results = []
|
||||||
if props.materials and props.active_material_index < len(props.materials):
|
if not props.materials or props.active_material_index >= len(props.materials):
|
||||||
material = props.materials[props.active_material_index].ifc_definition_id
|
return results
|
||||||
if not material:
|
|
||||||
return results
|
material = props.materials[props.active_material_index].ifc_definition_id
|
||||||
material = tool.Ifc.get().by_id(material)
|
if not material:
|
||||||
for definition in material.HasRepresentation:
|
return results
|
||||||
for representation in definition.Representations:
|
|
||||||
if not representation.is_a("IfcStyledRepresentation"):
|
material = tool.Ifc.get().by_id(material)
|
||||||
|
|
||||||
|
if not material.is_a("IfcMaterial"):
|
||||||
|
return results
|
||||||
|
|
||||||
|
for definition in material.HasRepresentation:
|
||||||
|
for representation in definition.Representations:
|
||||||
|
if not representation.is_a("IfcStyledRepresentation"):
|
||||||
|
continue
|
||||||
|
context = representation.ContextOfItems
|
||||||
|
for item in representation.Items:
|
||||||
|
if not item.is_a("IfcStyledItem"):
|
||||||
continue
|
continue
|
||||||
context = representation.ContextOfItems
|
for style in item.Styles:
|
||||||
for item in representation.Items:
|
if style.is_a("IfcSurfaceStyle"):
|
||||||
if not item.is_a("IfcStyledItem"):
|
results.append(
|
||||||
continue
|
{
|
||||||
for style in item.Styles:
|
|
||||||
if style.is_a("IfcSurfaceStyle"):
|
|
||||||
results.append({
|
|
||||||
"context_type": context.ContextType,
|
"context_type": context.ContextType,
|
||||||
"context_identifier": getattr(context, "ContextIdentifier", ""),
|
"context_identifier": getattr(context, "ContextIdentifier", ""),
|
||||||
"target_view": getattr(context, "TargetView", ""),
|
"target_view": getattr(context, "TargetView", ""),
|
||||||
"name": style.Name or "Unnamed",
|
"name": style.Name or "Unnamed",
|
||||||
"id": style.id(),
|
"id": style.id(),
|
||||||
"context_id": context.id(),
|
"context_id": context.id(),
|
||||||
})
|
}
|
||||||
|
)
|
||||||
return results
|
return results
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user