From 9ac159e0af553f2d3a4a397febff00fda9fe8c77 Mon Sep 17 00:00:00 2001 From: Blender Defender Date: Thu, 25 Jul 2024 19:18:13 +0200 Subject: [PATCH] feat: Parse type "Literal" as enum property in the IFC Patch Panel --- src/blenderbim/blenderbim/bim/module/patch/operator.py | 6 +++++- src/ifcpatch/ifcpatch/__init__.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/blenderbim/blenderbim/bim/module/patch/operator.py b/src/blenderbim/blenderbim/bim/module/patch/operator.py index 9397b52f33..7f805f930e 100644 --- a/src/blenderbim/blenderbim/bim/module/patch/operator.py +++ b/src/blenderbim/blenderbim/bim/module/patch/operator.py @@ -126,13 +126,17 @@ class UpdateIfcPatchArguments(bpy.types.Operator): if isinstance(data_type, list): data_type = [dt for dt in data_type if dt != "NoneType"][0] new_attr.data_type = { - "Literal": "string", + "Literal": "enum", "str": "string", "float": "float", "int": "integer", "bool": "boolean", }[data_type] new_attr.name = arg_name + if new_attr.data_type == "enum": + new_attr.enum_items = json.dumps(arg_info.get("enum_items", [])) + new_attr.enum_value = arg_info.get("default", new_attr.get_value_default()) + continue # Temporary workaround, because the Argument class resets the type to "string" when calling `set_value` new_attr.set_value(arg_info.get("default", new_attr.get_value_default())) return {"FINISHED"} diff --git a/src/ifcpatch/ifcpatch/__init__.py b/src/ifcpatch/ifcpatch/__init__.py index 9ffc25ba6f..09db1958e3 100644 --- a/src/ifcpatch/ifcpatch/__init__.py +++ b/src/ifcpatch/ifcpatch/__init__.py @@ -158,6 +158,9 @@ def _extract_docs(cls, method_name, boilerplate_args): continue if isinstance(type_hint, typing._UnionGenericAlias): inputs[input_name]["type"] = [t.__name__ for t in typing.get_args(type_hint)] + elif type_hint.__name__ == "Literal": + inputs[input_name]["type"] = "Literal" + inputs[input_name]["enum_items"] = list(typing.get_args(type_hint)) else: inputs[input_name]["type"] = type_hint.__name__