App#

class ansys.mechanical.core.embedding.app.App(db_file=None, private_appdata=False, **kwargs)#

Mechanical embedding Application.

Overview#

open

Open the db file.

save

Save the project.

save_as

Save the project as.

new

Clear to a new application.

close

Close the active project.

exit

Exit the application.

execute_script

Execute the given script with the internal IronPython engine.

plot

Visualize the model in 3d.

update_globals

Use to update globals variables.

print_tree

Print the hierarchical tree representation of the Mechanical project structure.

poster

Returns an instance of Poster.

DataModel

Return the DataModel.

ExtAPI

Return the ExtAPI object.

Tree

Return the ExtAPI object.

Model

Return the ExtAPI object.

readonly

Return whether the Mechanical object is read-only.

version

Returns the version of the app.

__repr__

Get the product info.

__enter__

Enter the scope.

__exit__

Exit the scope.

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#

Return the DataModel.

property App.ExtAPI#

Return the ExtAPI object.

property App.Tree#

Return the ExtAPI object.

property App.Model#

Return the ExtAPI object.

property App.readonly#

Return whether the Mechanical object is read-only.

property App.version#

Returns the version of the app.

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)#

Open the db file.

App.save(path=None)#

Save the project.

App.save_as(path)#

Save the project as.

App.new()#

Clear to a new application.

App.close()#

Close the active project.

App.exit()#

Exit the application.

App.execute_script(script: str) Any#

Execute the given script 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]

App.update_globals(globals_dict: Dict[str, Any], enums: bool = True) None#

Use to update globals variables.

When scripting inside Mechanical, the Mechanical UI will automatically set global variables in python. PyMechanical can not do that automatically, but this method can be used. app.update_globals(globals())

By default, all enums will be imported too. To avoid including enums, set the enums argument to False.

App.print_tree(node, max_lines=80, lines_count=0, indentation='')#

Print the hierarchical tree representation of the Mechanical project structure.

Each object in the tree is expected to have the following attributes:
  • Name: The name of the object.

  • Suppressed : Print as suppressed, if object is suppressed.

  • Children: Checks if object have children. Each child node is expected to have the all these attributes.

Parameters:
node: ExtAPI object

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

>>> import ansys.mechanical.core as mech
>>> app = mech.App()
>>> app.update_globals(globals())
>>> app.print_tree(DataModel.Project)
... ├── Project
... |  ├── Model
... |  |  ├── Geometry Imports
... |  |  ├── Geometry
... |  |  ├── Materials
... |  |  ├── Coordinate Systems
... |  |  |  ├── Global Coordinate System
... |  |  ├── Remote Points
... |  |  ├── Mesh
>>> app.print_tree(DataModel.Project, 1)
... ├── Project
... ... truncating after 1 lines