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:
- name
str
User-defined label for the new component.
- parent_component
Component
orNone
Parent component to place the new component under within the design assembly. The default is
None
only when dealing with aDesign
object.- grpc_client
GrpcClient
Active supporting Geometry service instance for design modeling.
- template
Component
, 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_id
str
, 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_component
MasterComponent
, 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.
- name
Overview#
Get all bodies in the component hierarchy. |
|
Get the full transformation matrix of the component in world space. |
|
Apply a translation and/or rotation to the placement matrix. |
|
Reset a component’s placement matrix to an identity matrix. |
|
Add a new component under this component within the design assembly. |
|
Set the shared topology to apply to the component. |
|
Create a solid body by extruding the sketch profile a distance. |
|
Create a body by sweeping a planar profile along a path. |
|
Create a body by sweeping a chain of curves along a path. |
|
Create a solid body by revolving a sketch profile around an axis. |
|
Extrude the face profile by a given distance to create a solid body. |
|
Create a sphere body defined by the center point and the radius. |
|
Create a lofted body from a collection of trimmed curves. |
|
Create a surface body with a sketch profile. |
|
Create a surface body based on a face. |
|
Create a surface body from a trimmed surface. |
|
Create a coordinate system. |
|
Translate the bodies in a specified direction by a distance. |
|
Create beams under the component. |
|
Create a beam under the component. |
|
Delete a component (itself or its children). |
|
Delete a body belonging to this component (or its children). |
|
Create a single design point. |
|
Create a list of design points. |
|
Delete an existing beam belonging to this component’s scope. |
|
Search nested components recursively for a component. |
|
Search bodies in the component’s scope. |
|
Search beams in the component’s scope. |
|
Tessellate the component. |
|
Plot the component. |
|
Print the component in tree format. |
Name of the component instance. |
|
ID of the component. |
|
Name of the component. |
|
List of |
|
List of |
|
List of |
|
List of |
|
List of |
|
Parent of the component. |
|
Whether the component is still alive on the server side. |
|
Shared topology type of the component (if any). |
Represent the |
Import detail#
from ansys.geometry.core.designer.component import Component
Property detail#
- 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.
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:
- translation
Vector3D
, default:None
Vector that defines the desired translation to the component.
- rotation_origin
Point3D
, default:None
Origin that defines the axis to rotate the component about.
- rotation_direction
UnitVector3D
, default:None
Direction of the axis to rotate the component about.
- rotation_angle
Quantity
|Angle
|Real
, default: 0 Angle to rotate the component around the axis.
- translation
Notes
To reset a component’s placement to an identity matrix, see
reset_placement()
or callmodify_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.
Set the shared topology to apply to the component.
- Parameters:
- share_type
SharedTopologyType
Shared topology type to assign to the component.
- share_type
- 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:
- name
str
User-defined label for the new solid body.
- sketch
Sketch
Two-dimensional sketch source for the extrusion.
- distance
Quantity
|Distance
|Real
Distance to extrude the solid body.
- direction
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.
- cutbool, default:
False
Whether to cut the extrusion from the existing component. By default, the extrusion is added to the existing component.
- name
- Returns:
Body
Extruded body from the given sketch.
None
If the cut parameter is
True
, the function returnsNone
.
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:
- 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:
- 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:
- name
str
User-defined label for the new solid body.
- sketch
Sketch
Two-dimensional sketch source for the revolve.
- axis
Vector3D
Axis of rotation for the revolve.
- angle
Quantity
|Angle
|Real
Angle to revolve the solid body around the axis. The angle can be positive or negative.
- rotation_origin
Point3D
Origin of the axis of rotation.
- name
- 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:
- name
str
User-defined label for the new solid body.
- face
Face
Target face to use as the source for the new surface.
- distance
Quantity
|Distance
|Real
Distance to extrude the solid body.
- direction
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.
- name
- 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:
- name
str
Body name.
- center
Point3D
Center point of the sphere.
- radius
Distance
Radius of the sphere.
- name
- 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:
- 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. Ifruled=True
, separate ruled surfaces are produced between each pair of profiles. Ifperiodic=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:
- name
str
User-defined label for the new surface body.
- sketch
Sketch
Two-dimensional sketch source for the surface definition.
- name
- 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:
- name
str
User-defined label for the new surface body.
- face
Face
Target face to use as the source for the new surface.
- name
- 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:
- name
str
User-defined label for the new surface body.
- trimmed_surface
TrimmedSurface
Geometry for the new surface body.
- name
- 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:
- name
str
User-defined label for the new coordinate system.
- frame
Frame
Frame defining the coordinate system bounds.
- name
- 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:
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:
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:
- start
Point3D
Starting point of the beam line segment.
- end
Point3D
Ending point of the beam line segment.
- profile
BeamProfile
Beam profile to use to create the beam.
- start
- Component.delete_component(component: Component | str) None #
Delete a component (itself or its children).
- Parameters:
- component
Component
|str
ID of the component or instance to delete.
- component
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:
- body
Body
|str
ID of the body or instance to delete.
- body
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:
- name
str
User-defined label for the design points.
- points
Point3D
3D point constituting the design point.
- name
- 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.
- Component.delete_beam(beam: ansys.geometry.core.designer.beam.Beam | str) None #
Delete an existing beam belonging to this component’s scope.
- Parameters:
- beam
Beam
|str
ID of the beam or instance to delete.
- beam
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:
- id
str
ID of the component to search for.
- id
- 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:
- id
str
ID of the body to search for.
- id
- 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:
- id
str
ID of the beam to search for.
- id
- 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. WhenTrue
, all the faces of the component are effectively merged into a single dataset. IfFalse
, the individual bodies are kept separate.- merge_bodiesbool, default:
True
Whether to merge each body into a single dataset. By default,
True
. Performance improved. WhenTrue
, all the faces of each individual body are effectively merged into a single dataset. IfFalse
, the individual faces are kept separate.- screenshot
str
, 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 theansys.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 theansys.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_options
dict
, default:None
Keyword arguments for plotting. For allowable keyword arguments, see the
- merge_componentbool, default:
- Returns:
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.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.
- depth
int
|None
, default:None
Depth level to print. If None, it prints all levels.
- indent
int
, 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.
- consider_compsbool, default:
- Returns: