Component#

class ansys.geometry.core.designer.component.Component(name: str, parent_component: beartype.typing.Union[Component, None], grpc_client: ansys.geometry.core.connection.client.GrpcClient, template: beartype.typing.Optional[Component] = None, preexisting_id: beartype.typing.Optional[str] = None, master_component: beartype.typing.Optional[ansys.geometry.core.designer.part.MasterComponent] = None, read_existing_comp: bool = False)#

Provides for creating and managing a component.

This class synchronizes to a design within a supporting Geometry service instance.

Parameters:
namestr

User-defined label for the new component.

parent_componentComponent or None

Parent component to place the new component under within the design assembly. The default is None only when dealing with a Design object.

grpc_clientGrpcClient

Active supporting Geometry service instance for design modeling.

templateComponent, default: None

Template to create this component from. This creates an instance component that shares a master with the template component.

preexisting_idstr, default: None

ID of a component pre-existing on the server side to use to create the component on the client-side data model. If an ID is specified, a new component is not created on the server.

master_componentMasterComponent, default: None

Master component to use to create a nested component instance instead of creating a new conponent.

read_existing_compbool, default: False

Whether an existing component on the service should be read. This parameter is only valid when connecting to an existing service session. Otherwise, avoid using this optional parameter.

Overview#

get_world_transform

Get the full transformation matrix of the component in world space.

modify_placement

Apply a translation and/or rotation to the existing placement matrix.

reset_placement

Reset a component’s placement matrix to an identity matrix.

add_component

Add a new component under this component within the design assembly.

set_shared_topology

Set the shared topology to apply to the component.

extrude_sketch

Create a solid body by extruding the sketch profile up by a given distance.

sweep_sketch

Create a body by sweeping a planar profile along a path.

sweep_chain

Create a body by sweeping a chain of curves along a path.

extrude_face

Extrude the face profile by a given distance to create a solid body.

create_sphere

Create a sphere body defined by the center point and the radius.

create_body_from_loft_profile

Create a lofted body from a collection of trimmed curves.

create_surface

Create a surface body with a sketch profile.

create_surface_from_face

Create a surface body based on a face.

create_coordinate_system

Create a coordinate system.

translate_bodies

Translate the geometry bodies in a specified direction by a given distance.

create_beams

Create beams under the component.

create_beam

Create a beam under the component.

delete_component

Delete a component (itself or its children).

delete_body

Delete a body belonging to this component (or its children).

add_design_point

Create a single design point.

add_design_points

Create a list of design points.

delete_beam

Delete an existing beam belonging to this component (or its children).

search_component

Search nested components recursively for a component.

search_body

Search bodies in the component and nested components recursively for a body.

search_beam

Search beams in the component and nested components recursively for a beam.

tessellate

Tessellate the component.

plot

Plot the component.

id

ID of the component.

name

Name of the component.

components

List of Component objects inside of the component.

bodies

List of Body objects inside of the component.

beams

List of Beam objects inside of the component.

design_points

List of DesignPoint objects inside of the component.

coordinate_systems

List of CoordinateSystem objects inside of the component.

parent_component

Parent of the component.

is_alive

Whether the component is still alive on the server side.

shared_topology

Shared topology type of the component (if any).

__repr__

Represent the Component as a string.

Import detail#

from ansys.geometry.core.designer.component import Component

Property detail#

property Component.id: str#

ID of the component.

property Component.name: str#

Name of the component.

property Component.components: beartype.typing.List[Component]#

List of Component objects inside of the component.

property Component.bodies: beartype.typing.List[ansys.geometry.core.designer.body.Body]#

List of Body objects inside of the component.

property Component.beams: beartype.typing.List[ansys.geometry.core.designer.beam.Beam]#

List of Beam objects inside of the component.

property Component.design_points: beartype.typing.List[ansys.geometry.core.designer.designpoint.DesignPoint]#

List of DesignPoint objects inside of the component.

property Component.coordinate_systems: beartype.typing.List[ansys.geometry.core.designer.coordinate_system.CoordinateSystem]#

List of CoordinateSystem objects inside of the component.

property Component.parent_component: beartype.typing.Union[Component, None]#

Parent of the component.

