Skip to content

FIX: Improve the speed up of the cleanup of objects and delete of objects in modeler. #6170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from 6 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/6170.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve the speed up of the cleanup of objects and delete of objects in modeler.
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/modeler/cad/object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1854,7 +1854,7 @@
"""
arg = ["NAME:Selections", "Selections:=", self._m_name]
self._oeditor.Delete(arg)
self._primitives.cleanup_objects()
del self._primitives.objects[self._m_name]

Check warning on line 1857 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L1857

Added line #L1857 was not covered by tests
self.__dict__ = {}

@pyaedt_function_handler()
Expand Down
42 changes: 15 additions & 27 deletions src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@ def __len__(self):
else:
return len(self.__parent.user_defined_component_names)

def __delitem__(self, key):
if key in dict.keys(self):
obj_name = dict.__getitem__(self, key).name
dict.__delitem__(self, key)
del self.__obj_names[obj_name]
del self.__parent._object_names_to_ids[obj_name]

def __contains__(self, item):
if self.__refreshed:
return True if (item in dict.keys(self) or item in self.__obj_names) else False
Expand Down Expand Up @@ -826,7 +833,7 @@ def objects_by_name(self):
"""
obj_dict = {}
for _, v in self.objects.items():
obj_dict[v._m_name] = v
obj_dict[v.name] = v
return obj_dict

@pyaedt_function_handler()
Expand Down Expand Up @@ -1021,21 +1028,10 @@ def cleanup_solids(self):
Dictionary of updated object IDs.

"""
new_object_dict = {}
new_object_id_dict = {}

all_objects = self.object_names
all_unclassified = self._unclassified
all_objs = all_objects + all_unclassified
if sorted(all_objs) != sorted(list(self._object_names_to_ids.keys())):
for old_id, obj in self.objects.items():
if obj.name in all_objs:
# Check if ID can change in boolean operations
# updated_id = obj.id # By calling the object property we get the new id
new_object_id_dict[obj.name] = old_id
new_object_dict[old_id] = obj
self._object_names_to_ids = {}
self.objects = Objects(self, "o", new_object_dict)
all_objs = self.oeditor.GetChildNames()
for obj_name, obj_id in {i: k for i, k in self._object_names_to_ids.items() if i not in all_objs}.items():
del self.objects[obj_id]

@pyaedt_function_handler()
def cleanup_points(self):
Expand Down Expand Up @@ -1099,16 +1095,8 @@ def add_new_solids(self):
List of added objects.
"""
added_objects = []

for obj_name in self.object_names:
if obj_name not in self._object_names_to_ids:
try:
pid = self.oeditor.GetObjectIDByName(obj_name)
except Exception:
pid = 0
self._create_object(obj_name, pid=pid, use_cached=True)
added_objects.append(obj_name)
for obj_name in self.unclassified_names:
objs = self.oeditor.GetChildNames()
for obj_name in objs:
if obj_name not in self._object_names_to_ids:
try:
pid = self.oeditor.GetObjectIDByName(obj_name)
Expand Down Expand Up @@ -1502,8 +1490,8 @@ def uncover_faces(self, assignment):

Examples
--------
>>> from ansys.aedt.core import Maxwell3D
>>> app = Maxwell3D()
>>> from ansys.aedt.core import Maxwell3d
>>> app = Maxwell3d()
>>> circle_1 = app.modeler.create_circle(cs_plane=0, position=[0, 0, 0], radius=3, name="Circle1")
>>> box_1 = app.modeler.create_box(origin=[-13.9 ,0 ,0],sizes=[27.8,-40,25.4], name="Box1")
>>> app.modeler.uncover_faces([circle_1.faces[0], [box_1.faces[0], box_1.faces[2]]])
Expand Down
Loading