Correctly unpack arguments when Patching IFC

This commit is contained in:
Gorgious
2021-08-04 22:28:16 +02:00
parent d532a6bfd0
commit e5f3b65e93
2 changed files with 19 additions and 3 deletions
@@ -48,14 +48,26 @@ class ExecuteIfcPatch(bpy.types.Operator):
return os.path.isfile(input_file) and "ifc" in os.path.splitext(input_file)[1]
def execute(self, context):
if context.scene.BIMPatchProperties.ifc_patch_args_attr:
arguments = []
for arg in context.scene.BIMPatchProperties.ifc_patch_args_attr:
if arg.data_type == "string":
arguments.append(arg.string_value)
if arg.data_type == "boolean":
arguments.append(arg.bool_value)
if arg.data_type == "integer":
arguments.append(arg.int_value)
if arg.data_type == "float":
arguments.append(arg.float_value)
else:
arguments = json.loads(context.scene.BIMPatchProperties.ifc_patch_args or "[]")
ifcpatch.execute(
{
"input": context.scene.BIMPatchProperties.ifc_patch_input,
"output": context.scene.BIMPatchProperties.ifc_patch_output,
"recipe": context.scene.BIMPatchProperties.ifc_patch_recipes,
"arguments": json.loads(context.scene.BIMPatchProperties.ifc_patch_args or "[]"),
"arguments": arguments,
"log": os.path.join(context.scene.BIMProperties.data_dir, "process.log"),
}
)
+5 -1
View File
@@ -13,7 +13,11 @@ def execute(args, is_library=None):
print("# Loading patch recipe ...")
recipes = getattr(__import__("ifcpatch.recipes.{}".format(args["recipe"])), "recipes")
recipe = getattr(recipes, args["recipe"])
patcher = recipe.Patcher(args["input"], ifc_file, logger, args["arguments"])
try:
# We unpack the arguments if the Patcher has been type-hinted and docstringed
patcher = recipe.Patcher(args["input"], ifc_file, logger, *args["arguments"])
except TypeError:
patcher = recipe.Patcher(args["input"], ifc_file, logger, args["arguments"])
print("# Patching ...")
patcher.patch()
ifc_file = getattr(patcher, "file_patched", patcher.file)