From 5eb9cb2ee4b199936ed47f61837e46d7e0806402 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 24 Feb 2025 11:34:47 +0500 Subject: [PATCH] len(get_inverse) -> get_total_inverses --- src/bonsai/bonsai/bim/module/structural/operator.py | 2 +- .../ifcopenshell/api/cost/edit_cost_value.py | 2 +- .../ifcopenshell/api/cost/remove_cost_item_quantity.py | 2 +- .../ifcopenshell/api/cost/remove_cost_value.py | 2 +- .../ifcopenshell/api/georeference/remove_georeferencing.py | 2 +- .../ifcopenshell/api/grid/remove_grid_axis.py | 2 +- .../ifcopenshell/api/material/assign_profile.py | 2 +- .../ifcopenshell/api/owner/remove_organisation.py | 4 ++-- .../ifcopenshell/api/owner/remove_person.py | 4 ++-- .../ifcopenshell/api/sequence/assign_lag_time.py | 4 ++-- .../ifcopenshell/api/sequence/assign_recurrence_pattern.py | 6 +++--- .../ifcopenshell/api/sequence/unassign_lag_time.py | 4 ++-- .../api/structural/edit_structural_connection_cs.py | 6 +++--- .../api/structural/edit_structural_item_axis.py | 2 +- .../ifcopenshell/api/style/assign_material_style.py | 2 +- .../ifcopenshell/api/unit/edit_named_unit.py | 2 +- .../test/api/geometry/test_add_boolean.py | 4 ++-- 17 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/structural/operator.py b/src/bonsai/bonsai/bim/module/structural/operator.py index 47d74515f8..ba08227179 100644 --- a/src/bonsai/bonsai/bim/module/structural/operator.py +++ b/src/bonsai/bonsai/bim/module/structural/operator.py @@ -750,7 +750,7 @@ class LoadStructuralLoads(bpy.types.Operator): for structural_load in loads: if ( names.count(structural_load.Name or "Unnamed") > 1 - and len(self.file.get_inverse(structural_load)) < 2 + and self.file.get_total_inverses(structural_load) < 2 ): continue new = props.structural_loads.add() diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/edit_cost_value.py b/src/ifcopenshell-python/ifcopenshell/api/cost/edit_cost_value.py index 5812cbcf75..ebc09ed34c 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/cost/edit_cost_value.py +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/edit_cost_value.py @@ -58,6 +58,6 @@ def edit_cost_value( value["ValueComponent"], ) value = file.create_entity("IfcMeasureWithUnit", value_component, value["UnitComponent"]) - if old_unit_basis and len(file.get_inverse(old_unit_basis)) == 0: + if old_unit_basis and file.get_total_inverses(old_unit_basis) == 0: ifcopenshell.util.element.remove_deep(file, old_unit_basis) setattr(cost_value, name, value) diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item_quantity.py b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item_quantity.py index 48ac816f18..80f330ce0b 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item_quantity.py +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_item_quantity.py @@ -43,7 +43,7 @@ def remove_cost_item_quantity( ifcopenshell.api.cost.remove_cost_item(model, cost_item=item, physical_quantity=quantity) """ - if len(file.get_inverse(physical_quantity)) == 1: + if file.get_total_inverses(physical_quantity) == 1: file.remove(physical_quantity) return quantities = list(cost_item.CostQuantities or []) diff --git a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_value.py b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_value.py index a99417f4df..b578cd7134 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_value.py +++ b/src/ifcopenshell-python/ifcopenshell/api/cost/remove_cost_value.py @@ -45,7 +45,7 @@ def remove_cost_value( ifcopenshell.api.cost.remove_cost_value(model, parent=item, cost_value=value) """ - if len(file.get_inverse(cost_value)) == 1: + if file.get_total_inverses(cost_value) == 1: file.remove(cost_value) # TODO deep purge elif parent.is_a("IfcCostItem"): diff --git a/src/ifcopenshell-python/ifcopenshell/api/georeference/remove_georeferencing.py b/src/ifcopenshell-python/ifcopenshell/api/georeference/remove_georeferencing.py index 63d46b840b..3cbcae5d60 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/georeference/remove_georeferencing.py +++ b/src/ifcopenshell-python/ifcopenshell/api/georeference/remove_georeferencing.py @@ -43,7 +43,7 @@ def remove_georeferencing(file: ifcopenshell.file) -> None: ifcopenshell.api.pset.remove_pset(file, project, file.by_id(pset["id"])) return for projected_crs in file.by_type("IfcProjectedCRS"): - if (unit := projected_crs.MapUnit) and len(file.get_inverse(unit)) == 1: + if (unit := projected_crs.MapUnit) and file.get_total_inverses(unit) == 1: projected_crs.MapUnit = None ifcopenshell.util.element.remove_deep2(file, unit) file.remove(projected_crs) diff --git a/src/ifcopenshell-python/ifcopenshell/api/grid/remove_grid_axis.py b/src/ifcopenshell-python/ifcopenshell/api/grid/remove_grid_axis.py index c47165643f..652fc89f56 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/grid/remove_grid_axis.py +++ b/src/ifcopenshell-python/ifcopenshell/api/grid/remove_grid_axis.py @@ -42,7 +42,7 @@ def remove_grid_axis(file: ifcopenshell.file, axis: ifcopenshell.entity_instance ifcopenshell.api.grid.remove_grid_axis(model, axis=axis_2) """ axis_curve = axis.AxisCurve - if len(file.get_inverse(axis_curve)) == 1: + if file.get_total_inverses(axis_curve) == 1: ifcopenshell.util.element.remove_deep(file, axis_curve) file.remove(axis_curve) file.remove(axis) diff --git a/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py b/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py index a749ad11c4..1e7c209e6c 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py +++ b/src/ifcopenshell-python/ifcopenshell/api/material/assign_profile.py @@ -117,7 +117,7 @@ class Usecase: for element in rel.RelatedObjects: self.change_profile(element, profile) - if old_profile and len(self.file.get_inverse(old_profile)) == 0: + if old_profile and self.file.get_total_inverses(old_profile) == 0: # TODO: check remove deep self.file.remove(old_profile) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_organisation.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_organisation.py index de1efef20d..acee11d9f5 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_organisation.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_organisation.py @@ -38,10 +38,10 @@ def remove_organisation(file: ifcopenshell.file, organisation: ifcopenshell.enti ifcopenshell.api.owner.remove_organisation(model, organisation=organisation) """ for role in organisation.Roles or []: - if len(file.get_inverse(role)) == 1: + if (file.get_total_inverses(role)) == 1: ifcopenshell.api.owner.remove_role(file, role=role) for address in organisation.Addresses or []: - if len(file.get_inverse(address)) == 1: + if (file.get_total_inverses(address)) == 1: ifcopenshell.api.owner.remove_address(file, address=address) for inverse in file.get_inverse(organisation): if inverse.is_a("IfcOrganizationRelationship"): diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py index 07508a977e..0c618c1e74 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py @@ -41,10 +41,10 @@ def remove_person(file: ifcopenshell.file, person: ifcopenshell.entity_instance) """ for role in person.Roles or []: - if len(file.get_inverse(role)) == 1: + if file.get_total_inverses(role) == 1: ifcopenshell.api.owner.remove_role(file, role=role) for address in person.Addresses or []: - if len(file.get_inverse(address)) == 1: + if file.get_total_inverses(address) == 1: ifcopenshell.api.owner.remove_address(file, address=address) for inverse in file.get_inverse(person): if inverse.is_a("IfcWorkControl"): diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_lag_time.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_lag_time.py index 905602db16..2c08ab00a3 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_lag_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_lag_time.py @@ -83,7 +83,7 @@ def assign_lag_time( duration = file.create_entity("IfcDuration", ifcopenshell.util.date.datetime2ifc(lag_value, "IfcDuration")) lag_time = file.create_entity("IfcLagTime", DurationType=duration_type, LagValue=duration) if rel_sequence.is_a("IfcRelSequence"): - if rel_sequence.TimeLag and len(file.get_inverse(rel_sequence.TimeLag)) == 1: - file.remove(rel_sequence.TimeLag) + if (current_lag_time := rel_sequence.TimeLag) and file.get_total_inverses(current_lag_time) == 1: + file.remove(current_lag_time) rel_sequence.TimeLag = lag_time return lag_time diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_recurrence_pattern.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_recurrence_pattern.py index 333aefb418..7f74fb300b 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_recurrence_pattern.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/assign_recurrence_pattern.py @@ -108,11 +108,11 @@ def assign_recurrence_pattern( recurrence = file.create_entity("IfcRecurrencePattern", recurrence_type) if parent.is_a("IfcWorkTime"): - if parent.RecurrencePattern and len(file.get_inverse(parent.RecurrencePattern)) == 1: - file.remove(parent.RecurrencePattern) + if (old_recurrence := parent.RecurrencePattern) and file.get_total_inverses(old_recurrence) == 1: + file.remove(old_recurrence) parent.RecurrencePattern = recurrence elif parent.is_a("IfcTaskTimeRecurring"): - if (recurrence_old := parent.Recurrence) and len(file.get_inverse(recurrence_old)) == 1: + if (recurrence_old := parent.Recurrence) and file.get_total_inverses(recurrence_old) == 1: file.remove(recurrence_old) parent.Recurrence = recurrence return recurrence diff --git a/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_lag_time.py b/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_lag_time.py index fb44184c5f..b07a630684 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_lag_time.py +++ b/src/ifcopenshell-python/ifcopenshell/api/sequence/unassign_lag_time.py @@ -55,8 +55,8 @@ def unassign_lag_time(file: ifcopenshell.file, rel_sequence: ifcopenshell.entity # What if you didn't? ifcopenshell.api.sequence.unassign_lag_time(model, rel_sequence=sequence) """ - if len(file.get_inverse(rel_sequence.TimeLag)) == 1: - file.remove(rel_sequence.TimeLag) + if file.get_total_inverses((current_lag_time := rel_sequence.TimeLag)) == 1: + file.remove(current_lag_time) else: rel_sequence.TimeLag = None ifcopenshell.api.sequence.cascade_schedule(file, task=rel_sequence.RelatedProcess) diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_connection_cs.py b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_connection_cs.py index e9fcc0d660..38befd9c6f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_connection_cs.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_connection_cs.py @@ -40,9 +40,9 @@ def edit_structural_connection_cs( structural_item.ConditionCoordinateSystem = ccs ccs = structural_item.ConditionCoordinateSystem - if ccs.Axis and len(file.get_inverse(ccs.Axis)) == 1: - file.remove(ccs.Axis) + if (current_axis := ccs.Axis) and file.get_total_inverses(current_axis) == 1: + file.remove(current_axis) ccs.Axis = file.create_entity("IfcDirection", ifc_safe_vector_type(axis)) - if (prev_ref_direction := ccs.RefDirection) and len(file.get_inverse(prev_ref_direction)) == 1: + if (prev_ref_direction := ccs.RefDirection) and file.get_total_inverses(prev_ref_direction) == 1: file.remove(prev_ref_direction) ccs.RefDirection = file.create_entity("IfcDirection", ifc_safe_vector_type(ref_direction)) diff --git a/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_item_axis.py b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_item_axis.py index 1b7105d95d..d3858bec95 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_item_axis.py +++ b/src/ifcopenshell-python/ifcopenshell/api/structural/edit_structural_item_axis.py @@ -31,6 +31,6 @@ def edit_structural_item_axis( Defaults to (0., 0., 1.). :return: None """ - if len(file.get_inverse(axis_dir := structural_item.Axis)) == 1: + if file.get_total_inverses(axis_dir := structural_item.Axis) == 1: file.remove(axis_dir) structural_item.Axis = file.create_entity("IfcDirection", ifc_safe_vector_type(axis)) diff --git a/src/ifcopenshell-python/ifcopenshell/api/style/assign_material_style.py b/src/ifcopenshell-python/ifcopenshell/api/style/assign_material_style.py index f870a3006e..fbd706df68 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/style/assign_material_style.py +++ b/src/ifcopenshell-python/ifcopenshell/api/style/assign_material_style.py @@ -174,7 +174,7 @@ class Usecase: new_items.append(self.create_styled_item(item_to_reuse)) representation.Items = new_items for item in same_style_items: - if len(self.file.get_inverse(item)) == 0: + if self.file.get_total_inverses(item) == 0: self.file.remove(item) else: representations = list(definition_representation.Representations) diff --git a/src/ifcopenshell-python/ifcopenshell/api/unit/edit_named_unit.py b/src/ifcopenshell-python/ifcopenshell/api/unit/edit_named_unit.py index ccd0e96d54..683feb7216 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/unit/edit_named_unit.py +++ b/src/ifcopenshell-python/ifcopenshell/api/unit/edit_named_unit.py @@ -45,7 +45,7 @@ def edit_named_unit(file: ifcopenshell.file, unit: ifcopenshell.entity_instance, for name, value in attributes.items(): if name == "Dimensions": dimensions = unit.Dimensions - if len(file.get_inverse(dimensions)) > 1: + if file.get_total_inverses(dimensions) > 1: unit.Dimensions = file.createIfcDimensionalExponents(*value) else: for i, exponent in enumerate(value): diff --git a/src/ifcopenshell-python/test/api/geometry/test_add_boolean.py b/src/ifcopenshell-python/test/api/geometry/test_add_boolean.py index ba8385fa3e..07a4400f5a 100644 --- a/src/ifcopenshell-python/test/api/geometry/test_add_boolean.py +++ b/src/ifcopenshell-python/test/api/geometry/test_add_boolean.py @@ -105,7 +105,7 @@ class TestAddBoolean(test.bootstrap.IFC4): assert len(booleans) == 1 assert len(rep.Items) == 2 - assert len(self.file.get_inverse(first1)) == 1 + assert self.file.get_total_inverses(first1) == 1 result = list(self.file.get_inverse(first1))[0] assert result.FirstOperand == first1 assert result.SecondOperand == second1 @@ -114,7 +114,7 @@ class TestAddBoolean(test.bootstrap.IFC4): # Second2 is now used twice. Reusing is OK (albeit confusing), so long as things don't get recursive. assert result2.SecondOperand == second2 - assert len(self.file.get_inverse(first2)) == 1 + assert self.file.get_total_inverses(first2) == 1 result3 = list(self.file.get_inverse(first2))[0] assert result3.FirstOperand == first2 assert result3.SecondOperand == second2