From b1231b74e2fafea7bba97ded3c39f95f70628742 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 10 Dec 2024 13:25:41 +0500 Subject: [PATCH] Save texture style without textures to remove texture style Mentioned in 618ba51, it probably will be more natural this way - if there are no textures, we hide UV attribute to indicate that it won't be saved and on save we either do nothing, if texture style wasn't saved before, or remove it. --- src/bonsai/bonsai/bim/module/style/operator.py | 9 +++++---- src/bonsai/bonsai/bim/module/style/ui.py | 3 ++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/style/operator.py b/src/bonsai/bonsai/bim/module/style/operator.py index 9f0fea4270..05f94f813a 100644 --- a/src/bonsai/bonsai/bim/module/style/operator.py +++ b/src/bonsai/bonsai/bim/module/style/operator.py @@ -764,6 +764,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): material.BIMStyleProperties.active_style_type = material.BIMStyleProperties.active_style_type def edit_existing_style(self): + ifc_file = tool.Ifc.get() material = tool.Ifc.get_object(self.style) assert self.surface_style @@ -791,8 +792,9 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): material = tool.Ifc.get_object(self.style) textures = self.get_texture_attributes() if not textures: - self.report({"ERROR"}, "Cannot save texture style without any textures.") - return {"CANCELLED"} + assert self.texture_style + ifcopenshell.api.style.remove_surface_style(ifc_file, self.texture_style) + return textures = tool.Ifc.run("style.add_surface_textures", textures=textures, uv_maps=[]) texture_style = tool.Ifc.run( "style.add_surface_style", @@ -835,8 +837,7 @@ class EditSurfaceStyle(bpy.types.Operator, tool.Ifc.Operator): material = tool.Ifc.get_object(self.style) textures = self.get_texture_attributes() if not textures: - self.report({"ERROR"}, "Cannot create texture style without any textures.") - return {"CANCELLED"} + return textures = tool.Ifc.run("style.add_surface_textures", textures=textures, uv_maps=[]) texture_style = tool.Ifc.run( "style.add_surface_style", diff --git a/src/bonsai/bonsai/bim/module/style/ui.py b/src/bonsai/bonsai/bim/module/style/ui.py index 14b44f7fdf..605cbef697 100644 --- a/src/bonsai/bonsai/bim/module/style/ui.py +++ b/src/bonsai/bonsai/bim/module/style/ui.py @@ -220,7 +220,8 @@ class BIM_PT_styles(Panel): row = self.layout.row(align=True) row.label(text=f"Style has {len(textures)} textures", icon="SHADING_TEXTURE") row.operator("bim.add_surface_texture", text="", icon="ADD") - self.layout.prop(self.props, "uv_mode") + if textures: + self.layout.prop(self.props, "uv_mode") for i, texture in enumerate(textures): split = self.layout.split(factor=0.30, align=True)