diff --git a/src/bonsai/bonsai/bim/module/style/data.py b/src/bonsai/bonsai/bim/module/style/data.py index 2866ba8c64..f2d6ea1402 100644 --- a/src/bonsai/bonsai/bim/module/style/data.py +++ b/src/bonsai/bonsai/bim/module/style/data.py @@ -50,7 +50,7 @@ class StylesData: materials: dict[bpy.types.PropertyGroup, 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 either unlinked or if it's not IfcSurfaceStyle. + # Material will be None if it's not IfcSurfaceStyle. materials[style] = material.name if material is not None else None return materials diff --git a/src/bonsai/bonsai/bim/module/style/operator.py b/src/bonsai/bonsai/bim/module/style/operator.py index c829e13697..3bea090594 100644 --- a/src/bonsai/bonsai/bim/module/style/operator.py +++ b/src/bonsai/bonsai/bim/module/style/operator.py @@ -98,7 +98,7 @@ class UnlinkStyle(bpy.types.Operator, tool.Ifc.Operator): bl_description = ( "Unlink Blender material from it's linked IFC style.\n\n" "You can either remove style the material is linked to from IFC or keep it. " - "Note that keeping the unlinked style in IFC might lead to unpredictable issues " + "Note that keeping the style in IFC might lead to unpredictable issues " "and should be used only by advanced users" ) bl_options = {"REGISTER", "UNDO"} @@ -125,17 +125,22 @@ class UnlinkStyle(bpy.types.Operator, tool.Ifc.Operator): tool.Ifc.unlink(obj=material) return {"FINISHED"} + # Create a copy that will be removed / left unassigned + # and leave user with unlinked original material. + # + # Note should_delete=False creates a weird session state + # when style is assigned to geometry in IFC + # but mesh material is using some non-IFC Blender material instead. + # In this case we still create a material copy and relink style to it, + # so it will be still safe to assume that get_object(surface_style) is not None + # saving us from possible errors. + material_copy = material.copy() + tool.Ifc.unlink(element=style) + tool.Ifc.link(style, material_copy) if self.should_delete: - # Create a copy that will be removed - # and leave user with unlinked original material. - # It's needed so we don't need to search everywhere original - # material was used and replace it with the unlinked version. - material_copy = material.copy() - tool.Ifc.unlink(element=style) - tool.Ifc.link(style, material_copy) core.remove_style(tool.Ifc, tool.Style, style) else: - tool.Ifc.unlink(element=style) + material_copy.use_fake_user = True # Ensure there won't be any style sync on project save: # bim.update_representation would create new IfcSurfaceStyle