MasterBody#

class ansys.geometry.core.designer.body.MasterBody(id: str, name: str, grpc_client: ansys.geometry.core.connection.client.GrpcClient, is_surface: bool = False)#

Bases: IBody

Represents solids and surfaces organized within the design assembly.

Solids and surfaces synchronize to a design within a supporting Geometry service instance.

Parameters:
idstr

Server-defined ID for the body.

namestr

User-defined label for the body.

parent_componentComponent

Parent component to place the new component under within the design assembly.

grpc_clientGrpcClient

Active supporting geometry service instance for design modeling.

is_surfacebool, default: False

Whether the master body is a surface or an 3D object (with volume). The default is False, in which case the master body is a surface. When True, the master body is a 3D object (with volume).

Overview#

imprint_curves

Imprint all specified geometries onto specified faces of the body.

project_curves

Project all specified geometries onto the body.

imprint_projected_curves

Project and imprint specified geometries onto the body.

plot

Plot the body.

intersect

Intersect two (or more) bodies.

subtract

Subtract two (or more) bodies.

unite

Unite two (or more) bodies.

reset_tessellation_cache

Decorate MasterBody methods that need tessellation cache update.

assign_material

Assign a material against the active design.

add_midsurface_thickness

Add a mid-surface thickness to a surface body.

add_midsurface_offset

Add a mid-surface offset to a surface body.

translate

Translate the body in a specified direction and distance.

rotate

Rotate the geometry body around the specified axis by a given angle.

scale

Scale the geometry body by the given value.

map

Map the geometry body to the new specified frame.

mirror

Mirror the geometry body across the specified plane.

get_collision

Get the collision state between bodies.

copy

Create a copy of the body under the specified parent.

tessellate

Tessellate the body and return the geometry as triangles.

id

Get the ID of the body as a string.

name

Get the name of the body.

is_surface

Check if the body is a planar body.

surface_thickness

Get the surface thickness of a surface body.

surface_offset

Get the surface offset type of a surface body.

faces

Get a list of all faces within the body.

edges

Get a list of all edges within the body.

is_alive

Check if the body is still alive and has not been deleted.

volume

Calculate the volume of the body.

__repr__

Represent the master body as a string.

Import detail#

from ansys.geometry.core.designer.body import MasterBody

Property detail#

property MasterBody.id: str#

Get the ID of the body as a string.

property MasterBody.name: str#

Get the name of the body.

property MasterBody.is_surface: bool#

Check if the body is a planar body.

property MasterBody.surface_thickness: beartype.typing.Union[pint.Quantity, None]#

Get the surface thickness of a surface body.

Notes

This method is only for surface-type bodies that have been assigned a surface thickness.

property MasterBody.surface_offset: beartype.typing.Union[MidSurfaceOffsetType, None]#

Get the surface offset type of a surface body.

Notes

This method is only for surface-type bodies that have been assigned a surface offset.

property MasterBody.faces: beartype.typing.List[ansys.geometry.core.designer.face.Face]#

Get a list of all faces within the body.

Returns:
List[Face]
property MasterBody.edges: beartype.typing.List[ansys.geometry.core.designer.edge.Edge]#

Get a list of all edges within the body.

Returns:
List[Edge]
property MasterBody.is_alive: bool#

Check if the body is still alive and has not been deleted.

property MasterBody.volume: pint.Quantity#

Calculate the volume of the body.

Notes

When dealing with a planar surface, a value of 0 is returned as a volume.

Method detail#

MasterBody.reset_tessellation_cache()#

Decorate MasterBody methods that need tessellation cache update.

Parameters:
funcmethod

Method to call.

Returns:
Any

Output of the method, if any.

MasterBody.assign_material(material: ansys.geometry.core.materials.material.Material) None#

Assign a material against the active design.

Parameters:
materialMaterial

Source material data.

MasterBody.add_midsurface_thickness(thickness: pint.Quantity) None#

Add a mid-surface thickness to a surface body.

Parameters:
thicknessQuantity

Thickness to assign.

Notes

Only surface bodies are eligible for mid-surface thickness assignment.

MasterBody.add_midsurface_offset(offset: MidSurfaceOffsetType) None#

Add a mid-surface offset to a surface body.

Parameters:
offset_typeMidSurfaceOffsetType

Surface offset to assign.

Notes

Only surface bodies are eligible for mid-surface offset assignment.

abstract MasterBody.imprint_curves(faces: beartype.typing.List[ansys.geometry.core.designer.face.Face], sketch: ansys.geometry.core.sketch.sketch.Sketch) beartype.typing.Tuple[beartype.typing.List[ansys.geometry.core.designer.edge.Edge], beartype.typing.List[ansys.geometry.core.designer.face.Face]]#

Imprint all specified geometries onto specified faces of the body.

Parameters:
faces: List[Face]

List of faces to imprint the curves of the sketch onto.

sketch: Sketch

All curves to imprint on the faces.

Returns:
Tuple[List[Edge], List[Face]]

All impacted edges and faces from the imprint operation.

abstract MasterBody.project_curves(direction: ansys.geometry.core.math.vector.UnitVector3D, sketch: ansys.geometry.core.sketch.sketch.Sketch, closest_face: bool, only_one_curve: beartype.typing.Optional[bool] = False) beartype.typing.List[ansys.geometry.core.designer.face.Face]#

Project all specified geometries onto the body.

Parameters:
direction: UnitVector3D

Direction of the projection.

sketch: Sketch

All curves to project on the body.

closest_face: bool

Whether to target the closest face with the projection.

only_one_curve: bool, default: False

Whether to project only one curve of the entire sketch. When True, only one curve is projected.

Returns:
List[Face]

All faces from the project curves operation.

Notes

The only_one_curve parameter allows you to optimize the server call because projecting curves is an expensive operation. This reduces the workload on the server side.

abstract MasterBody.imprint_projected_curves(direction: ansys.geometry.core.math.vector.UnitVector3D, sketch: ansys.geometry.core.sketch.sketch.Sketch, closest_face: bool, only_one_curve: beartype.typing.Optional[bool] = False) beartype.typing.List[ansys.geometry.core.designer.face.Face]#

Project and imprint specified geometries onto the body.

This method combines the project_curves() and imprint_curves() method into one method. It has higher performance than calling them back-to-back when dealing with many curves. Because it is a specialized function, this method only returns the faces (and not the edges) from the imprint operation.

Parameters:
direction: UnitVector3D

Direction of the projection.

sketch: Sketch

All curves to project on the body.

closest_face: bool

Whether to target the closest face with the projection.

only_one_curve: bool, default: False

Whether to project only one curve of the entire sketch. When True, only one curve is projected.

Returns:
List[Face]

All imprinted faces from the operation.

Notes

The only_one_curve parameter allows you to optimize the server call because projecting curves is an expensive operation. This reduces the workload on the server side.

MasterBody.translate(direction: ansys.geometry.core.math.vector.UnitVector3D, distance: beartype.typing.Union[pint.Quantity, ansys.geometry.core.misc.measurements.Distance, ansys.geometry.core.typing.Real]) None#

Translate the body in a specified direction and distance.

Parameters:
direction: UnitVector3D

Direction of the translation.

distance: Union[~pint.Quantity, Distance, Real]

Distance (magnitude) of the translation.

Returns:
None
MasterBody.rotate(axis_origin: ansys.geometry.core.math.point.Point3D, axis_direction: ansys.geometry.core.math.vector.UnitVector3D, angle: beartype.typing.Union[pint.Quantity, ansys.geometry.core.misc.measurements.Angle, ansys.geometry.core.typing.Real]) None#

Rotate the geometry body around the specified axis by a given angle.

Parameters:
axis_origin: Point3D

Origin of the rotational axis.

axis_direction: UnitVector3D

The axis of rotation.

angle: Union[~pint.Quantity, Angle, Real]

Angle (magnitude) of the rotation.

Returns:
None
MasterBody.scale(value: ansys.geometry.core.typing.Real) None#

Scale the geometry body by the given value.

Parameters:
value: Real

Value to scale the body by.

Notes

The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.

MasterBody.map(frame: ansys.geometry.core.math.frame.Frame) None#

Map the geometry body to the new specified frame.

Parameters:
frame: Frame

Structure defining the orientation of the body.

Notes

The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.

MasterBody.mirror(plane: ansys.geometry.core.math.plane.Plane) None#

Mirror the geometry body across the specified plane.

Parameters:
plane: Plane

Represents the mirror.

Notes

The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.

MasterBody.get_collision(body: Body) CollisionType#

Get the collision state between bodies.

Parameters:
body: Body

Object that the collision state is checked with.

Returns:
CollisionType

Enum that defines the collision state between bodies.

MasterBody.copy(parent: ansys.geometry.core.designer.component.Component, name: str = None) Body#

Create a copy of the body under the specified parent.

Parameters:
parent: Component

Parent component to place the new body under within the design assembly.

name: str

Name to give the new body.

Returns:
Body

Copy of the body.

MasterBody.tessellate(merge: beartype.typing.Optional[bool] = False, transform: ansys.geometry.core.math.matrix.Matrix44 = IDENTITY_MATRIX44) beartype.typing.Union[pyvista.PolyData, pyvista.MultiBlock]#

Tessellate the body and return the geometry as triangles.

Parameters:
mergebool, default: False

Whether to merge the body into a single mesh. When False (default), the number of triangles are preserved and only the topology is merged. When True, the individual faces of the tessellation are merged.

Returns:
PolyData, MultiBlock

Merged pyvista.PolyData if merge=True or a composite dataset.

Examples

Extrude a box centered at the origin to create a rectangular body and tessellate it:

>>> from ansys.geometry.core.misc.units import UNITS as u
>>> from ansys.geometry.core.sketch import Sketch
>>> from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D
>>> from ansys.geometry.core import Modeler
>>> modeler = Modeler()
>>> origin = Point3D([0, 0, 0])
>>> plane = Plane(origin, direction_x=[1, 0, 0], direction_y=[0, 0, 1])
>>> sketch = Sketch(plane)
>>> box = sketch.box(Point2D([2, 0]), 4, 4)
>>> design = modeler.create_design("my-design")
>>> my_comp = design.add_component("my-comp")
>>> body = my_comp.extrude_sketch("my-sketch", sketch, 1 * u.m)
>>> blocks = body.tessellate()
>>> blocks
>>> MultiBlock (0x7f94ec757460)
     N Blocks:  6
     X Bounds:  0.000, 4.000
     Y Bounds:  -1.000, 0.000
     Z Bounds:  -0.500, 4.500

Merge the body:

>>> mesh = body.tessellate(merge=True)
>>> mesh
PolyData (0x7f94ec75f3a0)
  N Cells:      12
  N Points:     24
  X Bounds:     0.000e+00, 4.000e+00
  Y Bounds:     -1.000e+00, 0.000e+00
  Z Bounds:     -5.000e-01, 4.500e+00
  N Arrays:     0
abstract MasterBody.plot(merge: bool = False, screenshot: beartype.typing.Optional[str] = None, use_trame: beartype.typing.Optional[bool] = None, **plotting_options: beartype.typing.Optional[dict]) None#

Plot the body.

Parameters:
mergebool, default: False

Whether to merge the body into a single mesh. When False (default), the number of triangles are preserved and only the topology is merged. When True, the individual faces of the tessellation are merged.

screenshotstr, default: None

Path for saving a screenshot of the image that is being represented.

use_tramebool, default: None

Whether to enable the use of trame. The default is None, in which case the USE_TRAME global setting is used.

**plotting_optionsdict, default: None

Keyword arguments for plotting. For allowable keyword arguments, see the Plotter.add_mesh method.

Examples

Extrude a box centered at the origin to create rectangular body and plot it:

>>> from ansys.geometry.core.misc.units import UNITS as u
>>> from ansys.geometry.core.sketch import Sketch
>>> from ansys.geometry.core.math import Plane, Point2D, Point3D, UnitVector3D
>>> from ansys.geometry.core import Modeler
>>> modeler = Modeler()
>>> origin = Point3D([0, 0, 0])
>>> plane = Plane(origin, direction_x=[1, 0, 0], direction_y=[0, 0, 1])
>>> sketch = Sketch(plane)
>>> box = sketch.box(Point2D([2, 0]), 4, 4)
>>> design = modeler.create_design("my-design")
>>> mycomp = design.add_component("my-comp")
>>> body = mycomp.extrude_sketch("my-sketch", sketch, 1 * u.m)
>>> body.plot()

Plot the body and color each face individually:

>>> body.plot(multi_colors=True)
abstract MasterBody.intersect(other: beartype.typing.Union[Body, beartype.typing.Iterable[Body]]) None#

Intersect two (or more) bodies.

Parameters:
otherBody

Body to intersect with.

Raises:
ValueError

If the bodies do not intersect.

Notes

The self parameter is directly modified with the result, and the other parameter is consumed. Thus, it is important to make copies if needed.

abstract MasterBody.subtract(other: beartype.typing.Union[Body, beartype.typing.Iterable[Body]]) None#

Subtract two (or more) bodies.

Parameters:
otherBody

Body to subtract from the self parameter.

Raises:
ValueError

If the subtraction results in an empty (complete) subtraction.

Notes

The self parameter is directly modified with the result, and the other parameter is consumed. Thus, it is important to make copies if needed.

abstract MasterBody.unite(other: beartype.typing.Union[Body, beartype.typing.Iterable[Body]]) None#

Unite two (or more) bodies.

Parameters:
otherBody

Body to unite with the self parameter.

Notes

The self parameter is directly modified with the result, and the other parameter is consumed. Thus, it is important to make copies if needed.

MasterBody.__repr__() str#

Represent the master body as a string.