From 2a713846ce9c4a0911647bcdd753cc9b127babbb Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 6 Dec 2024 18:13:57 +0500 Subject: [PATCH] bonsai ifcpatch - add warning for unsupported patches For patches that require filepath to be provided explicitly (they are still supported with "Load from memory" unchecked). --- .../bonsai/bim/module/patch/operator.py | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/patch/operator.py b/src/bonsai/bonsai/bim/module/patch/operator.py index 30014df816..f960d1875d 100644 --- a/src/bonsai/bonsai/bim/module/patch/operator.py +++ b/src/bonsai/bonsai/bim/module/patch/operator.py @@ -25,6 +25,7 @@ import bonsai.tool as tool import bonsai.core.patch as core import bonsai.bim.handler from pathlib import Path +from typing import cast class SelectIfcPatchInput(bpy.types.Operator): @@ -77,6 +78,8 @@ class ExecuteIfcPatch(bpy.types.Operator): def execute(self, context): props = context.scene.BIMPatchProperties + recipe_name = props.ifc_patch_recipes + arguments = [] if props.ifc_patch_args_attr: arguments = [] @@ -86,25 +89,28 @@ class ExecuteIfcPatch(bpy.types.Operator): value = value[0] arguments.append(value) + args = ifcpatch.ArgumentsDict( + recipe=props.ifc_patch_recipes, + arguments=arguments, + log=os.path.join(context.scene.BIMProperties.data_dir, "process.log"), + ) + if props.should_load_from_memory and tool.Ifc.get(): - input_file = props.ifc_patch_input - file = tool.Ifc.get() + args["file"] = tool.Ifc.get() + if ifcpatch.get_patch_input_argument_use(recipe_name) == "REQUIRED": + self.report( + {"ERROR"}, + f"The recipe '{recipe_name}' is not currently supported if file is loaded from memory.", + ) + return {"CANCELLED"} else: - input_file = props.ifc_patch_input - file = ifcopenshell.open(props.ifc_patch_input) + args["input"] = cast(str, props.ifc_patch_input) + args["file"] = cast(ifcopenshell.file, ifcopenshell.open(props.ifc_patch_input)) # Store this in case the patch recipe resets the Blender session, such as by loading a new project. ifc_patch_output = props.ifc_patch_output or props.ifc_patch_input - output = ifcpatch.execute( - { - "input": input_file, - "file": file, - "recipe": props.ifc_patch_recipes, - "arguments": arguments, - "log": os.path.join(context.scene.BIMProperties.data_dir, "process.log"), - } - ) + output = ifcpatch.execute(args) if tool.Patch.does_patch_has_output(props.ifc_patch_recipes): ifcpatch.write(output, ifc_patch_output) self.report({"INFO"}, f"{props.ifc_patch_recipes} patch executed successfully")