The IronPython script defines functions that respond to user and GUI interactions and implements the behavior of the extensions. Typically, functions are invoked through the different events or callbacks in the XML extension definition file.
In the extension ExtSample1, the IronPython script is named
sample1.py. The contents of this script follow:
clr.AddReference("Ans.UI.Toolkit")
clr.AddReference("Ans.UI.Toolkit.Base")
from Ansys.UI.Toolkit import *
def init(context):
ExtAPI.Log.WriteMessage("Init ExtSample1...")
def HighFiveOut(analysis_obj):
MessageBox.Show("High five! ExtSample1 is a success!")The script contains two functions:
init(): Called when the ANSYS product is opened. In the XML
file, the argument context for the
<interface> block contains the name of the product
("Mechanical").
HighFiveOut(): Called when the toolbar button
HighFive is clicked. The callback
<onclick> passes an instance of the active object
Analysis as an argument.
For any function, the global variable ExtAPI represents the main
entry point for all the services provided by ACT. As an example, the function
init() uses the ACT interface ILog to write
one message in the log file. For more information on the available interfaces, see the
ANSYS ACT API Reference Guide.