Helpers#

class ansys.mechanical.core.embedding.helpers.Helpers(app)#

Helper utilities for Mechanical embedding application.

Parameters:
appApp

The Mechanical embedding application instance.

Examples

>>> from ansys.mechanical.core import App
>>> app = App()
>>> helpers = app.helpers

Overview#

import_geometry

Import geometry file into the current Mechanical model.

import_materials

Import materials from a specified material database file.

export_image

Export an image of the specified object.

export_animation

Export an animation of the specified object.

display_image

Display an image using matplotlib.

Import detail#

from ansys.mechanical.core.embedding.helpers import Helpers

Attribute detail#

Helpers.Ansys#

Method detail#

Helpers.import_geometry(file_path: str, process_named_selections: bool = False, named_selection_key: str = 'NS', process_material_properties: bool = False, process_coordinate_systems: bool = False, analysis_type=None)#

Import geometry file into the current Mechanical model.

Parameters:
file_pathstr

The path to the geometry file to be imported.

process_named_selectionsbool, optional

Whether to process named selections during import. Default is False.

named_selection_keystr, optional

Named selection key for filtering. Default is “NS”.

process_material_propertiesbool, optional

Whether to process material properties during import. Default is False.

process_coordinate_systemsbool, optional

Whether to process coordinate systems during import. Default is False.

analysis_typeGeometryImportPreference.AnalysisType, optional

The analysis type enum for the geometry import. Default is GeometryImportPreference.AnalysisType.Type3D.

Returns:
Ansys.ACT.Automation.Mechanical.GeometryImport

The geometry import object.

Examples

>>> from ansys.mechanical.core import App
>>> app = App()
>>> app.helpers.import_geometry("C:\\path\\to\\geometry.pmdb")
>>> # Import with 2D analysis type
>>> from ansys.mechanical.core.embedding.enum_importer import GeometryImportPreference
>>> app.helpers.import_geometry(
...     "C:\\path\\to\\geometry.agdb",
...     analysis_type=GeometryImportPreference.AnalysisType.Type2D,
... )
>>> # Import with all options specified
>>> app.helpers.import_geometry(
...     "C:\\path\\to\\geometry.pmdb",
...     process_named_selections=True,
...     named_selection_key="",
...     process_material_properties=True,
...     process_coordinate_systems=True,
... )
Helpers.import_materials(file_path: str)#

Import materials from a specified material database file.

Parameters:
file_pathstr

The path to the material database file to be imported.

Examples

>>> from ansys.mechanical.core import App
>>> app.helpers.import_materials("C:\\path\\to\\materials.xml")
Helpers.export_image(obj=None, file_path: str | None = None, width: int = 1920, height: int = 1080, background=None, resolution=None, current_graphics_display: bool = False, image_format=None)#

Export an image of the specified object.

Parameters:
objoptional

The object to activate and export. If None, exports the current graphics display. Can be any Mechanical object such as Geometry, Mesh, or Results.

file_pathstr, optional

The path where the image will be saved.

widthint, optional

The width of the exported image in pixels. Default is 1920.

heightint, optional

The height of the exported image in pixels. Default is 1080.

backgroundGraphicsBackgroundType, optional

Background type for the exported image. Default is GraphicsBackgroundType.White.

resolutionGraphicsResolutionType, optional

Resolution type for the exported image. Default is GraphicsResolutionType.EnhancedResolution.

current_graphics_displaybool, optional

Whether to use current graphics display. Default is False.

image_formatGraphicsImageExportFormat, optional

Image format for export. Default is GraphicsImageExportFormat.PNG.

Examples

>>> from ansys.mechanical.core import App
>>> app = App()
>>> app.helpers.export_image(app.Model.Geometry, "C:\\path\\to\\geometry.png")
>>> from ansys.mechanical.core.embedding.enum_importer import (
...     GraphicsBackgroundType,
...     GraphicsImageExportFormat,
...     GraphicsResolutionType,
... )
>>> result = app.Model.Analyses[0].Solution.Children[0]
>>> app.helpers.export_image(
...     result,
...     "C:\\path\\to\\result.jpg",
...     background=GraphicsBackgroundType.GraphicsAppearanceSetting,
...     resolution=GraphicsResolutionType.HighResolution,
...     image_format=GraphicsImageExportFormat.JPG,
... )
Helpers.export_animation(obj=None, file_path: str | None = None, width: int = 1280, height: int = 720, animation_format=None)#

Export an animation of the specified object.

Parameters:
objoptional

The object to activate and export animation. If None, exports animation of the current graphics display. Can be any Mechanical object that supports animation such as results with multiple time steps or modal analysis results.

file_pathstr, optional

The path where the animation will be saved. If None, raises ValueError. If only a filename is provided, saves to current working directory.

widthint, optional

The width of the exported animation in pixels. Default is 1280.

heightint, optional

The height of the exported animation in pixels. Default is 720.

animation_formatGraphicsAnimationExportFormat, optional

Animation format for export. Default is GraphicsAnimationExportFormat.GIF.

Examples

>>> from ansys.mechanical.core import App
>>> app = App()
>>> result = app.Model.Analyses[0].Solution.Children[0]
>>> app.helpers.export_animation(result, "result_animation.gif")
>>> from ansys.mechanical.core.embedding.enum_importer import (
...     GraphicsAnimationExportFormat,
... )
>>> app.helpers.export_animation(
...     result,
...     "result_animation.mp4",
...     animation_format=GraphicsAnimationExportFormat.MP4,
... )
Helpers.display_image(image_path: str, figsize: tuple = (16, 9), axis: str = 'off')#

Display an image using matplotlib.

Parameters:
image_pathstr

The path to the image file to display.

figsizetuple, optional

The size of the figure in inches (width, height). Default is (16, 9).

axisstr, optional

The axis visibility setting (‘on’ or ‘off’). Default is “off”.

Examples

>>> from ansys.mechanical.core import App
>>> app = App()
>>> app.helpers.export_image(app.Model.Geometry, "geometry.png")
>>> app.helpers.display_image("geometry.png")
>>> # Display with custom figure size
>>> app.helpers.display_image("result.png", figsize=(10, 6))