How can I add parametric information in the legend of a Python result in Ansys Mechanical?

Tasos
Tasos Member, Employee Posts: 13
Name Dropper 5 Likes First Comment Photogenic
✭✭✭

I want to add parametric information in my Python result legend as text.

Best Answer

  • Tasos
    Tasos Member, Employee Posts: 13
    Name Dropper 5 Likes First Comment Photogenic
    ✭✭✭
    Answer ✓

    The ability to edit legend information via the Mechanical Scripting API is currently limited. One workaround to add parametric information to the legend is to take advantage of the fact that the Result object name is displayed in the legend.

    my_parameter = 1234
    this.Name = "My Parametric Result " + str(my_parameter)
    

    Adding a snippet like the one above in your Python result script will change the specific result’s object name and this will be reflected in the legend area, as seen in the screenshot below. This is a clever way to add text to your legend bypassing current API limitations.
    Note that the newline character (\n) is respected, and you can use this to arrange multiline text.