Responding to a Change to the Active Unit System

When a user makes a change to the active units system in Mechanical, values in the extension might need to be converted accordingly. You can register a callback function that is invoked when such a change is made. The XML node <onunitschanged>f_callback</onunitschanged> provides the mechanism to register a callback function for the event onunitschanged. The value f_callback specifies the name of the callback function. A function with this name must be defined in the IronPython script for the extension.

In the following XML extension definition file, the callback onunitschanged specifies the function unitschanged.

<extension version="1" name="UnitsChanged">
  <author>ANSYS, Inc.</author>
  <guid shortid="UnitsChanged">D4C1ED2D-5104-4507-B078-5AD95B712DF1</guid>
  <script src="rununitschanged.py" />
  <interface context="Mechanical">
    <images>images</images>
    <callbacks>
      <oninit>init</oninit>
      <onunitschanged>unitschanged</onunitschanged>
    </callbacks>
…
  </interface>
</extension>

The IronPython script rununitschanged.py defines the callback function unitschanged.

clr.AddReference("Ans.UI.Toolkit.Base")
clr.AddReference("Ans.UI.Toolkit")
from Ansys.UI.Toolkit import *
import System

def init(context):
    ExtAPI.Log.WriteMessage("Init ACT unitschanged example...")
def unitschanged():
     ExtAPI.Log.WriteMessage("***** Units Changed *****")

Release 18.2 - © ANSYS, Inc. All rights reserved.