diff --git a/doc/changelog.d/4398.added.md b/doc/changelog.d/4398.added.md new file mode 100644 index 00000000000..f83c9a07307 --- /dev/null +++ b/doc/changelog.d/4398.added.md @@ -0,0 +1 @@ +Implement named-object commands using root-level commands diff --git a/src/ansys/fluent/core/services/settings.py b/src/ansys/fluent/core/services/settings.py index 89781ac4d84..2f22176ddda 100644 --- a/src/ansys/fluent/core/services/settings.py +++ b/src/ansys/fluent/core/services/settings.py @@ -345,11 +345,17 @@ def get_static_info(self) -> dict[str, Any]: @_trace def execute_cmd(self, path: str, command: str, **kwds) -> Any: - """Execute a given command with the provided keyword arguments.""" + """Execute a given command with the provided keyword arguments. + + If `path` is in kwds, rename it to `path_1` to avoid conflict with + the `path` argument. + """ request = _get_request_instance_for_path( SettingsModule.ExecuteCommandRequest, path ) request.command = command + if "path_1" in kwds: + kwds["path"] = kwds.pop("path_1") self._set_state_from_value(request.args, kwds) response = self._service_impl.execute_cmd(request) diff --git a/src/ansys/fluent/core/solver/flobject.py b/src/ansys/fluent/core/solver/flobject.py index 7d905289813..2661366eaee 100644 --- a/src/ansys/fluent/core/solver/flobject.py +++ b/src/ansys/fluent/core/solver/flobject.py @@ -1501,6 +1501,21 @@ def __add__(self, other): ) return CombinedNamedObject([self, other]) + def list(self): + """Print the object names.""" + return self._root.list(object_path=self.path) + + def list_properties(self, object_name): + """Print the properties of the given object name. + + Parameters + ---------- + object_name : str + Name of the object whose properties are to be listed. + """ + # The generated parameter name is path_1 as the name path clashes with existing property. + return self._root.list_properties(path_1=self.path, name=object_name) + class CombinedNamedObject: """A ``CombinedNamedObject`` contains the concatenated named-objects.""" @@ -1762,6 +1777,8 @@ def _execute_command(self, *args, **kwds): else: print("Please enter 'y[es]' or 'n[o]'.") with self._while_executing_command(): + if "path" in kwds: + kwds["path_1"] = kwds.pop("path") ret = self.flproxy.execute_cmd(self._parent.path, self.obj_name, **kwds) if ( not config.disable_parameter_list_return_fix diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index 02f746011c5..98c6fce0c6e 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -28,9 +28,10 @@ from ansys.fluent.core import config from ansys.fluent.core.examples import download_file from ansys.fluent.core.pyfluent_warnings import PyFluentUserWarning -from ansys.fluent.core.solver import Viscous +from ansys.fluent.core.solver import VelocityInlets, Viscous from ansys.fluent.core.solver.flobject import ( DeprecatedSettingWarning, + NamedObject, _Alias, _InputFile, _OutputFile, @@ -795,6 +796,17 @@ def test_setting_string_constants(mixing_elbow_settings_session): viscous.k_epsilon_model = viscous.k_epsilon_model.EASM +@pytest.mark.fluent_version(">=24.2") +def test_named_object_commands(mixing_elbow_settings_session): + solver = mixing_elbow_settings_session + inlets = VelocityInlets(solver) + inlets.list() + inlets.list_properties(object_name="hot-inlet") + if solver.get_fluent_version() >= FluentVersion.v261: + NamedObject.list(inlets) + NamedObject.list_properties(inlets, object_name="hot-inlet") + + @pytest.mark.fluent_version(">=26.1") def test_migration_adapter_for_strings(mixing_elbow_settings_session): solver = mixing_elbow_settings_session