User defined function in ACT console

Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 442
250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
✭✭✭✭
edited June 2023 in Structures

It is possible to write your own helper functions and they will be available in Mechanical ACT console.

Tagged:

Answers

  • Ayush Kumar
    Ayush Kumar Member, Moderator, Employee Posts: 442
    250 Likes Solution Developer Community of Practice Member Ansys Employee First Anniversary
    ✭✭✭✭
    Answer ✓

    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)
    
  • Pernelle Marone-Hitz
    Pernelle Marone-Hitz Member, Moderator, Employee Posts: 859
    500 Comments Photogenic Name Dropper Solution Developer Community of Practice Member
    ✭✭✭✭
    Answer ✓

    Adding a few screenshots to illustrate:

    Module is then loaded in Mechanical:

    And function can be called:

  • Pierre Thieffry
    Pierre Thieffry Member, Moderator, Employee Posts: 107
    5 Likes Name Dropper First Comment First Answer
    ✭✭✭✭
    Answer ✓

    Ayush, don’t snippets help here? When you save a script as a snippet, it will appear as a choice in the console.