1111from ansys .dpf .core import server as server_module
1212from ansys .dpf .core import errors
1313from ansys .dpf .core .check_version import server_meet_version
14- from ansys .dpf .core .common import type_to_internal_object_keyword
14+ from ansys .dpf .core .common import create_dpf_instance
1515from ansys .dpf .gate import any_abstract_api , integral_types
1616
1717
@@ -92,6 +92,8 @@ def _type_to_new_from_get_as_method(self):
9292 string_field ,
9393 scoping ,
9494 data_tree ,
95+ custom_type_field ,
96+ collection ,
9597 )
9698
9799 return [
@@ -145,6 +147,16 @@ def _type_to_new_from_get_as_method(self):
145147 self ._api .any_new_from_data_tree ,
146148 self ._api .any_get_as_data_tree ,
147149 ),
150+ (
151+ custom_type_field .CustomTypeField ,
152+ self ._api .any_new_from_custom_type_field ,
153+ self ._api .any_get_as_custom_type_field ,
154+ ),
155+ (
156+ collection .Collection ,
157+ self ._api .any_new_from_any_collection ,
158+ self ._api .any_get_as_any_collection ,
159+ ),
148160 ]
149161
150162 @staticmethod
@@ -172,7 +184,7 @@ def new_from(obj, server=None):
172184 if isinstance (obj , type_tuple [0 ]):
173185 # call respective new_from function
174186 if isinstance (server , ansys .dpf .core .server_types .InProcessServer ) or not (
175- isinstance (obj , int ) or isinstance ( obj , str ) or isinstance ( obj , float ) or isinstance ( obj , bytes )
187+ isinstance (obj , ( int , str , float , bytes ) )
176188 ):
177189 any_dpf ._internal_obj = type_tuple [1 ](obj )
178190 else :
@@ -227,7 +239,7 @@ def cast(self, output_type=None):
227239 self ._internal_type = output_type if output_type is not None else self ._internal_type
228240
229241 for type_tuple in Any ._type_to_new_from_get_as_method (self ):
230- if self ._internal_type == type_tuple [0 ]:
242+ if issubclass ( self ._internal_type , type_tuple [0 ]) :
231243 # call the get_as function for the appropriate type
232244 internal_obj = type_tuple [2 ](self )
233245 if (
@@ -239,14 +251,7 @@ def cast(self, output_type=None):
239251 ):
240252 obj = internal_obj
241253 else :
242- # get current type's constructors' variable keyword for passing the internal_obj
243- internal_obj_keyword = type_to_internal_object_keyword ()[type_tuple [0 ]]
244-
245- # wrap parameters in a dictionary for parameters expansion when calling
246- # constructor
247- keyword_args = {internal_obj_keyword : internal_obj , "server" : self ._server }
248- # call constructor
249- obj = type_tuple [0 ](** keyword_args )
254+ return create_dpf_instance (self ._internal_type , internal_obj , self ._server )
250255
251256 return obj
252257
0 commit comments