Component#

class ansys.geometry.core.designer.component.Component(name: str, parent_component: Component | None, grpc_client: ansys.geometry.core.connection.client.GrpcClient, template: Component | None = None, instance_name: str | None = None, preexisting_id: str | None = None, master_component: ansys.geometry.core.designer.part.MasterComponent | None = 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.

instance_name: str, default: None

User defined optional name for the component instance.

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_all_bodies

Get all bodies in the component hierarchy.

get_world_transform

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

modify_placement

Apply a translation and/or rotation to the 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 a 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.

revolve_sketch

Create a solid body by revolving a sketch profile around an axis.

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_body_from_surface

Create a surface body from a trimmed surface.

create_coordinate_system

Create a coordinate system.

translate_bodies

Translate the bodies in a specified direction by a 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’s scope.

search_component

Search nested components recursively for a component.

search_body

Search bodies in the component’s scope.

search_beam

Search beams in the component’s scope.

tessellate

Tessellate the component.

plot

Plot the component.

tree_print

Print the component in tree format.

instance_name

Name of the component instance.

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.instance_name: str#

Name of the component instance.

property Component.id: str#

ID of the component.

property Component.name: str#

Name of the component.

property Component.components: list[Component]#

List of Component objects inside of the component.

property Component.bodies: list[ansys.geometry.core.designer.body.Body]#

List of Body objects inside of the component.

property Component.beams: list[ansys.geometry.core.designer.beam.Beam]#

List of Beam objects inside of the component.

property Component.design_points: list[ansys.geometry.core.designer.designpoint.DesignPoint]#

List of DesignPoint objects inside of the component.

property Component.coordinate_systems: list[ansys.geometry.core.designer.coordinate_system.CoordinateSystem]#

List of CoordinateSystem objects inside of the component.

property Component.parent_component: Component#

Parent of the component.

property Component.is_alive: bool#

Whether the component is still alive on the server side.

property Component.shared_topology: 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_all_bodies() list[ansys.geometry.core.designer.body.Body]#

Get all bodies in the component hierarchy.

Returns:
list[Body]

List of all bodies in the component hierarchy.

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: ansys.geometry.core.math.vector.Vector3D | None = None, rotation_origin: ansys.geometry.core.math.point.Point3D | None = None, rotation_direction: ansys.geometry.core.math.vector.UnitVector3D | None = None, rotation_angle: pint.Quantity | ansys.geometry.core.misc.measurements.Angle | ansys.geometry.core.typing.Real = 0)#

Apply a translation and/or rotation to the 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_angleQuantity | 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: Component | None = None, instance_name: str = 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: pint.Quantity | ansys.geometry.core.misc.measurements.Distance | ansys.geometry.core.typing.Real, direction: ExtrusionDirection | str = ExtrusionDirection.POSITIVE, cut: bool = False) ansys.geometry.core.designer.body.Body | None#

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

Parameters:
namestr

User-defined label for the new solid body.

sketchSketch

Two-dimensional sketch source for the extrusion.

distanceQuantity | Distance | Real

Distance to extrude the solid body.

directionExtrusionDirection | 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.

cutbool, default: False

Whether to cut the extrusion from the existing component. By default, the extrusion is added to the existing component.

Returns:
Body

Extruded body from the given sketch.

None

If the cut parameter is True, the function returns None.

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: 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: list[ansys.geometry.core.shapes.curves.trimmed_curve.TrimmedCurve], chain: 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.revolve_sketch(name: str, sketch: ansys.geometry.core.sketch.sketch.Sketch, axis: ansys.geometry.core.math.vector.Vector3D, angle: pint.Quantity | ansys.geometry.core.misc.measurements.Angle | ansys.geometry.core.typing.Real, rotation_origin: ansys.geometry.core.math.point.Point3D) ansys.geometry.core.designer.body.Body#

Create a solid body by revolving a sketch profile around an axis.

Parameters:
namestr

User-defined label for the new solid body.

sketchSketch

Two-dimensional sketch source for the revolve.

axisVector3D

Axis of rotation for the revolve.

angleQuantity | Angle | Real

Angle to revolve the solid body around the axis. The angle can be positive or negative.

rotation_originPoint3D

Origin of the axis of rotation.

Returns:
Body

Revolved body from the given sketch.

