Skip to content
Draft
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
32 changes: 26 additions & 6 deletions src/ansys/aedt/core/modeler/cad/object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import math
from pathlib import Path
import re
import warnings

from ansys.aedt.core.base import PyAedtBase
from ansys.aedt.core.generic.constants import AEDT_UNITS
Expand Down Expand Up @@ -1017,18 +1018,37 @@ def object_type(self):

@property
def is3d(self):
"""Check for if the object is 3D.
"""Check if the object is a 3D solid object.

This method determines whether the current object represents a
three-dimensional solid geometry by checking its object type.

.. deprecated::
Use :func:`is_3d` property instead.

Returns
-------
bool
``True`` when successful, ``False`` when failed.
``True`` if the object is a 3D solid, ``False`` otherwise.
"""
warnings.warn("`is3d` is deprecated. Use `is_3d` property instead.", DeprecationWarning)
res = self.is_3d
return res

@property
def is_3d(self):
"""Check if the object is a 3D solid object.

This method determines whether the current object represents a
three-dimensional solid geometry by checking its object type.

Returns
-------
bool
``True`` if the object is a 3D solid, ``False`` otherwise.
"""
if self.object_type == "Solid":
return True
else:
return False
res = self.object_type == "Solid"
return res

@property
def mass(self):
Expand Down
77 changes: 37 additions & 40 deletions src/ansys/aedt/core/modeler/cad/primitives_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@
if TYPE_CHECKING:
from ansys.aedt.core.modeler.cad.object_3d import Object3d

# Error messages
ERROR_MSG_CENTER = "The ``center`` argument must be a valid three-element list."
ERROR_MSG_ORIGIN = "The ``origin`` argument must be a valid three-element list."
ERROR_MSG_RADIUS = "The ``radius`` argument must be greater than 0."
ERROR_MSG_SIZES_2 = "The ``sizes`` argument must be a valid two-element list."
ERROR_MSG_SIZES_3 = "The ``sizes`` argument must be a valid three-element list."


class Primitives3D(GeometryModeler, PyAedtBase):
"""Manages primitives in applications using the 3D modeler.
Expand Down Expand Up @@ -160,11 +167,9 @@ def create_box(self, origin, sizes, name=None, material=None, **kwargs) -> "Obje

