Skip to content

Commit

Permalink
Reverted _refresh_from_aedt method to keep 22R2 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
maxcapodi78 committed Jan 16, 2025
1 parent e336b78 commit 17a2ec6
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,13 @@ def _create_point(self, name):

@pyaedt_function_handler()
def _refresh_all_ids_wrapper(self):
if settings.aedt_version >= "2023.2":
return self._refresh_all_ids_from_data_model()
else:
return self._refresh_all_ids_from_aedt_file()

@pyaedt_function_handler()
def _refresh_all_ids_from_data_model(self):
self._app.logger.info("Refreshing bodies from Object Info")
self._app.logger.reset_timer()
import json
Expand Down Expand Up @@ -882,6 +889,83 @@ def _refresh_all_ids_wrapper(self):
self._app.logger.info_timer("Bodies Info Refreshed")
return len(self.objects)

@pyaedt_function_handler()
def _refresh_all_ids_from_aedt_file(self):
self._app.logger.info("Refreshing objects from AEDT file")

dp = copy.deepcopy(self._app.design_properties)
if not dp or "ModelSetup" not in dp:
return False

try:
groups = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["Groups"]["Group"]
except KeyError:
groups = []
if not isinstance(groups, list):
groups = [groups]
try:
dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"]
except KeyError:
return 0

for el in dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"]:
if isinstance(el, dict):
attribs = el["Attributes"]
operations = el.get("Operations", None)
else:
attribs = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"][
"Attributes"
]
operations = dp["ModelSetup"]["GeometryCore"]["GeometryOperations"]["ToplevelParts"]["GeometryPart"][
"Operations"
]
if attribs["Name"] in self._all_object_names:
pid = 0

if operations and isinstance(operations.get("Operation", None), dict):
try:
pid = operations["Operation"]["ParentPartID"]
except Exception as e: # pragma: no cover
self.logger.debug(e)
elif operations and isinstance(operations.get("Operation", None), list):
try:
pid = operations["Operation"][0]["ParentPartID"]
except Exception as e:
self.logger.debug(e)

is_polyline = False
if operations and "PolylineParameters" in operations.get("Operation", {}):
is_polyline = True

o = self._create_object(name=attribs["Name"], pid=pid, use_cached=True, is_polyline=is_polyline)
o._part_coordinate_system = attribs["PartCoordinateSystem"]
if "NonModel" in attribs["Flags"]:
o._model = False
else:
o._model = True
if "Wireframe" in attribs["Flags"]:
o._wireframe = True
else:
o._wireframe = False
groupname = ""
for group in groups:
if attribs["GroupId"] == group["GroupID"]:
groupname = group["Attributes"]["Name"]

o._m_groupName = groupname
try:
o._color = tuple(int(x) for x in attribs["Color"][1:-1].split(" "))
except Exception:
o._color = None
o._surface_material = attribs.get("SurfaceMaterialValue", None)
if o._surface_material:
o._surface_material = o._surface_material[1:-1].lower()
if "MaterialValue" in attribs:
o._material_name = attribs["MaterialValue"][1:-1].lower()

o._is_updated = True
return len(self.objects)

@pyaedt_function_handler()
def cleanup_objects(self):
"""Clean up objects that no longer exist in the modeler because they were removed by previous operations.
Expand Down

0 comments on commit 17a2ec6

Please sign in to comment.