Helpers#
- class ansys.mechanical.core.embedding.helpers.Helpers(app)#
Helper utilities for Mechanical embedding application.
- Parameters:
- app
App The Mechanical embedding application instance.
- app
Examples
>>> from ansys.mechanical.core import App >>> app = App() >>> helpers = app.helpers
Overview#
Import geometry file into the current Mechanical model. |
|
Import materials from a specified material database file. |
|
Export an image of the specified object. |
|
Export an animation of the specified object. |
|
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_path
str 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_key
str,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_type
GeometryImportPreference.AnalysisType,optional The analysis type enum for the geometry import. Default is
GeometryImportPreference.AnalysisType.Type3D.
- file_path
- Returns:
Ansys.ACT.Automation.Mechanical.GeometryImportThe 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_path
str The path to the material database file to be imported.
- file_path
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:
- obj
optional 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_path
str,optional The path where the image will be saved.
- width
int,optional The width of the exported image in pixels. Default is 1920.
- height
int,optional The height of the exported image in pixels. Default is 1080.
- background
GraphicsBackgroundType,optional Background type for the exported image. Default is
GraphicsBackgroundType.White.- resolution
GraphicsResolutionType,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_format
GraphicsImageExportFormat,optional Image format for export. Default is
GraphicsImageExportFormat.PNG.
- obj
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:
- obj
optional 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_path
str,optional The path where the animation will be saved. If None, raises ValueError. If only a filename is provided, saves to current working directory.
- width
int,optional The width of the exported animation in pixels. Default is 1280.
- height
int,optional The height of the exported animation in pixels. Default is 720.
- animation_format
GraphicsAnimationExportFormat,optional Animation format for export. Default is
GraphicsAnimationExportFormat.GIF.
- obj
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:
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))