property Component.is_alive: bool#

Whether the component is still alive on the server side.

property Component.shared_topology: beartype.typing.Union[SharedTopologyType, None]#

Shared topology type of the component (if any).

Notes

If no shared topology has been set, None is returned.

Method detail#

Component.get_world_transform() ansys.geometry.core.math.matrix.Matrix44#

Get the full transformation matrix of the component in world space.

Returns:
Matrix44

4x4 transformation matrix of the component in world space.

Component.modify_placement(translation: beartype.typing.Optional[ansys.geometry.core.math.vector.Vector3D] = None, rotation_origin: beartype.typing.Optional[ansys.geometry.core.math.point.Point3D] = None, rotation_direction: beartype.typing.Optional[ansys.geometry.core.math.vector.UnitVector3D] = None, rotation_angle: beartype.typing.Union[pint.Quantity, ansys.geometry.core.misc.measurements.Angle, ansys.geometry.core.typing.Real] = 0)#

Apply a translation and/or rotation to the existing placement matrix.

Parameters:
translationVector3D, default: None

Vector that defines the desired translation to the component.

rotation_originPoint3D, default: None

Origin that defines the axis to rotate the component about.

rotation_directionUnitVector3D, default: None

Direction of the axis to rotate the component about.

rotation_angleUnion[Quantity, Angle, Real], default: 0

Angle to rotate the component around the axis.

Notes

To reset a component’s placement to an identity matrix, see reset_placement() or call modify_placement() with no arguments.

Component.reset_placement()#

Reset a component’s placement matrix to an identity matrix.

See modify_placement().

Component.add_component(name: str, template: beartype.typing.Optional[Component] = None) Component#

Add a new component under this component within the design assembly.

Parameters:
namestr

User-defined label for the new component.

templateComponent, default: None

Template to create this component from. This creates an instance component that shares a master with the template component.

Returns:
Component

New component with no children in the design assembly.

Component.set_shared_topology(share_type: SharedTopologyType) None#

Set the shared topology to apply to the component.

Parameters:
share_typeSharedTopologyType

Shared topology type to assign to the component.

Component.extrude_sketch(name: str, sketch: ansys.geometry.core.sketch.sketch.Sketch, distance: beartype.typing.Union[pint.Quantity, ansys.geometry.core.misc.measurements.Distance, ansys.geometry.core.typing.Real], direction: beartype.typing.Union[ExtrusionDirection, str] = ExtrusionDirection.POSITIVE) ansys.geometry.core.designer.body.Body#

Create a solid body by extruding the sketch profile up by a given distance.

Parameters:
namestr

User-defined label for the new solid body.

sketchSketch

Two-dimensional sketch source for the extrusion.

distanceUnion[Quantity, Distance, Real]

Distance to extrude the solid body.

directionUnion[ExtrusionDirection, str], default: “+”

Direction for extruding the solid body. The default is to extrude in the positive normal direction of the sketch. Options are “+” and “-” as a string, or the enum values.

Returns:
Body

Extruded body from the given sketch.

Notes

The newly created body is placed under this component within the design assembly.

Component.sweep_sketch(name: str, sketch: ansys.geometry.core.sketch.sketch.Sketch, path: beartype.typing.List[ansys.geometry.core.shapes.curves.trimmed_curve.TrimmedCurve]) ansys.geometry.core.designer.body.Body#

Create a body by sweeping a planar profile along a path.

Parameters:
namestr

User-defined label for the new solid body.

sketchSketch

Two-dimensional sketch source for the extrusion.

pathList[TrimmedCurve]

The path to sweep the profile along.

Returns:
Body

Created body from the given sketch.

Notes

The newly created body is placed under this component within the design assembly.

Component.sweep_chain(name: str, path: beartype.typing.List[ansys.geometry.core.shapes.curves.trimmed_curve.TrimmedCurve], chain: beartype.typing.List[ansys.geometry.core.shapes.curves.trimmed_curve.TrimmedCurve]) ansys.geometry.core.designer.body.Body#

Create a body by sweeping a chain of curves along a path.

Parameters:
namestr

User-defined label for the new solid body.

pathList[TrimmedCurve]

The path to sweep the chain along.

chainList[TrimmedCurve]

A chain of trimmed curves.

Returns:
Body

Created body from the given sketch.

Notes

The newly created body is placed under this component within the design assembly.

Component.extrude_face(name: str, face: ansys.geometry.core.designer.face.Face, distance: beartype.typing.Union[pint.Quantity, ansys.geometry.core.misc.measurements.Distance], direction: beartype.typing.Union[ExtrusionDirection, str] = ExtrusionDirection.POSITIVE) ansys.geometry.core.designer.body.Body#

Extrude the face profile by a given distance to create a solid body.

There are no modifications against the body containing the source face.

Parameters:
namestr

User-defined label for the new solid body.

faceFace

Target face to use as the source for the new surface.

distanceUnion[Quantity, Distance, Real]

Distance to extrude the solid body.

directionUnion[ExtrusionDirection, str], default: “+”

Direction for extruding the solid body’s face. The default is to extrude in the positive normal direction of the face. Options are “+” and “-” as a string, or the enum values.

Returns:
Body

Extruded solid body.

Notes

The source face can be anywhere within the design component hierarchy. Therefore, there is no validation requiring that the face is placed under the target component where the body is to be created.

Component.create_sphere(name: str, center: ansys.geometry.core.math.point.Point3D, radius: ansys.geometry.core.misc.measurements.Distance) ansys.geometry.core.designer.body.Body#

Create a sphere body defined by the center point and the radius.

Parameters:
namestr

Body name.

centerPoint3D

Center point of the sphere.

radiusDistance

Radius of the sphere.

Returns:
Body

Sphere body object.

Component.create_body_from_loft_profile(name: str, profiles: beartype.typing.List[beartype.typing.List[ansys.geometry.core.shapes.curves.trimmed_curve.TrimmedCurve]], periodic: bool = False, ruled: bool = False) ansys.geometry.core.designer.body.Body#

Create a lofted body from a collection of trimmed curves.

Parameters:
namestr

Name of the lofted body.

profilesList[List[TrimmedCurve]]

Collection of lists of trimmed curves (profiles) defining the lofted body’s shape.

periodicbool, default: False

Whether the lofted body should have periodic continuity.

ruledbool

Whether the lofted body should be ruled.

Returns:
Body

Created lofted body object.

Notes

Surfaces produced have a U parameter in the direction of the profile curves, and a V parameter in the direction of lofting. Profiles can have different numbers of segments. A minimum twist solution is produced. Profiles should be all closed or all open. Closed profiles cannot contain inner loops. If closed profiles are supplied, a closed (solid) body is produced, if possible. Otherwise, an open (sheet) body is produced. The periodic argument applies when the profiles are closed. It is ignored if the profiles are open.

If periodic=True, at least three profiles must be supplied. The loft continues from the last profile back to the first profile to produce surfaces that are periodic in V.

If periodic=False, at least two profiles must be supplied. If the first and last profiles are planar, end capping faces are created. Otherwise, an open (sheet) body is produced. If ruled=True, separate ruled surfaces are produced between each pair of profiles. If periodic=True, the loft continues from the last profile back to the first profile, but the surfaces are not periodic.

Component.create_surface(name: str, sketch: ansys.geometry.core.sketch.sketch.Sketch) ansys.geometry.core.designer.body.Body#

Create a surface body with a sketch profile.

The newly created body is placed under this component within the design assembly.

Parameters:
namestr

User-defined label for the new surface body.

sketchSketch

Two-dimensional sketch source for the surface definition.

Returns:
Body

Body (as a planar surface) from the given sketch.

Component.create_surface_from_face(name: str, face: ansys.geometry.core.designer.face.Face) ansys.geometry.core.designer.body.Body#

Create a surface body based on a face.

Parameters:
namestr

User-defined label for the new surface body.

faceFace

Target face to use as the source for the new surface.

Returns:
Body

Surface body.

Notes

The source face can be anywhere within the design component hierarchy. Therefore, there is no validation requiring that the face is placed under the target component where the body is to be created.

Component.create_coordinate_system(name: str, frame: ansys.geometry.core.math.frame.Frame) ansys.geometry.core.designer.coordinate_system.CoordinateSystem#

