From c33b5aa4b716b39b51010c3222a6170aa472fd4e Mon Sep 17 00:00:00 2001 From: Gorgious56 Date: Fri, 28 Oct 2022 12:08:28 +0200 Subject: [PATCH] Extract attribute description fetching --- src/blenderbim/blenderbim/bim/helper.py | 32 +++++++++++++++---------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/helper.py b/src/blenderbim/blenderbim/bim/helper.py index 3a0a08d677..3bddd84159 100644 --- a/src/blenderbim/blenderbim/bim/helper.py +++ b/src/blenderbim/blenderbim/bim/helper.py @@ -103,21 +103,29 @@ def import_attribute(attribute, props, data, callback=None): elif data_type == "enum": enum_items = ifcopenshell.util.attribute.get_enum_items(attribute) new.enum_items = json.dumps(enum_items) - new.enum_descriptions.clear() - if isinstance(enum_items, dict): - enum_items = enum_items.keys() - for enum_item in enum_items: - new_enum_description = new.enum_descriptions.add() - # TODO this only supports predefined type enums. Add support for other types of enums ? - new_enum_description.name = get_predefined_type_description(data["type"], enum_item) or "" - if data[attribute.name()]: - new.enum_value = data[attribute.name()] - description = get_attribute_description(data["type"], attribute.name()) - if description: - new.description = description + add_attribute_enum_items_descriptions(data["type"], new, enum_items) + if data[new.name]: + new.enum_value = data[new.name] + add_attribute_description(data["type"], new) new.ifc_class = data["type"] +def add_attribute_enum_items_descriptions(ifc_class, new_attribute, enum_items): + new_attribute.enum_descriptions.clear() + if isinstance(enum_items, dict): + enum_items = enum_items.keys() + for enum_item in enum_items: + new_enum_description = new_attribute.enum_descriptions.add() + # TODO this only supports predefined type enums. Add support for other types of enums ? + new_enum_description.name = get_predefined_type_description(ifc_class, enum_item) or "" + + +def add_attribute_description(ifc_class, new_attribute): + description = get_attribute_description(ifc_class, new_attribute.name) + if description: + new_attribute.description = description + + def export_attributes(props, callback=None): attributes = {} for prop in props: