From 54488bddbb38be33db23fed8bd74eb599f9f5d3a Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 7 Jul 2025 11:27:47 +0500 Subject: [PATCH] bim.attribute_search_values - use enumproperty for data_type --- src/bonsai/bonsai/bim/operator.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index 5fa3315e9a..0a1b5111fb 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -42,7 +42,7 @@ from mathutils import Vector, Euler from math import radians from pathlib import Path from collections import namedtuple -from typing import Union, TYPE_CHECKING +from typing import Union, TYPE_CHECKING, Literal, get_args from collections.abc import Iterable from natsort import natsorted @@ -1302,7 +1302,7 @@ class ShowSystemInfo(bpy.types.Operator): col.label(text="(The information has been copied to the clipboard.)") -def update_attribute_search_value(self, context): +def update_attribute_search_value(self: "BIM_OT_attribute_search_values", context: bpy.types.Context) -> None: should_click_ok = False attr_name, attribute_obj = BIM_OT_attribute_search_values.resolve_data_path(self.data_path) @@ -1321,6 +1321,9 @@ def update_attribute_search_value(self, context): context.window.screen = context.window.screen +AttributeSearchDataType = Literal["string", "integer", "float"] + + class BIM_OT_attribute_search_values(bpy.types.Operator): """Search for attribute values. This implementation is based on bim.enum_property_search""" @@ -1332,7 +1335,10 @@ class BIM_OT_attribute_search_values(bpy.types.Operator): attribute_name: bpy.props.StringProperty(name="Attribute Name") attribute_ifc_class: bpy.props.StringProperty(name="Attribute IFC Class") data_path: bpy.props.StringProperty(name="Data Path") - data_type: bpy.props.StringProperty(name="Data Type") + data_type: bpy.props.EnumProperty( + name="Data Type", + items=[(i, i, "") for i in get_args(AttributeSearchDataType)], + ) search_value: bpy.props.StringProperty( name="Search", description="Search for attribute values", @@ -1342,6 +1348,9 @@ class BIM_OT_attribute_search_values(bpy.types.Operator): ) collection_values: bpy.props.CollectionProperty(type=StrProperty, options={"SKIP_SAVE"}) + if TYPE_CHECKING: + data_type: AttributeSearchDataType + @staticmethod def resolve_data_path(data_path: str) -> tuple[str, "Attribute"]: """Resolve the data path of an object's attribute to get the attribute name and the object."""