Python Code

Executes Python code in response to events occurring in Mechanical for a given workflow. When inserted, an editor pane displays automatically and includes features such as auto-completion and syntax highlighting. The events related to Python code execution can be split into two main categories:

  • During the solution process when the input file is created. Python Code objects can query information about the Mechanical data model (objects) and inject Mechanical APDL commands into specific locations of the input file.

  • Following certain processing events that take place before the solution process, such as mesh generation, geometry changes/updates, etc.

Object Properties

The Details pane includes the following properties for this object.

CategoryProperties/Options/Descriptions

Definition

Target Callback: Provides the following options.

  • Get Post Commands

  • After Solve

  • After Post

  • After Object Changed

  • Initialize

Suppressed: Options include Yes and No (default). Suppressing an object removes it from the analysis but maintains scoping and property definitions.

Connected: Read-only property. Values include True and False.

Advanced

Script Execution Scope

Allow Recursion: Options include Yes and No (default). When active, you can include API calls that recurse back to the object’s script.


Caution:  Recursive calls need to be carefully defined in order to avoid any undue issues with the application.


Tree Dependencies

  • Valid Parent Objects: Model, Body, Contact Region, Environment, and Solution.

  • Valid Child Objects: This feature does not support child objects.

Insertion Methods

Right-click the supported parent object and select Insert > Python Code.

Right-click Options

In addition to common right-click options, relevant right-click options for this object include:

  • Connect

  • Reload Properties

  • Suppress

API Reference

See the Python Code section of the ACT API Reference Guide for specific scripting information.

Additional Related Information

See the following sections for additional information: Python Code.