How to assign a legend style to an object by referencing the guid in Ansys 2025R1

Member Posts: 31
10 Comments Name Dropper First Anniversary
**

@Landon Mitchell Kanner

I have been using the same commands that you have posted here for some releases. However, they stopped working in one of the 2024 releases and are not working in 2025R1:

cmds = '''
DS.Graphics.GfxUtility.Legend.ApplyLegendStyle("{}")
'''.format(guid)
ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmds)

What commands can I use in 2025R1? Python is of course preferred.

Welcome!

It looks like you're new here. Sign in or register to get started.

Best Answer

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭
    edited February 12 Answer ✓
    1. cmds = '''
    2. DS.Graphics.GfxUtility.Legend.LegendStyle="{}"
    3. DS.Graphics.Redraw(true)
    4. '''.format(guid)
    5.  
    6. ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmds)

Answers

  • Member Posts: 31
    10 Comments Name Dropper First Anniversary
    **

    And if somebody is looking at the changes which have been done in JS, could you please also check if retrieving the legend style is still working?

    res_lgd_stl = ExtAPI.Application.ScriptByName("jscript").ExecuteCommand("""res_lgd_stl = DS.Graphics.GfxUtility.Legend.LegendStyle
    returnFromScript(res_lgd_stl)""")

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    It is working on my end at 2025R1 and R2

  • Member Posts: 31
    10 Comments Name Dropper First Anniversary
    **

    @Landon Mitchell Kanner
    Can you please check if the legend style in your models is really applied correctly?

    When running your script from the other thread the values from the legend style are copied to the legend of the object. But there is no thorough linking of the legend to the legend style.

    The name of your legend style is "0_9999". Yet it is not linked to the active object in the tree. The style is still shown as "unnamed".

    Can you confirm this behavior?

    In 2023R2 your script as well as mine are working as intended as I have stated in my first post. See figure below

  • Member Posts: 31
    10 Comments Name Dropper First Anniversary
    **

    @Landon Mitchell Kanner
    This is exactly the code I am using.

    Does it really assign the legend style in your model? If you right click on the legend and go to named legends is there a check mark in front of your legend style?

    Or does it just copy/assign the values without actually linking/assigning the style as shown in the first figure above?

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    @Matthias said:
    And if somebody is looking at the changes which have been done in JS, could you please also check if retrieving the legend style is still working?

    Yes, this is still working in 2025R1

  • Member, Employee, GitHub-issue-creator Posts: 353
    50 Answers 100 Comments Second Anniversary 25 Likes
    ✭✭✭✭

    @Matthias said:
    @Landon Mitchell Kanner
    This is exactly the code I am using.

    Does it really assign the legend style in your model? If you right click on the legend and go to named legends is there a check mark in front of your legend style?

    Or does it just copy/assign the values without actually linking/assigning the style as shown in the first figure above?

    Based on my testing at 25.1:
    LegendStyle="{guid}" assigns the legend style
    ApplyLegendStyle("{guid}") copies the values without actual assigning

    My guess is it should have always been this way but in older versions ApplyLegendStyle had a bug where it would also assign the legend style

  • Member Posts: 31
    10 Comments Name Dropper First Anniversary
    **

    @Landon Mitchell Kanner said:

    Yes, this is still working in 2025R1

    Thanks for checking.

    Regarding the assignment issue: Did I describe the issue that occurs in 2025R1 in my test model clear enough? And can you reproduce it?

  • Member Posts: 31
    10 Comments Name Dropper First Anniversary
    **

    @Landon Mitchell Kanner said:

    1. cmds = '''
    2. DS.Graphics.GfxUtility.Legend.LegendStyle="{}"
    3. '''.format(guid)
    4. ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmds)

    @Landon Mitchell Kanner
    Sorry, my bad. I did overlook the change in the code from
    Legend.ApplyLegendStyle="{}"
    to
    Legend.LegendStyle="{}"

    I have not been using the latter and will try it out.

Welcome!

It looks like you're new here. Sign in or register to get started.