User defined function in ACT console
Ayush Kumar
Member, Moderator, Employee Posts: 470
✭✭✭✭
It is possible to write your own helper functions and they will be available in Mechanical ACT console.
Tagged:
0
Answers
-
Note: Just an internal trick, not supported.
$AWP_ROOT202/Addins/ACT/libraries/Mechanical contains Python Modules which are loaded by default in Mechanical session. If you create a Python file for example
helper.py
in this folder, all functions within this file can be directly used in ACT Mechanical Console.Eg. Content of
helper.py
:def get_attributes(attribute_string, object): return filter(lambda x: (attribute_string.upper() in x.upper()), dir(object))
Usage in Mechanical ACT console:
import helper helper.get_attributes("Unit", analysis)
2 -
Adding a few screenshots to illustrate:
Module is then loaded in Mechanical:
And function can be called:
0 -
Ayush, don’t snippets help here? When you save a script as a snippet, it will appear as a choice in the console.
2