Skip to content
Open
12 changes: 12 additions & 0 deletions src/ansys/dpf/core/any.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def _type_to_new_from_get_as_method(self, obj): # noqa: PLR0911, PLR0912, C901
fields_container,
generic_data_container,
generic_support,
meshed_region,
meshes_container,
property_field,
scoping,
string_field,
Expand Down Expand Up @@ -223,6 +225,16 @@ def _type_to_new_from_get_as_method(self, obj): # noqa: PLR0911, PLR0912, C901
self._api.any_new_from_cyclic_support,
self._api.any_get_as_cyclic_support,
)
elif issubclass(obj, meshed_region.MeshedRegion):
return (
self._api.any_new_from_meshed_region,
self._api.any_get_as_meshed_region,
)
elif issubclass(obj, meshes_container.MeshesContainer):
return (
self._api.any_new_from_meshes_container,
self._api.any_get_as_meshes_container,
)
elif issubclass(obj, Any):
return (
lambda x: x,
Expand Down
26 changes: 26 additions & 0 deletions tests/test_any.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,29 @@ def test_cast_fields_container_any(server_type):
new_entity = any_dpf.cast()

assert entity.name == new_entity.name

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
reason="any does not support operator below 10.0",
)
def test_cast_meshed_region_any(server_type):
entity = dpf.MeshedRegion(server=server_type)
entity.unit = "mm"
any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert entity.unit == new_entity.unit

@pytest.mark.skipif(
not conftest.SERVERS_VERSION_GREATER_THAN_OR_EQUAL_TO_10_0,
reason="any does not support operator below 10.0",
)
def test_cast_meshes_container_any(server_type):
entity = dpf.MeshesContainer(server=server_type)
entity.add_label("idx")
entity.add_mesh({"idx": 0}, dpf.MeshedRegion(server=server_type))

any_dpf = dpf.Any.new_from(entity)
new_entity = any_dpf.cast()

assert entity.get_label_space(0) == new_entity.get_label_space(0)
Loading