diff --git a/src/ansys/dpf/core/any.py b/src/ansys/dpf/core/any.py index ad60e8b983..aec71d740a 100644 --- a/src/ansys/dpf/core/any.py +++ b/src/ansys/dpf/core/any.py @@ -122,6 +122,7 @@ def _type_to_new_from_get_as_method(self, obj): data_tree, custom_type_field, collection, + fields_container ) if issubclass(obj, int): @@ -190,6 +191,11 @@ def _type_to_new_from_get_as_method(self, obj): self._api.any_new_from_int_collection, self._api.any_get_as_int_collection, ) + elif issubclass(obj, fields_container.FieldsContainer): + return ( + self._api.any_new_from_fields_container, + self._api.any_get_as_fields_container + ) @staticmethod def new_from(obj, server=None): diff --git a/tests/test_any.py b/tests/test_any.py index bf3897fe1f..f666ea6914 100644 --- a/tests/test_any.py +++ b/tests/test_any.py @@ -120,3 +120,16 @@ def test_cast_scoping_any(server_type): new_entity = any_dpf.cast() assert entity.location == new_entity.location + +@conftest.raises_for_servers_version_under("7.0") +def test_cast_fields_container_any(server_type): + fc = dpf.FieldsContainer(server=server_type) + fc.labels = ["time"] + + field1 = dpf.Field(nentities=2,server=server_type) + field1.data = [1, 2, 3, 4, 5, 6] + fc.add_field({"time": 0}, field1) + any_dpf = dpf.Any.new_from(fc) + + entity: dpf.FieldsContainer = any_dpf.cast() + assert entity.get_field({"time":0}).size == 6 \ No newline at end of file