mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-09 17:31:45 +00:00
#2408 ifcopenshell.file.get_inverse(with_attribute_indices)
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user