From e5fa8a01b4292ef636ae57f4afb298379f1c76f0 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 4 Dec 2023 17:36:18 +0500 Subject: [PATCH] fixed couple styles ui bugs 1) it was failing adding a new IfcSurfaceStyle if surface_style_class != Shading/Render as surface_style was not defined 2) It was never creating render material as IfcSurfaceStyleRendering class is a child of IfcSurfaceStyleShading and if statement never got to the is_a("IfcSurfaceStyleRendering") check --- .../blenderbim/bim/module/style/operator.py | 15 +++++++++++---- src/blenderbim/blenderbim/bim/module/style/ui.py | 2 ++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/style/operator.py b/src/blenderbim/blenderbim/bim/module/style/operator.py index f94840013c..718c88b0c2 100644 --- a/src/blenderbim/blenderbim/bim/module/style/operator.py +++ b/src/blenderbim/blenderbim/bim/module/style/operator.py @@ -501,6 +501,9 @@ class AddPresentationStyle(bpy.types.Operator, tool.Ifc.Operator): props = bpy.context.scene.BIMStylesProperties if props.style_type == "IfcSurfaceStyle": style = ifcopenshell.api.run("style.add_style", tool.Ifc.get(), name=props.style_name) + + # setup surface style element + surface_style = None if props.surface_style_class in ("IfcSurfaceStyleShading", "IfcSurfaceStyleRendering"): surface_style = ifcopenshell.api.run( "style.add_surface_style", @@ -518,13 +521,17 @@ class AddPresentationStyle(bpy.types.Operator, tool.Ifc.Operator): ) if props.surface_style_class == "IfcSurfaceStyleRendering": surface_style.ReflectanceMethod = "NOTDEFINED" + + # setup blender material material = bpy.data.materials.new(style.Name) tool.Ifc.link(style, material) material.use_fake_user = True - if surface_style.is_a("IfcSurfaceStyleShading"): - tool.Loader.create_surface_style_shading(material, surface_style) - elif surface_style.is_a("IfcSurfaceStyleRendering"): - tool.Loader.create_surface_style_rendering(material, surface_style) + if surface_style: + if surface_style.is_a("IfcSurfaceStyleRendering"): + tool.Loader.create_surface_style_rendering(material, surface_style) + elif surface_style.is_a("IfcSurfaceStyleShading"): + tool.Loader.create_surface_style_shading(material, surface_style) + props.is_adding = False core.load_styles(tool.Style, style_type=props.style_type) diff --git a/src/blenderbim/blenderbim/bim/module/style/ui.py b/src/blenderbim/blenderbim/bim/module/style/ui.py index d96d0a5376..b18b9ec20a 100644 --- a/src/blenderbim/blenderbim/bim/module/style/ui.py +++ b/src/blenderbim/blenderbim/bim/module/style/ui.py @@ -65,6 +65,8 @@ class BIM_PT_styles(Panel): row.prop(self.props, "style_name", text="Name") if self.props.style_type == "IfcSurfaceStyle": row = box.row() + # NOTE: user must choose 1 of the style elements to create IfcSurfaceStyle + # otherwise it won't be a valid IFC row.prop(self.props, "surface_style_class", text="Class") if self.props.surface_style_class in ("IfcSurfaceStyleShading", "IfcSurfaceStyleRendering"): row = box.row()