diff --git a/doc/changelog.d/7383.added.md b/doc/changelog.d/7383.added.md new file mode 100644 index 000000000000..618b3ca6c791 --- /dev/null +++ b/doc/changelog.d/7383.added.md @@ -0,0 +1 @@ +Props test implementation for GetObjData diff --git a/src/ansys/aedt/core/application/__init__.py b/src/ansys/aedt/core/application/__init__.py index 6bea0105f95c..bd6a2af3a1c1 100644 --- a/src/ansys/aedt/core/application/__init__.py +++ b/src/ansys/aedt/core/application/__init__.py @@ -60,3 +60,66 @@ def _fix_dict(p_list, p_out) -> None: props = {} _fix_dict(props_list, props) return props + + +@pyaedt_function_handler() +def _get_obj_data(child_object): + import json + + def _obj_data_parser(node): + + # Case 1: If the node is a list, parse each item in the list + if isinstance(node, list): + return [_obj_data_parser(item) for item in node] + + # Case 2: If the node is a dictionary without "name", parse its values + if isinstance(node, dict) and "name" not in node: + return node + + # Case 3: schema dict with "name" + if isinstance(node, dict): + name = node.get("name") + + if "value" in node: + return {name: node["value"]} + + values = node.get("values", []) + + if not values: + return {name: {}} + + parsed_children = [_obj_data_parser(child) for child in values] + + result = {} + + for child in parsed_children: + if isinstance(child, dict): + for k, v in child.items(): + if k in result: + if not isinstance(result[k], list): + result[k] = [result[k]] + result[k].append(v) + else: + result[k] = v + else: + return {name: parsed_children} + + return {name: result} + # return result + + obj_data = child_object.GetObjData() + + data = json.loads(obj_data) + result = {} + + data_2 = data.get("data_2", []) + + if data_2 and isinstance(data_2, list): + values = data_2[0].get("values", []) + else: + values = [] + + for item in values: + result.update(_obj_data_parser(item)) + + return result diff --git a/src/ansys/aedt/core/application/design.py b/src/ansys/aedt/core/application/design.py index b275f77ba2b2..85f24ccff72c 100644 --- a/src/ansys/aedt/core/application/design.py +++ b/src/ansys/aedt/core/application/design.py @@ -45,6 +45,7 @@ from typing import Any from ansys.aedt.core.aedt_logger import AedtLogger +from ansys.aedt.core.application import _get_obj_data from ansys.aedt.core.application.aedt_objects import AedtObjects from ansys.aedt.core.application.design_solutions import DesignSolution from ansys.aedt.core.application.design_solutions import HFSSDesignSolution @@ -266,6 +267,11 @@ def __init__( if self._design_type not in ["Maxwell Circuit", "Circuit Netlist"]: self.design_settings = DesignSettings(self) + if self._aedt_version >= "2026.1": + self.__get_props = _get_obj_data + else: + self.__get_props = lambda obj: None + @property def _pyaedt_details(self) -> dict[str, str]: """Retrieve detailed session information for PyAEDT. @@ -518,16 +524,26 @@ def boundaries(self) -> list[BoundaryObject]: continue if boundarytype == "MaxwellParameters": maxwell_parameter_type = self.get_oo_property_value(self.odesign, f"Parameters\\{boundary}", "Type") - - self._boundaries[boundary] = MaxwellParameters(self, boundary, boundarytype=maxwell_parameter_type) + child_obj = self.get_oo_object(self.odesign, f"Parameters\\{boundary}") + props = self.__get_props(child_obj) + self._boundaries[boundary] = MaxwellParameters( + self, boundary, props=props, boundarytype=maxwell_parameter_type + ) elif boundarytype == "MotionSetup": maxwell_motion_type = self.get_oo_property_value(self.odesign, f"Model\\{boundary}", "Type") - - self._boundaries[boundary] = BoundaryObject(self, boundary, boundarytype=maxwell_motion_type) + child_obj = self.get_oo_object(self.odesign, f"Model\\{boundary}") + props = self.__get_props(child_obj) + self._boundaries[boundary] = BoundaryObject( + self, boundary, props=props, boundarytype=maxwell_motion_type + ) elif boundarytype == "Network": - self._boundaries[boundary] = NetworkObject(self, boundary) + child_obj = self.get_oo_object(self.odesign, f"Thermal\\{boundary}") + props = self.__get_props(child_obj) + self._boundaries[boundary] = NetworkObject(self, boundary, props=props) else: - self._boundaries[boundary] = BoundaryObject(self, boundary, boundarytype=boundarytype) + child_obj = self.get_oo_object(self.odesign, f"Boundaries\\{boundary}") + props = self.__get_props(child_obj) + self._boundaries[boundary] = BoundaryObject(self, boundary, props=props, boundarytype=boundarytype) try: for k, v in zip(current_excitations, current_excitation_types): diff --git a/src/ansys/aedt/core/modules/boundary/common.py b/src/ansys/aedt/core/modules/boundary/common.py index a4db78d024ae..438dc3aecf60 100644 --- a/src/ansys/aedt/core/modules/boundary/common.py +++ b/src/ansys/aedt/core/modules/boundary/common.py @@ -24,6 +24,7 @@ """This module contains these classes: ``BoundaryCommon`` and ``BoundaryObject``.""" +from ansys.aedt.core.application import _get_obj_data from ansys.aedt.core.base import PyAedtBase from ansys.aedt.core.generic.data_handlers import _dict2arg from ansys.aedt.core.generic.general_methods import PropsManager @@ -308,6 +309,18 @@ def props(self) -> BoundaryProps: self._type = props[1] return self.__props + @property + def props_test(self): + """Boundary data test.""" + if self.__props: + return self.__props + props = _get_obj_data(self._child_object) + + if props: + self.__props = BoundaryProps(self, props) + self._type = self.get_oo_property_value(self.odesign, f"Boundaries\\{self.name}", "Type") + return self.__props + @property def type(self) -> str: """Boundary type. diff --git a/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py b/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py index 8b10cb597859..6aa98ed78698 100644 --- a/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py +++ b/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py @@ -26,6 +26,7 @@ from dataclasses import dataclass from dataclasses import field +from ansys.aedt.core.application import _get_obj_data from ansys.aedt.core.base import PyAedtBase from ansys.aedt.core.generic.constants import SolutionsMaxwell3D from ansys.aedt.core.generic.data_handlers import _dict2arg @@ -235,6 +236,11 @@ def __init__(self, app, name, props=None, boundarytype=None) -> None: self.type = boundarytype self._initialize_tree_node() + if self._app._aedt_version >= "2026.1": + self.__get_props = _get_obj_data + else: + self.__get_props = lambda obj: None + @property def _child_object(self): cc = self._app.odesign.GetChildObject("Parameters") @@ -263,6 +269,19 @@ def props(self) -> BoundaryProps: self._type = props[1] return self.__props + @property + def props_test(self) -> BoundaryProps: + """Maxwell parameter data.""" + if self.__props: + return self.__props + + props = self.__get_props(self.child_object) + + if props: + self.__props = BoundaryProps(self, props) + self._type = self.get_oo_property_value(self.odesign, f"Parameters\\{self.name}", "Type") + return self.__props + @property def name(self) -> str: """Boundary Name.""" diff --git a/src/ansys/aedt/core/modules/mesh.py b/src/ansys/aedt/core/modules/mesh.py index 9994ebf1c091..0bbf67b2f0d3 100644 --- a/src/ansys/aedt/core/modules/mesh.py +++ b/src/ansys/aedt/core/modules/mesh.py @@ -27,6 +27,7 @@ import os import shutil +from ansys.aedt.core.application import _get_obj_data from ansys.aedt.core.base import PyAedtBase from ansys.aedt.core.generic.data_handlers import _dict2arg from ansys.aedt.core.generic.file_utils import generate_unique_name @@ -189,6 +190,13 @@ def props(self) -> MeshProps: self._legacy_props = MeshProps(self, props) return self._legacy_props + @property + def props_test(self): + if not self._legacy_props: + props = _get_obj_data(self._child_object) + self._legacy_props = MeshProps(self, props) + return self._legacy_props + @pyaedt_function_handler() def _get_args(self): """Retrieve arguments.""" diff --git a/src/ansys/aedt/core/modules/solve_setup.py b/src/ansys/aedt/core/modules/solve_setup.py index 3088b6529f1a..60deae8c3f01 100644 --- a/src/ansys/aedt/core/modules/solve_setup.py +++ b/src/ansys/aedt/core/modules/solve_setup.py @@ -39,6 +39,7 @@ from typing import TYPE_CHECKING import warnings +from ansys.aedt.core.application import _get_obj_data from ansys.aedt.core.base import PyAedtBase from ansys.aedt.core.generic.aedt_constants import DesignType from ansys.aedt.core.generic.constants import AEDT_UNITS @@ -307,6 +308,24 @@ def props(self) -> SetupProps: def props(self, value: dict) -> None: self._legacy_props = SetupProps(self, value) + @property + def props_test(self) -> SetupProps: + """Properties of the setup.""" + if self._legacy_props: + return self._legacy_props + if self._is_new_setup: + setup_template = SetupKeys.get_setup_templates()[self.setuptype] + setup_template["Name"] = self._name + self._legacy_props = SetupProps(self, setup_template) + self._is_new_setup = False + else: + setup_data = _get_obj_data(self._child_object) + self._legacy_props = SetupProps(self, setup_data) + + @props_test.setter + def props_test(self, value: dict) -> None: + self._legacy_props = SetupProps(self, value) + @property def is_solved(self) -> bool: """Verify if solutions are available for given setup. @@ -1163,30 +1182,6 @@ class SetupCircuit(CommonSetup): def __init__(self, app, solution_type, name: str = "MySetupAuto", is_new_setup: bool = True) -> None: CommonSetup.__init__(self, app, solution_type, name, is_new_setup) - @property - def props(self) -> SetupProps: - if self._legacy_props: - return self._legacy_props - if self._is_new_setup: - setup_template = SetupKeys.get_setup_templates()[self.setuptype] - setup_template["Name"] = self.name - self._legacy_props = SetupProps(self, setup_template) - self._is_new_setup = False - else: - self._legacy_props = SetupProps(self, {}) - try: - setups_data = self._app.design_properties["SimSetups"]["SimSetup"] - if not isinstance(setups_data, list): - setups_data = [setups_data] - for setup in setups_data: - if self.name == setup["Name"]: - setup_data = setup - setup_data.pop("Sweeps", None) - self._legacy_props = SetupProps(self, setup_data) - except Exception: - self._legacy_props = SetupProps(self, {}) - return self._legacy_props - @property def _odesign(self): """Design.""" @@ -1876,31 +1871,6 @@ def sweeps(self) -> list["SweepHFSS3DLayout"]: pass return self._sweeps - @property - def props(self) -> SetupProps: - if self._legacy_props: - return self._legacy_props - if self._is_new_setup: - setup_template = SetupKeys.get_setup_templates()[self.setuptype] - setup_template["Name"] = self.name - self._legacy_props = SetupProps(self, setup_template) - self._is_new_setup = False - - else: - try: - setups_data = self._app.design_properties["Setup"]["Data"] - if self.name in setups_data: - setup_data = setups_data[self.name] - self._legacy_props = SetupProps(self, setup_data) - except Exception: - self._legacy_props = SetupProps(self, {}) - settings.logger.error("Unable to set props.") - return self._legacy_props - - @props.setter - def props(self, value: dict) -> None: - self._legacy_props = SetupProps(self, value) - @property def is_solved(self) -> bool: """Verify if solutions are available for a given setup.