mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +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())
|
||||
)))
|
||||
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user