Component.extrude_face(name: str, face: ansys.geometry.core.designer.face.Face, distance: pint.Quantity | ansys.geometry.core.misc.measurements.Distance, direction: 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.

distanceQuantity | Distance | Real

Distance to extrude the solid body.

directionExtrusionDirection | 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: list[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_body_from_surface(name: str, trimmed_surface: ansys.geometry.core.shapes.surfaces.TrimmedSurface) ansys.geometry.core.designer.body.Body#

Create a surface body from a trimmed surface.

Parameters:
namestr

User-defined label for the new surface body.

trimmed_surfaceTrimmedSurface

Geometry for the new surface body.

Returns:
Body

Surface body.

Notes

It is possible to create a closed solid body (as opposed to an open surface body) with a Sphere or Torus if they are untrimmed. This can be validated with body.is_surface.

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: list[ansys.geometry.core.designer.body.Body], direction: ansys.geometry.core.math.vector.UnitVector3D, distance: pint.Quantity | ansys.geometry.core.misc.measurements.Distance | ansys.geometry.core.typing.Real) None#

Translate the bodies in a specified direction by a distance.

Parameters:
bodies: list[Body]

list of bodies to translate by the same distance.

direction: UnitVector3D

Direction of the translation.

distance: ~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: list[tuple[ansys.geometry.core.math.point.Point3D, ansys.geometry.core.math.point.Point3D]], profile: ansys.geometry.core.designer.beam.BeamProfile) 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: Component | str) None#

Delete a component (itself or its children).

Parameters:
componentComponent | 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: ansys.geometry.core.designer.body.Body | str) None#

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

Parameters:
bodyBody | 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: list[ansys.geometry.core.math.point.Point3D]) 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: ansys.geometry.core.designer.beam.Beam | str) None#

Delete an existing beam belonging to this component’s scope.

Parameters:
beamBeam | str

ID of the beam or instance to delete.

Notes

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

Component.search_component(id: str) 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) ansys.geometry.core.designer.body.Body | None#

Search bodies in the component’s scope.

Parameters:
idstr

ID of the body to search for.

Returns:
Body | None

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

Notes

This method searches for bodies in the component and nested components recursively.

Component.search_beam(id: str) ansys.geometry.core.designer.beam.Beam | None#

Search beams in the component’s scope.

Parameters:
idstr

ID of the beam to search for.

Returns:
Beam | None

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

Notes

This method searches for beams in the component and nested components recursively.

Component.tessellate(_recursive_call: bool = False) pyvista.PolyData | list[pyvista.MultiBlock]#

Tessellate the component.

Parameters:
_recursive_call: bool, default: False

Internal flag to indicate if this method is being called recursively. Not to be used by the user.

Returns:
PolyData, list[MultiBlock]

Tessellated component as a single PolyData object. If the method is called recursively, a list of MultiBlock objects is returned.

Component.plot(merge_component: bool = True, merge_bodies: bool = True, screenshot: str | None = None, use_trame: bool | None = None, use_service_colors: bool | None = None, allow_picking: bool | None = None, **plotting_options: dict | None) None | list[Any]#

Plot the component.

Parameters:
merge_componentbool, default: True

Whether to merge the component into a single dataset. By default, True. Performance improved. When True, all the faces of the component are effectively merged into a single dataset. If False, the individual bodies are kept separate.

merge_bodiesbool, default: True

Whether to merge each body into a single dataset. By default, True. Performance improved. When True, all the faces of each individual body are effectively merged into a single dataset. If False, the individual faces are kept separate.

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 ansys.tools.visualization_interface.USE_TRAME global 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 the ansys.geometry.core.USE_SERVICE_COLORS global setting is used.

allow_pickingbool, default: None

Whether to enable picking. The default is None, in which case the picker is not enabled.

**plotting_optionsdict, default: None

Keyword arguments for plotting. For allowable keyword arguments, see the

Returns:
None | list[Any]

If allow_picking=True, a list of picked objects is returned. Otherwise, None.

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.

Component.tree_print(consider_comps: bool = True, consider_bodies: bool = True, consider_beams: bool = True, depth: int | None = None, indent: int = 4, sort_keys: bool = False, return_list: bool = False, skip_loc_header: bool = False) None | list[str]#

Print the component in tree format.

Parameters:
consider_compsbool, default: True

Whether to print the nested components.

consider_bodiesbool, default: True

Whether to print the bodies.

consider_beamsbool, default: True

Whether to print the beams.

depthint | None, default: None

Depth level to print. If None, it prints all levels.

indentint, default: 4

Indentation level. Minimum is 2 - if less than 2, it is set to 2 by default.

sort_keysbool, default: False

Whether to sort the keys alphabetically.

return_listbool, default: False

Whether to return a list of strings or print out the tree structure.

skip_loc_headerbool, default: False

Whether to skip the location header. Mostly for internal use.

Returns:
None | list[str]

Tree-style printed component or list of strings representing the component tree.