App
#
- class ansys.mechanical.core.embedding.app.App(db_file=None, private_appdata=False, **kwargs)#
Mechanical embedding Application.
- Parameters:
- db_file
str
,optional
Path to a mechanical database file (.mechdat or .mechdb).
- version
int
,optional
Version number of the Mechanical application.
- private_appdatabool,
optional
Setting for a temporary AppData directory. Default is False. Enables running parallel instances of Mechanical.
- config
AddinConfiguration
,optional
Configuration for addins. By default “Mechanical” is used and ACT Addins are disabled.
- copy_profilebool,
optional
Whether to copy the user profile when private_appdata is True. Default is True.
- db_file
Examples
Create App with Mechanical project file and version:
>>> from ansys.mechanical.core import App >>> app = App(db_file="path/to/file.mechdat", version=251)
Disable copying the user profile when private appdata is enabled
>>> app = App(private_appdata=True, copy_profile=False)
Create App with “Mechanical” configuration and no ACT Addins
>>> from ansys.mechanical.core.embedding import AddinConfiguration >>> from ansys.mechanical.core import App >>> config = AddinConfiguration("Mechanical") >>> config.no_act_addins = True >>> app = App(config=config)
Overview#
Open the db file. |
|
Save the project. |
|
Save the project as a new file. |
|
Launch the GUI. |
|
Clear to a new application. |
|
Close the active project. |
|
Exit the application. |
|
Execute the given script with the internal IronPython engine. |
|
Execute the given script from file with the internal IronPython engine. |
|
Return |
|
Visualize the model in 3d. |
|
Update global variables. |
|
Print the hierarchical tree representation of the Mechanical project structure. |
Returns an instance of Poster. |
|
Return the DataModel. |
|
Return the ExtAPI object. |
|
Return the Tree object. |
|
Return the Model object. |
|
Return the Graphics object. |
|
Return whether the Mechanical object is read-only. |
|
Returns the version of the app. |
|
Returns the current project directory. |
Import detail#
from ansys.mechanical.core.embedding.app import App
Property detail#
- property App.poster: ansys.mechanical.core.embedding.poster.Poster#
Returns an instance of Poster.
- property App.DataModel: Ansys.Mechanical.DataModel.Interfaces.DataModelObject#
Return the DataModel.
- property App.ExtAPI: Ansys.ACT.Interfaces.Mechanical.IMechanicalExtAPI#
Return the ExtAPI object.
- property App.Tree: Ansys.ACT.Automation.Mechanical.Tree#
Return the Tree object.
- property App.Model: Ansys.ACT.Automation.Mechanical.Model#
Return the Model object.
- property App.Graphics: Ansys.ACT.Common.Graphics.MechanicalGraphicsWrapper#
Return the Graphics object.
- property App.readonly#
Return whether the Mechanical object is read-only.
- property App.version#
Returns the version of the app.
- property App.project_directory#
Returns the current project directory.
Method detail#
- App.__repr__()#
Get the product info.
- App.__enter__()#
Enter the scope.
- App.__exit__(exc_type, exc_val, exc_tb)#
Exit the scope.
- App.open(db_file, remove_lock=False)#
Open the db file.
- App.save(path=None)#
Save the project.
- App.save_as(path: str, overwrite: bool = False)#
Save the project as a new file.
If the overwrite flag is enabled, the current saved file is replaced with the new file.
- Parameters:
- Raises:
Exception
If the file already exists at the specified path and overwrite is False.
Notes
For version 232, if overwrite is True, the existing file and its associated directory (if any) will be removed before saving the new file.
- App.new()#
Clear to a new application.
- App.close()#
Close the active project.
- App.exit()#
Exit the application.
- App.execute_script_from_file(file_path=None)#
Execute the given script from file with the internal IronPython engine.
- App.plot() None #
Visualize the model in 3d.
Requires installation using the viz option. E.g. pip install ansys-mechanical-core[viz]
Examples
>>> from ansys.mechanical.core import App >>> app = App() >>> app.open("path/to/file.mechdat") >>> app.plot()
- App.update_globals(globals_dict: Dict[str, Any], enums: bool = True) None #
Update global variables.
When scripting inside Mechanical, the Mechanical UI automatically sets global variables in Python. PyMechanical cannot do that automatically, but this method can be used.
By default, all enums will be imported too. To avoid including enums, set the enums argument to False.
Examples
>>> from ansys.mechanical.core import App >>> app = App() >>> app.update_globals(globals())
- App.print_tree(node=None, max_lines=80, lines_count=0, indentation='')#
Print the hierarchical tree representation of the Mechanical project structure.
- Parameters:
- node: DataModel object, optional
The starting object of the tree.
- max_lines: int, optional
The maximum number of lines to print. Default is 80. If set to -1, no limit is applied.
- Raises:
AttributeError
If the node does not have the required attributes.
Examples
>>> from ansys.mechanical.core import App >>> app = App() >>> app.update_globals(globals()) >>> app.print_tree() ... ├── Project ... | ├── Model ... | | ├── Geometry Imports (⚡︎) ... | | ├── Geometry (?) ... | | ├── Materials (✓) ... | | ├── Coordinate Systems (✓) ... | | | ├── Global Coordinate System (✓) ... | | ├── Remote Points (✓) ... | | ├── Mesh (?)
>>> app.print_tree(Model, 3) ... ├── Model ... | ├── Geometry Imports (⚡︎) ... | ├── Geometry (?) ... ... truncating after 3 lines
>>> app.print_tree(max_lines=2) ... ├── Project ... | ├── Model ... ... truncating after 2 lines