Skip to content

Commit 9422441

Browse files
committed
Recursive get_info()
1 parent 5c7e7ca commit 9422441

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

src/ifcopenshell-python/ifcopenshell/entity_instance.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,25 @@ def __dir__(self):
124124
self.wrapped_data.get_inverse_attribute_names()
125125
)))
126126

127-
def get_info(self):
127+
def get_info(self, include_identifier=True, recursive=False):
128128
_info = {}
129129
try:
130-
_info["id"] = self.id()
130+
if include_identifier:
131+
_info["id"] = self.id()
131132
_info["type"] = self.is_a()
132133
except:
133134
logging.exception("unhandled exception while getting id / type info on {}".format(self))
134135
for i in range(len(self)):
135136
try:
136-
_info[self.attribute_name(i)] = self[i]
137+
attr_value = self[i]
138+
if recursive:
139+
is_instance = lambda e: isinstance(e, entity_instance)
140+
get_info = lambda inst: entity_instance.get_info(inst,
141+
include_identifier=include_identifier,
142+
recursive=recursive
143+
)
144+
attr_value = entity_instance.walk(is_instance, get_info, attr_value)
145+
_info[self.attribute_name(i)] = attr_value
137146
except:
138147
logging.exception("unhandled exception occured setting attribute name for {}".format(self))
139148
return _info

0 commit comments

Comments
 (0)