The auxiliary.py module#

Summary#

get_geometry_ctx

Access the PyAnsys Geometry-MCP context from the MCP context.

walk_components

Yield a component and its live descendants with relative name paths.

find_body_by_name

Find a body by name across the full design tree.

find_bodies_by_id

Find bodies by ID across the full design tree.

find_component

Find a component by name across the full design tree.

find_named_selection

Find a named selection by name in the design.

resolve_bodies

Resolve the bodies a tool should act on from IDs or a selection.

build_sketch

Build a sketch from a list of primitive dictionaries and an optional plane definition.

Description#

Shared helpers used by the MCP tool modules.

Module detail#

auxiliary.get_geometry_ctx(ctx: fastmcp.server.Context) → ansys.geometry.mcp.context.PyAnsysGeometryContext#

Access the PyAnsys Geometry-MCP context from the MCP context.

auxiliary.walk_components(component: ansys.geometry.core.designer.component.Component, prefix: str = '') → collections.abc.Iterator[tuple[ansys.geometry.core.designer.component.Component, str]]#

Yield a component and its live descendants with relative name paths.

auxiliary.find_body_by_name(design: ansys.geometry.core.designer.design.Design, body_name: str) → Body | None#

Find a body by name across the full design tree.

Uses the Component.get_all_bodies() method, which recursively collects every body in the component hierarchy.

Parameters#

designDesign

Active design to search in.

body_namestr

Name of the body to find.

Returns#

Body | None

Body with the specified name, or None if not found.

auxiliary.find_bodies_by_id(design: ansys.geometry.core.designer.design.Design, body_ids: list[str]) → tuple[list[ansys.geometry.core.designer.body.Body], list[str]]#

Find bodies by ID across the full design tree.

Body names need not be unique, so tools address bodies by ID.

Parameters#

designDesign

Active design to search in.

body_idslist of str

IDs of the bodies to find, as reported by list_entities.

Returns#

tuple[list[Body], list[str]]

(bodies, missing): the bodies found, in the order requested, and the IDs that matched no body.

auxiliary.find_component(design: ansys.geometry.core.designer.design.Design, component_name: str) → Component | None#

Find a component by name across the full design tree.

Uses the Design._get_all_components() method, which recursively collects every component in the design hierarchy.

Parameters#

designDesign

Active design to search in.

component_namestr

Name of the component to find.

Returns#

Component | None

Component with the specified name, or None if not found.

auxiliary.find_named_selection(design: ansys.geometry.core.designer.design.Design, name: str) → NamedSelection | None#

Find a named selection by name in the design.

Parameters#

designDesign

Active design to search in.

namestr

Name of the named selection to find.

Returns#

NamedSelection | None

Named selection with the specified name, or None if not found.

auxiliary.resolve_bodies(app_context: ansys.geometry.mcp.context.PyAnsysGeometryContext, design: ansys.geometry.core.designer.design.Design, body_ids: list[str] | None = None, named_selection: str | None = None, selection_handle: str | None = None) → tuple[list[ansys.geometry.core.designer.body.Body], str | None]#

Resolve the bodies a tool should act on from IDs or a selection.

Precedence is selection_handle, then named_selection, then body_ids, and then every body in the design.

On success, a bodies = ... line is appended to the command history. It replays the lookup the caller asked for (the selection, the named selection, the supplied IDs, or every body) rather than the IDs it resolved to, so the script stays valid when the design is rebuilt and IDs change.

Parameters#

app_contextPyAnsysGeometryContext

Application state, which is used to look up selection_handle and to record the command history.

designDesign

Active design to resolve against.

body_idslist of str, default: None

Body IDs, as reported by list_entities.

named_selectionstr, default: None

Label of a named selection whose bodies should be used.

selection_handlestr, default: None

Handle of a selection builder from the create_selection_builder method.

Returns#

tuple[list[Body], str | None]

(bodies, error). error is None on success; otherwise the body list is empty and the string is meant to be returned to the caller.

auxiliary.build_sketch(sketch_primitives: list[dict], plane_origin: list[float] | None = None, plane_dir_x: list[float] | None = None, plane_dir_y: list[float] | None = None) → tuple[ansys.geometry.core.sketch.Sketch, list[str]]#

Build a sketch from a list of primitive dictionaries and an optional plane definition.

Parameters#

sketch_primitiveslist of dict

Each dictionary must have a "type" key. See extrude_sketch for supported types.

plane_originlist of float, default: None

[x, y, z] origin of the sketch plane.

plane_dir_xlist of float, default: None

[x, y, z] X direction of the sketch plane.

plane_dir_ylist of float, default: None

[x, y, z] Y direction of the sketch plane.

Returns#

tuple[Sketch, list[str]]

Populated sketch object and the list of accumulated commands.