mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-11 14:22:33 +00:00
More advanced entity_instance.get_info()
This commit is contained in:
@@ -124,27 +124,35 @@ class entity_instance(object):
|
|||||||
map(str, self.wrapped_data.get_inverse_attribute_names())
|
map(str, self.wrapped_data.get_inverse_attribute_names())
|
||||||
)))
|
)))
|
||||||
|
|
||||||
def get_info(self, include_identifier=True, recursive=False):
|
def get_info(self, include_identifier=True, recursive=False, return_type=dict, ignore=()):
|
||||||
_info = {}
|
def _():
|
||||||
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)):
|
|
||||||
try:
|
try:
|
||||||
attr_value = self[i]
|
if include_identifier:
|
||||||
if recursive:
|
yield "id", self.id()
|
||||||
is_instance = lambda e: isinstance(e, entity_instance)
|
yield "type", self.is_a()
|
||||||
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
|
|
||||||
except:
|
except:
|
||||||
logging.exception("unhandled exception occured setting attribute name for {}".format(self))
|
logging.exception("unhandled exception while getting id / type info on {}".format(self))
|
||||||
return _info
|
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)
|
__dict__ = property(get_info)
|
||||||
|
|||||||
Reference in New Issue
Block a user