Skip to content

Add detach_faces method #4534

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 6 commits into from
Apr 19, 2024
Merged
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
10 changes: 10 additions & 0 deletions _unittest/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -1965,3 +1965,13 @@ def test_91_primitives_builder(self, add_app):
primitives_builder = PrimitivesBuilder(q2d, input_dict=primitive_dict)
primitive_names = primitives_builder.create()
assert all(element is None for element in primitive_names)

def test_92_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) == 2
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) == 3
assert all(isinstance(o, Object3d) for o in out_obj)
34 changes: 34 additions & 0 deletions pyaedt/modeler/cad/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -3714,6 +3714,40 @@ def intersect(self, assignment, keep_originals=False, **kwargs):
self.logger.info("Intersection Succeeded")
return self.convert_to_selections(assignment[0], False)

@pyaedt_function_handler()
def detach_faces(self, assignment, faces):
"""Section the object.

Parameters
----------
assignment : Object3d or str
Object from which to detach faces.
faces : List[FacePrimitive] or List[int] or int or FacePrimitive
Face or faces to detach from the object.

Returns
-------
List[:class:`pyaedt.modeler.cad.object3d.Object3d`]
List of objects resulting from the operation (including the original one).

References
----------

>>> oEditor.DetachFaces

"""
if isinstance(assignment, str):
assignment = self._modeler[assignment]
if isinstance(faces, FacePrimitive) or isinstance(faces, int):
faces = [faces]
if isinstance(faces[0], FacePrimitive):
faces = [f.id for f in faces]
result = self.oeditor.DetachFaces(
["NAME:Selections", "Selections:=", assignment.name, "NewPartsModelFlag:=", "Model"],
["NAME:Parameters", ["NAME:DetachFacesToParameters", "FacesToDetach:=", faces]],
)
return [assignment] + [self._modeler[o] for o in result]

@pyaedt_function_handler(theList="assignment")
def connect(self, assignment):
"""Connect objects from a list.
Expand Down
22 changes: 22 additions & 0 deletions pyaedt/modeler/cad/object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,28 @@ 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 detach from the object.

Returns
-------
List[:class:`pyaedt.modeler.cad.object3d.Object3d`]
List of object resulting from the operation.

References
----------

>>> oEditor.DetachFaces

"""
return self._primitives.detach_faces(self, faces)

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