"""
if len(origin) != 3:
self.logger.error("The ``position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)
if len(sizes) != 3:
self.logger.error("The ``dimension_list`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_SIZES_3)

x_position, y_position, z_position = self._pos_with_arg(origin)
x_size, y_size, z_size = self._pos_with_arg(sizes)
Expand Down Expand Up @@ -243,11 +248,9 @@ def create_cylinder(self, orientation, origin, radius, height, num_sides=0, name

"""
if isinstance(radius, (int, float)) and radius < 0:
self.logger.error("The ``radius`` argument must be greater than 0.")
return False
raise ValueError(ERROR_MSG_RADIUS)
if len(origin) != 3:
self.logger.error("The ``position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)

axis = GeometryOperators.cs_axis_str(orientation)
x_center, y_center, z_center = self._pos_with_arg(origin)
Expand Down Expand Up @@ -332,14 +335,11 @@ def create_polyhedron(self, orientation=None, center=(0.0, 0.0, 0.0), origin=(0.
"""
orientation = GeometryOperators.cs_axis_str(orientation)
if len(center) != 3:
self.logger.error("The ``center_position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_CENTER)
if len(origin) != 3:
self.logger.error("The ``start_position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)
if center == origin:
self.logger.error("The ``center_position`` and ``start_position`` arguments must be different.")
return False
raise ValueError("The ``center`` and ``origin`` arguments must be different.")

x_center, y_center, z_center = self._pos_with_arg(center)
x_start, y_start, z_start = self._pos_with_arg(origin)
Expand Down Expand Up @@ -419,17 +419,13 @@ def create_cone(self, orientation, origin, bottom_radius, top_radius, height, na

"""
if isinstance(bottom_radius, (int, float)) and bottom_radius < 0:
self.logger.error("The ``bottom_radius`` argument must be greater than 0.")
return False
raise ValueError("The ``bottom_radius`` argument must be greater than 0.")
if isinstance(top_radius, (int, float)) and top_radius < 0:
self.logger.error("The ``top_radius`` argument must be greater than 0.")
return False
raise ValueError("The ``top_radius`` argument must be greater than 0.")
if isinstance(height, (int, float)) and height <= 0:
self.logger.error("The ``height`` argument must be greater than 0.")
return False
raise ValueError("The ``height`` argument must be greater than 0.")
if len(origin) != 3:
self.logger.error("The ``position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)

x_center, y_center, z_center = self._pos_with_arg(origin)
axis = GeometryOperators.cs_axis_str(orientation)
Expand Down Expand Up @@ -492,10 +488,9 @@ def create_sphere(self, origin, radius, name=None, material=None, **kwargs):
>>> ret_object = aedtapp.modeler.create_sphere(origin=[0,0,0],radius=2,name="mysphere",material="copper")
"""
if len(origin) != 3:
self.logger.error("The ``position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)
if isinstance(radius, (int, float)) and radius < 0:
self.logger.error("The ``radius`` argument must be greater than 0.")
self.logger.error(ERROR_MSG_RADIUS)
return False

x_center, y_center, z_center = self._pos_with_arg(origin)
Expand Down Expand Up @@ -565,8 +560,7 @@ def create_torus(self, origin, major_radius, minor_radius, axis=None, name=None,

"""
if len(origin) != 3:
self.logger.error("The ``center`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)
# if major_radius <= 0 or minor_radius <= 0:
# raise ValueError("Both major and minor radius must be greater than 0.")
# if minor_radius >= major_radius:
Expand Down Expand Up @@ -663,12 +657,10 @@ def create_bondwire(self, start, end, h1=0.2, h2=0, alpha=80, beta=5, bond_type=
... beta=4,bond_type=0,name="mybox",material="copper")
"""
if len(start) != 3:
self.logger.error("The ``start_position`` argument must be a valid three-Element List")
return False
raise ValueError("The ``start`` argument must be a valid three-Element List")
x_position, y_position, z_position = self._pos_with_arg(start)
if len(end) != 3:
self.logger.error("The ``end_position`` argument must be a valid three-Element List")
return False
raise ValueError("The ``end`` argument must be a valid three-Element List")
x_position_end, y_position_end, z_position_end = self._pos_with_arg(end)

cont = 0
Expand Down Expand Up @@ -737,7 +729,16 @@ def create_bondwire(self, start, end, h1=0.2, h2=0, alpha=80, beta=5, bond_type=
return self._create_object(new_object_name, **kwargs)

@pyaedt_function_handler(csPlane="orientation", position="origin", dimension_list="sizes", matname="material")
def create_rectangle(self, orientation, origin, sizes, name=None, material=None, is_covered=True, **kwargs):
def create_rectangle(
self,
orientation,
origin,
sizes,
name=None,
material=None,
is_covered=True,
**kwargs
) -> "Object3d":
"""Create a rectangle.

Parameters
Expand Down Expand Up @@ -772,8 +773,7 @@ def create_rectangle(self, orientation, origin, sizes, name=None, material=None,
>>> oEditor.CreateRectangle
"""
if len(sizes) != 2:
self.logger.error("The ``sizes`` argument must be a valid two-element list.")
return False
raise ValueError(ERROR_MSG_SIZES_2)

axis = GeometryOperators.cs_plane_to_axis_str(orientation)
x_start, y_start, z_start = self._pos_with_arg(origin)
Expand Down Expand Up @@ -1223,8 +1223,7 @@ def create_helix(self, assignment, origin, x_start_dir, y_start_dir, z_start_dir
return False

if len(origin) != 3:
self.logger.error("The ``position`` argument must be a valid three-element list.")
return False
raise ValueError(ERROR_MSG_ORIGIN)
x_center, y_center, z_center = self._pos_with_arg(origin)

arg_1 = [
Expand Down Expand Up @@ -1369,11 +1368,9 @@ def create_spiral(self, internal_radius=10, spacing=1, faces=8, turns=10, width=
Polyline object or ``False`` if it fails.
"""
if internal_radius < 0:
self.logger.error("The ``internal_radius`` argument must be greater than 0.")
return False
raise ValueError("The ``internal_radius`` argument must be greater than 0.")
if faces < 0:
self.logger.error("The ``faces`` argument must be greater than 0.")
return False
raise ValueError("The ``faces`` argument must be greater than 0.")
dtheta = 2 * pi / faces
theta = pi / 2
pts = [(internal_radius, 0, elevation), (internal_radius, internal_radius * tan(dtheta / 2), elevation)]
Expand Down
Loading
Loading