Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/bonsai/bonsai/bim/module/style/operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,8 @@ class UpdateCurrentStyle(bpy.types.Operator):
bl_idname = "bim.update_current_style"
bl_label = "Update Current Style"
bl_description = (
"Update style for all selected objects according to current style type\n(Shading/External).\n\n"
"Update style for all selected objects according to current style type\n(Shading/External).\n"
+ "External styles are reloaded from their .blend file.\n\n"
+ "SHIFT+CLICK to update ALL styles in the .ifc file to current style type"
)
bl_options = {"REGISTER", "UNDO"}
Expand All @@ -232,6 +233,11 @@ def execute(self, context):
if self.update_all:
sprops = tool.Style.get_style_props()
sprops.active_style_type = current_style_type
if current_style_type == "External":
for mat in bpy.data.materials:
if tool.Blender.get_ifc_definition_id(mat) == 0:
continue
self.reload_external_style(mat)
return {"FINISHED"}

updated_materials: set[bpy.types.Material] = set()
Expand All @@ -247,9 +253,21 @@ def execute(self, context):
if mat in updated_materials:
continue
msprops_.active_style_type = current_style_type
if current_style_type == "External":
self.reload_external_style(mat)
updated_materials.add(mat)
return {"FINISHED"}

def reload_external_style(self, material: bpy.types.Material) -> None:
# Setting active_style_type only flips the cached dual-branch outputs,
# so re-append from the .blend to pick up changes made to the external style.
if not tool.Style.has_blender_external_style(tool.Style.get_style_elements(material)):
return
try:
bpy.ops.bim.activate_external_style(material_name=material.name)
except RuntimeError as error:
self.report({"WARNING"}, str(error))


class SetAssetMaterialToExternalStyle(bpy.types.Operator):
bl_idname = "bim.set_asset_material_to_external_style"
Expand Down