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

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.
Best Answer
-
- cmds = '''
- DS.Graphics.GfxUtility.Legend.LegendStyle="{}"
- DS.Graphics.Redraw(true)
- '''.format(guid)
- ExtAPI.Application.ScriptByName("jscript").ExecuteCommand(cmds)
1
Answers
-
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)""")0 -
-
@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
0 -
@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?
0 -
@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
1 -
@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 styleApplyLegendStyle("{guid}")
copies the values without actual assigningMy 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
1 -
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?
0 -
@Landon Mitchell Kanner said:
- cmds = '''
- DS.Graphics.GfxUtility.Legend.LegendStyle="{}"
- '''.format(guid)
- 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.
0