Skip to content

Commit

Permalink
Add detach_faces method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzovecchietti committed Apr 18, 2024
1 parent 2199664 commit c332134
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
11 changes: 11 additions & 0 deletions _unittest/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pyaedt.generic.general_methods import time_fn
from pyaedt.modeler.cad.elements3d import EdgePrimitive
from pyaedt.modeler.cad.elements3d import FacePrimitive
from pyaedt.modeler.cad.object3d import Object3d


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -671,3 +672,13 @@ def test_20_simplify_objects(self):
)
assert not self.aedtapp.modeler.simplify_objects(input_objects_list=None)
assert not self.aedtapp.modeler.simplify_objects(input_objects_list=1)

def test_21_detach_faces(self):
box = self.aedtapp.modeler.create_box([0, 0, 0], [1, 2, 3])
out_obj = box.detach_faces(box.top_face_z)
assert len(out_obj) == 1
assert isinstance(out_obj[0], Object3d)
box = self.aedtapp.modeler.create_box([0, 0, 0], [1, 2, 3])
out_obj = box.detach_faces([box.top_face_z.id, box.bottom_face_z.id])
assert len(out_obj) == 2
assert all(isinstance(o, Object3d) for o in out_obj)
30 changes: 30 additions & 0 deletions pyaedt/modeler/cad/object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,36 @@ def section(self, plane, create_new=True, section_cross_object=False):
self._primitives.section(self, plane, create_new, section_cross_object)
return self

@pyaedt_function_handler()
def detach_faces(self, faces):
"""Section the object.
Parameters
----------
faces : List[FacePrimitive] or List[int] or int or FacePrimitive
Face or faces to be detached from the object.
Returns
-------
List[:class:`pyaedt.modeler.cad.object3d.Object3d`]
List of object resulting from the operation.
References
----------
>>> oEditor.DetachFaces
"""
if isinstance(faces, FacePrimitive) or isinstance(faces, int):
faces = [faces]
if isinstance(faces[0], FacePrimitive):
faces = [f.id for f in faces]
result = self._primitives.oeditor.DetachFaces(
["NAME:Selections", "Selections:=", self.name, "NewPartsModelFlag:=", "Model"],
["NAME:Parameters", ["NAME:DetachFacesToParameters", "FacesToDetach:=", faces]],
)
return [getattr(self._primitives, "_modeler")[o] for o in result]

@pyaedt_function_handler()
def clone(self):
"""Clone the object and return the new 3D object.
Expand Down

0 comments on commit c332134

Please sign in to comment.