Skip to content
Closed
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
59 changes: 59 additions & 0 deletions src/ansys/aedt/core/modeler/cad/primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -5868,6 +5868,65 @@ def wrap_sheet(self, sheet, object, imprinted=False):
self.cleanup_objects()
return True

def project_sheet(self, sheet, object, thickness, draft_angle=0, angle_unit="deg", keep_originals=True):
"""Project sheet on an object.

If projection produces an unclassified operation it will be reverted.

Parameters
----------
sheet : str, int, or :class:`ansys.aedt.core.modeler.cad.object_3d.Object3d`
Sheet name, id, or sheet object.
object : list, str, int, or :class:`ansys.aedt.core.modeler.cad.object_3d.Object3d`
Object name, id, or solid object to be projected on.
thickness : float, str
Thickness of the projected sheet in model units.
draft_angle : float, str, optional
Draft angle for the projection. Default is ``0``.
angle_unit : str, optional
Angle unit. Default is ``deg``.
keep_originals : bool, optional
Whether to keep the original objects. Default is ``True``.

Returns
-------
bool
``True`` when successful, ``False`` when failed.

References
----------
>>> oEditor.ProjectSheet
"""
sheet = self.convert_to_selections(sheet, False)
object = self.convert_to_selections(object, False)

try:
unclassified = [i for i in self.unclassified_objects]
self.oeditor.ProjectSheet(
["NAME:Selections", "Selections:=", f"{sheet},{object}"],
[
"NAME:ProjectSheetParameters",
"Thickness:=",
self._app.value_with_units(thickness),
"DraftAngle:=",
self._app.value_with_units(draft_angle, angle_unit),
"KeepOriginals:=",
keep_originals,
],
)
unclassified_new = [i for i in self.unclassified_objects if i not in unclassified]
if unclassified_new:
self.logger.error("Failed to Project Sheet. Reverting to original objects.")
self._odesign.Undo()
return False
except Exception:
self.logger.error("Failed to Project Sheet.")
return False

if not keep_originals:
self.cleanup_objects()
return True

@pyaedt_function_handler(input_objects_list="assignment")
def heal_objects(
self,
Expand Down
32 changes: 32 additions & 0 deletions tests/system/general/test_02_3D_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

import logging
import secrets

from mock import PropertyMock
from mock import patch
import pytest

from ansys.aedt.core.generic.constants import Axis
Expand Down Expand Up @@ -1231,3 +1234,32 @@ def test_pointing_to_axis(self):
assert go.is_vector_equal(x, [0.7053456158585983, 0.07053456158585983, 0.7053456158585983])
assert go.is_vector_equal(y, [0.19470872568244801, 0.9374864569895649, -0.28845737138140465])
assert go.is_vector_equal(z, [-0.681598176590997, 0.3407990882954985, 0.6475182677614472])

def test_65_project_sheet(self, caplog: pytest.LogCaptureFixture):
rect1 = self.aedtapp.modeler.create_rectangle(Plane.XY, [-5, -5, 15], [10, 20], "sheet1")
rect2 = self.aedtapp.modeler.create_rectangle(Plane.XY, [-3, -3, 15], [6, 16], "sheet2")
box1 = self.aedtapp.modeler.create_box([-10, -10, -10], [20, 20, 20], "box1")
box2 = self.aedtapp.modeler.create_box([-1, -1, 10], [2, 2, 2], "box2")
assert self.aedtapp.modeler.project_sheet(rect1, box1, 1)
self.aedtapp.odesign.Undo()
assert self.aedtapp.modeler.project_sheet(rect1, [box1, box2], 1)
self.aedtapp.odesign.Undo()

with patch.object(
type(self.aedtapp.modeler),
"unclassified_objects",
new_callable=PropertyMock,
side_effect=[["unclassified"], ["unclassified", "unclassified2"]],
):
self.aedtapp.logger.clear_messages(level=2)
result = self.aedtapp.modeler.project_sheet(rect1, box1, 1)
assert [
record
for record in caplog.records
if record.levelno == logging.ERROR
and record.message == "Failed to Project Sheet. Reverting to original objects."
]
assert not result

self.aedtapp.modeler.subtract([rect1], [rect2])
assert not self.aedtapp.modeler.project_sheet(rect1, [box1, box2], 5) # This projection will fail.