Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/4398.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Implement named-object commands using root-level commands
8 changes: 7 additions & 1 deletion src/ansys/fluent/core/services/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/ansys/fluent/core/solver/flobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment refers to 'generated parameter name' but this is manually written code. The comment should clarify that path_1 is used to avoid conflict with the existing path property, and explain the parameter renaming mechanism.

Suggested change
# The generated parameter name is path_1 as the name path clashes with existing property.
# 'path_1' is used here to avoid a naming conflict with the existing 'path' property.
# When a parameter name would conflict with an existing property, a suffix (e.g., '_1') is added to the parameter name.

Copilot uses AI. Check for mistakes.

return self._root.list_properties(path_1=self.path, name=object_name)


class CombinedNamedObject:
"""A ``CombinedNamedObject`` contains the concatenated named-objects."""
Expand Down Expand Up @@ -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")
Comment on lines +1780 to +1781
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter renaming logic is duplicated in the settings.py file but in reverse. Consider extracting this logic into a utility function to avoid code duplication and ensure consistency.

Copilot uses AI. Check for mistakes.

ret = self.flproxy.execute_cmd(self._parent.path, self.obj_name, **kwds)
if (
not config.disable_parameter_list_return_fix
Expand Down
14 changes: 13 additions & 1 deletion tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down