Create a coordinate system.

The newly created coordinate system is place under this component within the design assembly.

Parameters:
namestr

User-defined label for the new coordinate system.

frameFrame

Frame defining the coordinate system bounds.

Returns:
CoordinateSystem
Component.translate_bodies(bodies: beartype.typing.List[ansys.geometry.core.designer.body.Body], 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 geometry bodies in a specified direction by a given distance.

Parameters:
bodies: List[Body]

List of bodies to translate by the same distance.

direction: UnitVector3D

Direction of the translation.

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

Magnitude of the translation.

Returns:
None

Notes

If the body does not belong to this component (or its children), it is not translated.

Component.create_beams(segments: beartype.typing.List[beartype.typing.Tuple[ansys.geometry.core.math.point.Point3D, ansys.geometry.core.math.point.Point3D]], profile: ansys.geometry.core.designer.beam.BeamProfile) beartype.typing.List[ansys.geometry.core.designer.beam.Beam]#

Create beams under the component.

Parameters:
segmentsList[Tuple[Point3D, Point3D]]

List of start and end pairs, each specifying a single line segment.

profileBeamProfile

Beam profile to use to create the beams.

Notes

The newly created beams synchronize to a design within a supporting Geometry service instance.

Component.create_beam(start: ansys.geometry.core.math.point.Point3D, end: ansys.geometry.core.math.point.Point3D, profile: ansys.geometry.core.designer.beam.BeamProfile) ansys.geometry.core.designer.beam.Beam#

Create a beam under the component.

The newly created beam synchronizes to a design within a supporting Geometry service instance.

Parameters:
startPoint3D

Starting point of the beam line segment.

endPoint3D

Ending point of the beam line segment.

profileBeamProfile

Beam profile to use to create the beam.

Component.delete_component(component: beartype.typing.Union[Component, str]) None#

Delete a component (itself or its children).

Parameters:
componentUnion[Component, str]

ID of the component or instance to delete.

Notes

If the component is not this component (or its children), it is not deleted.

Component.delete_body(body: beartype.typing.Union[ansys.geometry.core.designer.body.Body, str]) None#

Delete a body belonging to this component (or its children).

Parameters:
bodyUnion[Body, str]

ID of the body or instance to delete.

Notes

If the body does not belong to this component (or its children), it is not deleted.

Component.add_design_point(name: str, point: ansys.geometry.core.math.point.Point3D) ansys.geometry.core.designer.designpoint.DesignPoint#

Create a single design point.

Parameters:
namestr

User-defined label for the design points.

pointsPoint3D

3D point constituting the design point.

Component.add_design_points(name: str, points: beartype.typing.List[ansys.geometry.core.math.point.Point3D]) beartype.typing.List[ansys.geometry.core.designer.designpoint.DesignPoint]#

Create a list of design points.

Parameters:
namestr

User-defined label for the list of design points.

pointsList[Point3D]

List of the 3D points that constitute the list of design points.

Component.delete_beam(beam: beartype.typing.Union[ansys.geometry.core.designer.beam.Beam, str]) None#

Delete an existing beam belonging to this component (or its children).

Parameters:
beamUnion[Beam, str]

ID of the beam or instance to delete.

Notes

If the beam does not belong to this component (or its children), it is not deleted.

Component.search_component(id: str) beartype.typing.Union[Component, None]#

Search nested components recursively for a component.

Parameters:
idstr

ID of the component to search for.

Returns:
Component

Component with the requested ID. If this ID is not found, None is returned.

Component.search_body(id: str) beartype.typing.Union[ansys.geometry.core.designer.body.Body, None]#

Search bodies in the component and nested components recursively for a body.

Parameters:
idstr

ID of the body to search for.

Returns:
Body

Body with the requested ID. If the ID is not found, None is returned.

Component.search_beam(id: str) beartype.typing.Union[ansys.geometry.core.designer.beam.Beam, None]#

Search beams in the component and nested components recursively for a beam.

Parameters:
idstr

ID of the beam to search for.

Returns:
Union[Beam, None]

Beam with the requested ID. If the ID is not found, None is returned.

Component.tessellate(merge_component: bool = False, merge_bodies: bool = False) beartype.typing.Union[pyvista.PolyData, pyvista.MultiBlock]#

Tessellate the component.

Parameters:
merge_componentbool, default: False

Whether to merge this component into a single dataset. When True, all the individual bodies are effectively combined into a single dataset without any hierarchy.

merge_bodiesbool, default: False

Whether to merge each body into a single dataset. When True, all the faces of each individual body are effectively merged into a single dataset without separating faces.

Returns:
PolyData, MultiBlock

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

Examples

Create two stacked bodies and return the tessellation as two merged bodies:

>>> from ansys.geometry.core.sketch import Sketch
>>> from ansys.geometry.core import Modeler
>>> from ansys.geometry.core.math import Point2D, Point3D, Plane
>>> from ansys.geometry.core.misc import UNITS
>>> from ansys.geometry.core.plotting import Plotter
>>> modeler = Modeler("10.54.0.72", "50051")
>>> sketch_1 = Sketch()
>>> box = sketch_1.box(
>>>    Point2D([10, 10], UNITS.m), Quantity(10, UNITS.m), Quantity(5, UNITS.m))
>>> sketch_1.circle(Point2D([0, 0], UNITS.m), Quantity(25, UNITS.m))
>>> design = modeler.create_design("MyDesign")
>>> comp = design.add_component("MyComponent")
>>> distance = Quantity(10, UNITS.m)
>>> body = comp.extrude_sketch("Body", sketch=sketch_1, distance=distance)
>>> sketch_2 = Sketch(Plane([0, 0, 10]))
>>> box = sketch_2.box(
>>>    Point2D([10, 10], UNITS.m), Quantity(10, UNITS.m), Quantity(5, UNITS.m))
>>> circle = sketch_2.circle(Point2D([0, 0], UNITS.m), Quantity(25, UNITS.m))
>>> body = comp.extrude_sketch("Body", sketch=sketch_2, distance=distance)
>>> dataset = comp.tessellate(merge_bodies=True)
>>> dataset
MultiBlock (0x7ff6bcb511e0)
  N Blocks:     2
  X Bounds:     -25.000, 25.000
  Y Bounds:     -24.991, 24.991
  Z Bounds:     0.000, 20.000
Component.plot(merge_component: bool = False, merge_bodies: bool = False, screenshot: beartype.typing.Optional[str] = None, use_trame: beartype.typing.Optional[bool] = None, **plotting_options: beartype.typing.Optional[dict]) None#

Plot the component.

Parameters:
merge_componentbool, default: False

Whether to merge the component into a single dataset. When True, all the individual bodies are effectively merged into a single dataset without any hierarchy.

merge_bodiesbool, default: False

Whether to merge each body into a single dataset. When True, all the faces of each individual body are effectively merged into a single dataset without separating faces.

screenshotstr, default: None

Path for saving a screenshot of the image 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

Examples

Create 25 small cylinders in a grid-like pattern on the XY plane and plot them. Make the cylinders look metallic by enabling physically-based rendering with pbr=True.

>>> 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
>>> import numpy as np
>>> modeler = Modeler()
>>> origin = Point3D([0, 0, 0])
>>> plane = Plane(origin, direction_x=[1, 0, 0], direction_y=[0, 1, 0])
>>> design = modeler.create_design("my-design")
>>> mycomp = design.add_component("my-comp")
>>> n = 5
>>> xx, yy = np.meshgrid(
...     np.linspace(-4, 4, n),
...     np.linspace(-4, 4, n),
... )
>>> for x, y in zip(xx.ravel(), yy.ravel()):
...     sketch = Sketch(plane)
...     sketch.circle(Point2D([x, y]), 0.2*u.m)
...     mycomp.extrude_sketch(f"body-{x}-{y}", sketch, 1 * u.m)
>>> mycomp
ansys.geometry.core.designer.Component 0x2203cc9ec50
    Name                 : my-comp
    Exists               : True
    Parent component     : my-design
    N Bodies             : 25
    N Components         : 0
    N Coordinate Systems : 0
>>> mycomp.plot(pbr=True, metallic=1.0)
Component.__repr__() str#

Represent the Component as a string.