From 85524170dd9c884460f9d94dcd86c7b32aa5e2cb Mon Sep 17 00:00:00 2001 From: Thomas Krijnen Date: Fri, 4 Aug 2017 16:30:43 +0200 Subject: [PATCH] More advanced entity_instance.get_info() --- .../ifcopenshell/entity_instance.py | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/entity_instance.py b/src/ifcopenshell-python/ifcopenshell/entity_instance.py index ec3fab2283..ac6621ee73 100644 --- a/src/ifcopenshell-python/ifcopenshell/entity_instance.py +++ b/src/ifcopenshell-python/ifcopenshell/entity_instance.py @@ -124,27 +124,35 @@ class entity_instance(object): map(str, self.wrapped_data.get_inverse_attribute_names()) ))) - def get_info(self, include_identifier=True, recursive=False): - _info = {} - try: - if include_identifier: - _info["id"] = self.id() - _info["type"] = self.is_a() - except: - logging.exception("unhandled exception while getting id / type info on {}".format(self)) - for i in range(len(self)): + def get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=()): + def _(): try: - attr_value = self[i] - if recursive: - is_instance = lambda e: isinstance(e, entity_instance) - get_info = lambda inst: entity_instance.get_info(inst, - include_identifier=include_identifier, - recursive=recursive - ) - attr_value = entity_instance.walk(is_instance, get_info, attr_value) - _info[self.attribute_name(i)] = attr_value + if include_identifier: + yield "id", self.id() + yield "type", self.is_a() except: - logging.exception("unhandled exception occured setting attribute name for {}".format(self)) - return _info + logging.exception("unhandled exception while getting id / type info on {}".format(self)) + for i in range(len(self)): + try: + if self.wrapped_data.get_attribute_names()[i] in ignore: + continue + attr_value = self[i] + if recursive: + is_instance = lambda e: isinstance(e, entity_instance) + def get_info_(inst): + # for ty in ignore: + # if inst.is_a(ty): + # return None + return entity_instance.get_info(inst, + include_identifier=include_identifier, + recursive=recursive, + return_type=return_type, + ignore=ignore + ) + attr_value = entity_instance.walk(is_instance, get_info_, attr_value) + yield self.attribute_name(i), attr_value + except: + logging.exception("unhandled exception occured setting attribute name for {}".format(self)) + return return_type(_()) __dict__ = property(get_info)