Remove usage of .wrapped_item and some other fixes

This commit is contained in:
Thomas Krijnen
2026-01-10 11:01:18 +01:00
parent 5c9213426f
commit b66b04b001
55 changed files with 129 additions and 118 deletions
@@ -24,7 +24,7 @@ import ifcopenshell.util.unit
def add_linear_placement_fallback_position(file: ifcopenshell.file) -> ifcopenshell.file:
import ifcopenshell.api.alignment
patched_file = ifcopenshell.file.from_string(file.wrapped_data.to_string())
patched_file = ifcopenshell.file.from_string(file.to_string())
linear_placements = patched_file.by_type("IfcLinearPlacement")
for lp in linear_placements:
@@ -36,7 +36,7 @@ def add_linear_placement_fallback_position(file: ifcopenshell.file) -> ifcopensh
def create_alignment_geometry(file: ifcopenshell.file) -> ifcopenshell.file:
import ifcopenshell.api.alignment
patched_file = ifcopenshell.file.from_string(file.wrapped_data.to_string())
patched_file = ifcopenshell.file.from_string(file.to_string())
alignments = patched_file.by_type("IfcAlignment")
for alignment in alignments:
@@ -49,7 +49,7 @@ def append_zero_length_segments(file: ifcopenshell.file) -> ifcopenshell.file:
"""Appends zero length segments to all alignment layouts and layout geometry, if missing."""
import ifcopenshell.api.alignment
patched_file = ifcopenshell.file.from_string(file.wrapped_data.to_string())
patched_file = ifcopenshell.file.from_string(file.to_string())
alignments = patched_file.by_type("IfcAlignment")
for alignment in alignments:
@@ -70,7 +70,7 @@ def get_declaration(element: ifcopenshell.entity_instance):
print(declaration.is_abstract()) # False
print(declaration.supertype().name()) # IfcBuildingElement
"""
return element.wrapped_data.declaration().as_entity()
return element.declaration().as_entity()
def is_a(declaration: ifcopenshell.ifcopenshell_wrapper.declaration, ifc_class: str) -> bool:
@@ -104,7 +104,7 @@ def get_supertypes(
.. code:: python
wall = model.createIfcWall()
results = ifcopenshell.util.schema.get_supertypes(wall.wrapped_data.declaration().as_entity())
results = ifcopenshell.util.schema.get_supertypes(wall.declaration().as_entity())
# [<entity IfcBuildingElement>, <entity IfcElement>, ..., <entity IfcRoot>]
"""
results = []
@@ -462,7 +462,7 @@ class Migrator:
) -> None:
# NOTE: `attribute` is an attribute in new file schema
# print("Migrating attribute", element, new_element, attribute.name())
old_file = element.wrapped_data.file
old_file = element.file
if hasattr(element, attribute.name()):
value = getattr(element, attribute.name())
# print("Attribute names matched", value)
@@ -386,7 +386,7 @@ def _get_element_value(element: ifcopenshell.entity_instance, keys: list[str]) -
if key in ("x", "y", "z"):
value = xyz["xyz".index(key)]
else:
enh = ifcopenshell.util.geolocation.auto_xyz2enh(element.wrapped_data.file, *xyz)
enh = ifcopenshell.util.geolocation.auto_xyz2enh(element.file, *xyz)
value = enh[("easting", "northing", "elevation").index(key)]
else:
value = None
@@ -569,7 +569,7 @@ def set_element_value(
element: ifcopenshell.entity_instance, value: Union[str, None], *, is_type: bool
) -> None:
predefined_type = element.PredefinedType
declaration = element.wrapped_data.declaration()
declaration = element.declaration()
entity = declaration.as_entity()
enum_attr = next(attr for attr in entity.attributes() if attr.name() == "PredefinedType")
enum_items = ifcopenshell.util.attribute.get_enum_items(enum_attr)
@@ -639,9 +639,9 @@ def set_element_value(
except:
# Try to cast
data_type = ifcopenshell.util.attribute.get_primitive_type(
element.wrapped_data.declaration()
element.declaration()
.as_entity()
.attribute_by_index(element.wrapped_data.get_argument_index(key))
.attribute_by_index(element.get_argument_index(key))
)
if data_type == "string":
value = str(value)
@@ -475,7 +475,7 @@ def get_property_unit(
measure_class = None
if prop.is_a("IfcPhysicalSimpleQuantity"):
entity = prop.wrapped_data.declaration().as_entity()
entity = prop.declaration().as_entity()
measure_class = entity.attribute_by_index(3).type_of_attribute().declared_type().name()
elif prop.is_a("IfcPropertySingleValue"):
measure_class = prop.NominalValue.is_a()
@@ -875,7 +875,7 @@ def convert_file_length_units(ifc_file: ifcopenshell.file, target_units: str = "
si_unit = get_unit_name(target_units)
# Copy all elements from the original file to the patched file
file_patched = ifcopenshell.file.from_string(ifc_file.wrapped_data.to_string())
file_patched = ifcopenshell.file.from_string(ifc_file.to_string())
old_length = get_project_unit(file_patched, "LENGTHUNIT")
if si_unit: