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:
IBodyRepresents solids and surfaces organized within the design assembly.
Solids and surfaces synchronize to a design within a supporting Geometry service instance.
- Parameters:
- id
str Server-defined ID for the body.
- name
str User-defined label for the body.
- parent_component
Component Parent component to place the new component under within the design assembly.
- grpc_client
GrpcClient 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. WhenTrue, the master body is a 3D object (with volume).
- id
Overview#
Imprint all specified geometries onto specified faces of the body. |
|
Project all specified geometries onto the body. |
|
Project and imprint specified geometries onto the body. |
|
Create a copy of the body under the specified parent. |
|
Plot the body. |
|
Intersect two (or more) bodies. |
|
Subtract two (or more) bodies. |
|
Unite two (or more) bodies. |
Decorate |
|
Assign a material against the active design. |
|
Get the assigned material of the body. |
|
Remove the material assigned to the body. |
|
Add a mid-surface thickness to a surface body. |
|
Add a mid-surface offset to a surface body. |
|
Translate the body in a specified direction and distance. |
|
Set the name of the body. |
|
Set the fill style of the body. |
|
Set the body suppression state. |
|
Set the color of the body. |
|
Set the opacity of the body. |
|
Rotate the geometry body around the specified axis by a given angle. |
|
Scale the geometry body by the given value. |
|
Map the geometry body to the new specified frame. |
|
Mirror the geometry body across the specified plane. |
|
Get the collision state between bodies. |
|
Tessellate the body and return the raw tessellation data. |
|
Tessellate the body and return the geometry as triangles. |
|
Shell the body to the thickness specified. |
|
Shell by removing a given set of faces. |
|
Combine this body with another body or bodies, merging them into a single body. |
Get the ID of the body as a string. |
|
Get the name of the body. |
|
Get the fill style of the body. |
|
Get the body suppression state. |
|
Get the current color of the body. |
|
Get the float value of the opacity for the body. |
|
Check if the body is a planar body. |
|
Get the surface thickness of a surface body. |
|
Get the surface offset type of a surface body. |
|
Get a list of all faces within the body. |
|
Get a list of all edges within the body. |
|
Get a list of all vertices within the body. |
|
Check if the body is still alive and has not been deleted. |
|
Calculate the volume of the body. |
|
Get the assigned material of the body. |
|
Get the bounding box of the body. |
Represent the master body as a string. |
Import detail#
from ansys.geometry.core.designer.body import MasterBody
Property detail#
- property MasterBody.is_suppressed: bool#
Get the body suppression state.
Warning
This method is only available starting on Ansys release 25R2.
- property MasterBody.surface_thickness: 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: 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: list[ansys.geometry.core.designer.face.Face]#
Get a list of all faces within the body.
- Returns:
list[Face]
- property MasterBody.edges: list[ansys.geometry.core.designer.edge.Edge]#
Get a list of all edges within the body.
- Returns:
list[Edge]
- property MasterBody.vertices: list[ansys.geometry.core.designer.vertex.Vertex]#
Get a list of all vertices within the body.
- Returns:
list[Vertex]
- property MasterBody.volume: pint.Quantity#
Calculate the volume of the body.
Notes
When dealing with a planar surface, a value of
0is returned as a volume.
- property MasterBody.material: ansys.geometry.core.materials.material.Material#
Get the assigned material of the body.
- Returns:
MaterialMaterial assigned to the body.
- property MasterBody.bounding_box: ansys.geometry.core.math.bbox.BoundingBox#
Get the bounding box of the body.
- Returns:
BoundingBoxBounding box of the body.
Warning
This method is only available starting on Ansys release 25R2.
Method detail#
- MasterBody.reset_tessellation_cache()#
Decorate
MasterBodymethods that need tessellation cache update.- Parameters:
- func
method Method to call.
- func
- Returns:
AnyOutput of the method, if any.
- MasterBody.assign_material(material: ansys.geometry.core.materials.material.Material) None#
Assign a material against the active design.
- Parameters:
- material
Material Source material data.
- material
- MasterBody.get_assigned_material() ansys.geometry.core.materials.material.Material#
Get the assigned material of the body.
- Returns:
MaterialMaterial assigned to the body.
- MasterBody.add_midsurface_thickness(thickness: ansys.geometry.core.misc.measurements.Distance | pint.Quantity | ansys.geometry.core.typing.Real) None#
Add a mid-surface thickness to a surface body.
- Parameters:
- thickness
Distance|Quantity|Real Thickness to assign.
- thickness
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_type
MidSurfaceOffsetType Surface offset to assign.
- offset_type
Notes
Only surface bodies are eligible for mid-surface offset assignment.
- abstractmethod MasterBody.imprint_curves(faces: list[ansys.geometry.core.designer.face.Face], sketch: ansys.geometry.core.sketch.sketch.Sketch) tuple[list[ansys.geometry.core.designer.edge.Edge], list[ansys.geometry.core.designer.face.Face]]#
Imprint all specified geometries onto specified faces of the body.
- abstractmethod MasterBody.project_curves(direction: ansys.geometry.core.math.vector.UnitVector3D, sketch: ansys.geometry.core.sketch.sketch.Sketch, closest_face: bool, only_one_curve: bool = False) 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_curveparameter allows you to optimize the server call because projecting curves is an expensive operation. This reduces the workload on the server side.
- abstractmethod MasterBody.imprint_projected_curves(direction: ansys.geometry.core.math.vector.UnitVector3D, sketch: ansys.geometry.core.sketch.sketch.Sketch, closest_face: bool, only_one_curve: bool = False) list[ansys.geometry.core.designer.face.Face]#
Project and imprint specified geometries onto the body.
This method combines the
project_curves()andimprint_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_curveparameter 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: 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: ~pint.Quantity | Distance | Real
Distance (magnitude) of the translation.
- MasterBody.set_name(name: str) None#
Set the name of the body.
Warning
This method is only available starting on Ansys release 25R1.
- MasterBody.set_fill_style(fill_style: FillStyle) None#
Set the fill style of the body.
Warning
This method is only available starting on Ansys release 25R1.
- MasterBody.set_suppressed(suppressed: bool) None#
Set the body suppression state.
Warning
This method is only available starting on Ansys release 25R2.
- MasterBody.set_color(color: str | tuple[float, float, float] | tuple[float, float, float, float]) None#
Set the color of the body.
- Parameters:
Warning
This method is only available starting on Ansys release 25R1.
- MasterBody.set_opacity(opacity: float) None#
Set the opacity of the body.
Warning
This method is only available starting on Ansys release 25R2.
- MasterBody.rotate(axis_origin: ansys.geometry.core.math.point.Point3D, axis_direction: ansys.geometry.core.math.vector.UnitVector3D, angle: 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: ~pint.Quantity | Angle | Real
Angle (magnitude) of the rotation.
Warning
This method is only available starting on Ansys release 24R2.
- MasterBody.scale(value: ansys.geometry.core.typing.Real) None#
Scale the geometry body by the given value.
The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.
- Parameters:
- value: Real
Value to scale the body by.
Warning
This method is only available starting on Ansys release 24R2.
- MasterBody.map(frame: ansys.geometry.core.math.frame.Frame) None#
Map the geometry body to the new specified frame.
The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.
- Parameters:
- frame: Frame
Structure defining the orientation of the body.
Warning
This method is only available starting on Ansys release 24R2.
- MasterBody.mirror(plane: ansys.geometry.core.math.plane.Plane) None#
Mirror the geometry body across the specified plane.
The calling object is directly modified when this method is called. Thus, it is important to make copies if needed.
- Parameters:
- plane: Plane
Represents the mirror.
Warning
This method is only available starting on Ansys release 24R2.
- MasterBody.get_collision(body: Body) CollisionType#
Get the collision state between bodies.
- Parameters:
- body: Body
Object that the collision state is checked with.
- Returns:
CollisionTypeEnum that defines the collision state between bodies.
Warning
This method is only available starting on Ansys release 24R2.
- abstractmethod 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:
BodyCopy of the body.
- MasterBody.get_raw_tessellation(tess_options: ansys.geometry.core.misc.options.TessellationOptions | None = None, reset_cache: bool = False, include_faces: bool = True, include_edges: bool = False) dict#
Tessellate the body and return the raw tessellation data.
- Parameters:
- transform
Matrix44, default:IDENTITY_MATRIX44 A transformation matrix to apply to the tessellation.
- tess_options
TessellationOptions|None, default:None A set of options to determine the tessellation quality.
- reset_cachebool, default:
False Whether to reset the tessellation cache and re-request the tessellation from the server.
- include_facesbool, default:
True Whether to include face tessellation data in the output.
- include_edgesbool, default:
False Whether to include edge tessellation data in the output.
- transform
- Returns:
dictDictionary with face and edge IDs as keys and face and edge tessellation data as values.
- MasterBody.tessellate(merge: bool = False, transform: ansys.geometry.core.math.matrix.Matrix44 = IDENTITY_MATRIX44, tess_options: ansys.geometry.core.misc.options.TessellationOptions | None = None, reset_cache: bool = False, include_faces: bool = True, include_edges: bool = False) 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. WhenTrue, the individual faces of the tessellation are merged.- tess_options
TessellationOptions|None, default:None A set of options to determine the tessellation quality.
- reset_cachebool, default:
False Whether to reset the tessellation cache and re-request the tessellation from the server.
- include_facesbool, default:
True Whether to include face tessellation data in the output.
- include_edgesbool, default:
False Whether to include edge tessellation data in the output.
- mergebool, default:
- Returns:
PolyData,MultiBlockMerged
pyvista.PolyDataifmerge=Trueor 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
- MasterBody.shell_body(offset: ansys.geometry.core.misc.measurements.Distance | pint.Quantity | ansys.geometry.core.typing.Real) bool#
Shell the body to the thickness specified.
- Parameters:
- offset
Distance|Quantity|Real Shell thickness.
- offset
- Returns:
- bool
Truewhen successful,Falsewhen failed.
Warning
This method is only available starting on Ansys release 25R2.
- MasterBody.remove_faces(selection: ansys.geometry.core.designer.face.Face | collections.abc.Iterable[ansys.geometry.core.designer.face.Face], offset: ansys.geometry.core.misc.measurements.Distance | pint.Quantity | ansys.geometry.core.typing.Real) bool#
Shell by removing a given set of faces.
- Parameters:
- selection
Face|Iterable[Face] Face or faces to be removed.
- offset
Distance|Quantity|Real Shell thickness.
- selection
- Returns:
- bool
Truewhen successful,Falsewhen failed.
Warning
This method is only available starting on Ansys release 25R2.
- MasterBody.combine_merge(other: Body | list[Body]) None#
Combine this body with another body or bodies, merging them into a single body.
- Parameters:
- other
Union[Body,list[Body]] The body or list of bodies to combine with this body.
- other
Notes
The
selfparameter is directly modified, and theotherbodies are consumed.
- abstractmethod MasterBody.plot(merge: bool = True, screenshot: str | None = None, use_trame: bool | None = None, use_service_colors: bool | None = None, **plotting_options: dict | None) None#
Plot the body.
- Parameters:
- mergebool, default:
True Whether to merge the body into a single mesh. Performance improved when
True. WhenTrue(default), the individual faces of the tessellation are merged. WhenFalse, the number of triangles are preserved and only the topology is merged.- screenshot
str, 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 theansys.tools.visualization_interface.USE_TRAMEglobal setting is used.- use_service_colorsbool, default:
None Whether to use the colors assigned to the body in the service. The default is
None, in which case theansys.geometry.core.USE_SERVICE_COLORSglobal setting is used.- **plotting_options
dict, default:None Keyword arguments for plotting. For allowable keyword arguments, see the
Plotter.add_meshmethod.
- mergebool, default:
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)
- abstractmethod MasterBody.intersect(other: Body | collections.abc.Iterable[Body], keep_other: bool = False) None#
Intersect two (or more) bodies.
- Parameters:
- Raises:
ValueErrorIf the bodies do not intersect.
Notes
The
selfparameter is directly modified with the result, and theotherparameter is consumed. Thus, it is important to make copies if needed. If thekeep_otherparameter is set toTrue, the intersected body is retained.
- abstractmethod MasterBody.subtract(other: Body | collections.abc.Iterable[Body], keep_other: bool = False) None#
Subtract two (or more) bodies.
- Parameters:
- Raises:
ValueErrorIf the subtraction results in an empty (complete) subtraction.
Notes
The
selfparameter is directly modified with the result, and theotherparameter is consumed. Thus, it is important to make copies if needed. If thekeep_otherparameter is set toTrue, the subtracted body is retained.
- abstractmethod MasterBody.unite(other: Body | collections.abc.Iterable[Body], keep_other: bool = False) None#
Unite two (or more) bodies.
- Parameters:
Notes
The
selfparameter is directly modified with the result, and theotherparameter is consumed. Thus, it is important to make copies if needed. If thekeep_otherparameter is set toTrue, the united body is retained.