User defined function in ACT console

Options
Ayush Kumar
Ayush Kumar Member, Moderator, Employee Posts: 416
First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
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: 416
    First Anniversary Ansys Employee Solution Developer Community of Practice Member First Answer
    Answer ✓
    Options

    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: 813
    First Comment First Anniversary Ansys Employee Solution Developer Community of Practice Member
    Answer ✓
    Options

    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: 101
    First Anniversary Ansys Employee Solution Developer Community of Practice Member Photogenic
    Answer ✓
    Options

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