Do we have a simple scripting way to change all/some legend values of my stress plot in Mechanical?

Rohith Patchigolla
Rohith Patchigolla Member, Moderator, Employee Posts: 193
100 Comments 25 Answers Second Anniversary 25 Likes
✭✭✭✭

Do we have a simple scripting way to change all/some legend values of my stress plot in Mechanical?

Best Answer

  • Rohith Patchigolla
    Rohith Patchigolla Member, Moderator, Employee Posts: 193
    100 Comments 25 Answers Second Anniversary 25 Likes
    ✭✭✭✭
    Answer ✓
    • Activate a Stress Result object first
    • Open Scripting Console in Mechanical and paste the below script, which changes the third from the bottom and 2nd from the top legend values.
    • Click on "Run Script" button (please note its NOT the Green play button)
    #Automated Script
    #10 Values for a standard Legend with 9 Bands
    #Blank can be input as None
    #Order is lowest to Highest.
    legendVals = [None,None,1.2,None,None,None,None,None,2.8,None]
    
    def changeLegend(data):
        legendSettings = Ansys.Mechanical.Graphics.Tools.CurrentLegendSettings()
        i = 1
        for val in legendVals:
            if val != None:
                if i < len(legendVals):
                    legendSettings.SetLowerBound(i-1, Quantity(val,"MPa"))
                else:
                    legendSettings.SetUpperBound(i-2, Quantity(val,"MPa"))
            i += 1    
    
    changeLegend(legendVals)