When the active units system is changed 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. In the following XML file for the theoretical
extension UnitsChanged
, the callback
<onunitschanged>
invokes the IronPython 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 code follows for the 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 *****")