@@ -379,7 +379,9 @@ def python_name(self) -> str:
379379
380380 def _set_python_name (self ):
381381 this_command = self ._command ()
382- self ._python_name = camel_to_snake_case (this_command .get_attr ("helpString" ))
382+ self ._python_name = camel_to_snake_case (
383+ this_command .get_attr ("APIName" ) or this_command .get_attr ("helpString" )
384+ )
383385 self ._cache_data (this_command )
384386
385387 def _cache_data (self , command ):
@@ -429,7 +431,10 @@ def __getattr__(self, attr):
429431 return ArgumentWrapper (self , attr )
430432 except Exception as ex :
431433 logger .debug (str (ex ))
432- return self ._task_objects .get (attr , None )
434+ result = self ._task_objects .get (attr , None )
435+ if result :
436+ return result
437+ return super ().__getattribute__ (attr )
433438
434439 def __setattr__ (self , attr , value ):
435440 logger .debug (f"BaseTask.__setattr__({ attr } , { value } )" )
@@ -490,18 +495,15 @@ def update_child_tasks(self, setup_type_changed: bool):
490495 """Update child tasks."""
491496 self ._task .UpdateChildTasks (SetupTypeChanged = setup_type_changed )
492497
493- def insert_compound_child_task (self ):
494- """Insert a compound child task."""
495- return self ._task .InsertCompoundChildTask ()
496-
497498 def _get_next_python_task_names (self ) -> list [str ]:
498499 self ._python_task_names_map = {}
499500 for command_name in self ._task .GetNextPossibleTasks ():
501+ comm_obj = getattr (
502+ self ._command_source ._command_source , command_name
503+ ).create_instance ()
500504 self ._python_task_names_map [
501505 camel_to_snake_case (
502- getattr (self ._command_source ._command_source , command_name )
503- .create_instance ()
504- .get_attr ("helpString" )
506+ comm_obj .get_attr ("APIName" ) or comm_obj .get_attr ("helpString" )
505507 )
506508 ] = command_name
507509 return list (self ._python_task_names_map .keys ())
@@ -1163,6 +1165,10 @@ def _add_child(self, state: Optional[dict] = None) -> None:
11631165 state .update ({"add_child" : "yes" })
11641166 self .arguments .update_dict (state )
11651167
1168+ def insert_compound_child_task (self ):
1169+ """Insert a compound child task."""
1170+ return self .add_child_and_update ()
1171+
11661172 def add_child_and_update (self , state = None , defer_update = None ):
11671173 """Add a child to this CompoundTask and update.
11681174
@@ -1183,18 +1189,20 @@ def add_child_and_update(self, state=None, defer_update=None):
11831189 )
11841190 self ._command_source ._compound_child = True
11851191 self ._command_source ._parent_of_compound_child = py_name
1186- if self ._fluent_version >= FluentVersion .v241 :
1187- if defer_update is None :
1188- defer_update = False
1189- self ._task .AddChildAndUpdate (DeferUpdate = defer_update )
1190- else :
1191- if defer_update is not None :
1192- warnings .warn (
1193- " The 'defer_update()' method is supported in Fluent 2024 R1 and later." ,
1194- PyFluentUserWarning ,
1195- )
1196- self ._task .AddChildAndUpdate ()
1197- self ._command_source ._compound_child = False
1192+ try :
1193+ if self ._fluent_version >= FluentVersion .v241 :
1194+ if defer_update is None :
1195+ defer_update = False
1196+ self ._task .AddChildAndUpdate (DeferUpdate = defer_update )
1197+ else :
1198+ if defer_update is not None :
1199+ warnings .warn (
1200+ "The 'defer_update()' method is supported in Fluent 2024 R1 and later." ,
1201+ PyFluentUserWarning ,
1202+ )
1203+ self ._task .AddChildAndUpdate ()
1204+ finally :
1205+ self ._command_source ._compound_child = False
11981206 return self .last_child ()
11991207
12001208 def last_child (self ) -> BaseTask :
@@ -1324,6 +1332,29 @@ def task(self, name: str) -> BaseTask:
13241332
13251333 The wrapper adds extra functionality.
13261334
1335+ Parameters
1336+ ----------
1337+ name : str
1338+ Task name - the display name, not the internal ID.
1339+ Returns
1340+ -------
1341+ BaseTask
1342+ wrapped task object.
1343+ """
1344+ py_name = self .tasks ()[
1345+ [repr (task ) for task in self .tasks ()].index (repr (self ._task (name )))
1346+ ].python_name ()
1347+ warnings .warn (
1348+ f"'task' is deprecated -> Use '{ py_name } ' instead." ,
1349+ PyFluentDeprecationWarning ,
1350+ )
1351+ return self ._task (name )
1352+
1353+ def _task (self , name : str ) -> BaseTask :
1354+ """Get a TaskObject by name, in a ``BaseTask`` wrapper.
1355+
1356+ The wrapper adds extra functionality.
1357+
13271358 Parameters
13281359 ----------
13291360 name : str
@@ -1393,7 +1424,7 @@ def inactive_tasks() -> list:
13931424 def __getattr__ (self , attr ):
13941425 """Delegate attribute lookup to the wrapped workflow object."""
13951426 if attr in self ._repeated_task_python_name_display_text_map :
1396- return self .task (self ._repeated_task_python_name_display_text_map [attr ])
1427+ return self ._task (self ._repeated_task_python_name_display_text_map [attr ])
13971428 _task_object = self ._task_objects .get (attr )
13981429 if _task_object :
13991430 return _task_object
@@ -1453,7 +1484,7 @@ def _workflow_and_task_list_state(self) -> Tuple[dict, dict]:
14531484 def _task_by_id_impl (self , task_id , workflow_state ):
14541485 task_key = "TaskObject:" + task_id
14551486 task_state = workflow_state [task_key ]
1456- return self .task (task_state ["_name_" ])
1487+ return self ._task (task_state ["_name_" ])
14571488
14581489 def _task_by_id (self , task_id ):
14591490 workflow_state = self ._workflow_state ()
@@ -1536,7 +1567,9 @@ def _populate_first_tasks_python_name_command_id_map(self):
15361567 if isinstance (command_obj , PyCommand ):
15371568 command_obj_instance = command_obj .create_instance ()
15381569 if not command_obj_instance .get_attr ("requiredInputs" ):
1539- help_str = command_obj_instance .get_attr ("helpString" )
1570+ help_str = command_obj_instance .get_attr (
1571+ "APIName"
1572+ ) or command_obj_instance .get_attr ("helpString" )
15401573 if help_str :
15411574 self ._initial_task_python_names_map [help_str ] = command
15421575 del command_obj_instance
0 commit comments