mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 09:21:46 +00:00
Fix styles UI breaking on undo
Turn out storing bpy.types.PropetyGroups was not very reliable idea as they get invalidated, just as Objects. It's still breaking if you'd try to rename the style and then undo.
This commit is contained in:
@@ -44,14 +44,14 @@ class StylesData:
|
||||
cls.is_loaded = True
|
||||
|
||||
@classmethod
|
||||
def styles_to_blender_material_names(cls) -> dict[bpy.types.PropertyGroup, Union[str, None]]:
|
||||
def styles_to_blender_material_names(cls) -> list[Union[str, None]]:
|
||||
ifc_file = tool.Ifc.get()
|
||||
props = bpy.context.scene.BIMStylesProperties
|
||||
materials: dict[bpy.types.PropertyGroup, Union[str, None]] = {}
|
||||
materials: list[Union[str, None]] = []
|
||||
for style in props.styles:
|
||||
material = tool.Ifc.get_object(ifc_file.by_id(style.ifc_definition_id))
|
||||
# Material will be None if it's not IfcSurfaceStyle.
|
||||
materials[style] = material.name if material is not None else None
|
||||
materials.append(material.name if material is not None else None)
|
||||
return materials
|
||||
|
||||
@classmethod
|
||||
|
||||
@@ -95,7 +95,7 @@ class BIM_PT_styles(Panel):
|
||||
# style ui tools
|
||||
if active_style:
|
||||
row = self.layout.row(align=True)
|
||||
material_name = StylesData.data["styles_to_blender_material_names"][style]
|
||||
material_name = StylesData.data["styles_to_blender_material_names"][self.props.active_style_index]
|
||||
if material_name: # The user may have unlinked the style, so the material may not exist
|
||||
material = bpy.data.materials[material_name]
|
||||
row.prop(material.BIMStyleProperties, "active_style_type", icon="SHADING_RENDERED", text="")
|
||||
@@ -265,10 +265,10 @@ class BIM_PT_styles(Panel):
|
||||
|
||||
|
||||
class BIM_UL_styles(UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
|
||||
if item:
|
||||
row = layout.row(align=True)
|
||||
material_name: Union[str, None] = StylesData.data["styles_to_blender_material_names"][item]
|
||||
material_name: Union[str, None] = StylesData.data["styles_to_blender_material_names"][index]
|
||||
material_icon = 0
|
||||
if material_name and (material := bpy.data.materials.get(material_name)):
|
||||
preview = material.preview_ensure()
|
||||
|
||||
Reference in New Issue
Block a user