#2408 ifcopenshell.file.get_inverse(with_attribute_indices)

This commit is contained in:
Thomas Krijnen
2022-10-20 13:35:02 +02:00
parent 45087e8822
commit f012286eda
4 changed files with 66 additions and 2 deletions
+14 -2
View File
@@ -377,17 +377,29 @@ class file(object):
return [entity_instance(e, self) for e in fn(inst.wrapped_data, max_levels)]
def get_inverse(self, inst, allow_duplicate=False):
def get_inverse(self, inst, allow_duplicate=False, with_attribute_indices=False):
"""Return a list of entities that reference this entity
:param inst: The entity instance to get inverse relationships
:type inst: ifcopenshell.entity_instance.entity_instance
:param allow_duplicate: Returns a `list` when True, `set` when False
:param with_attribute_indices: Returns pairs of <i, idx>
where i[idx] is inst or contains inst. Requires allow_duplicate=True
:returns: A list of ifcopenshell.entity_instance.entity_instance objects
:rtype: list
"""
if with_attribute_indices and not allow_duplicate:
raise ValueError("with_attribute_indices requires allow_duplicate to be True")
inverses = [entity_instance(e, self) for e in self.wrapped_data.get_inverse(inst.wrapped_data)]
if allow_duplicate:
return inverses
if with_attribute_indices:
idxs = self.wrapped_data.get_inverse_indices(inst.wrapped_data)
return list(zip(inverses, idxs))
else:
return inverses
return set(inverses)
def get_total_inverses(self, inst):