Result-Specific Legend Settings

Some legend settings are specific to the result object. To access result-specific legend settings, you first navigate to the result with the legend that you want to manipulate and then use the command CurrentLegendSettings:

Ansys.Mechanical.Graphics.Tools.CurrentLegendSettings()


Note:  You can only manipulate the legend of the result that is currently active.


These properties are available for the object for result-specific legend settings:

PropertyDescription
NumberOfBandsGets or sets the number of bands on the legend.
AllScientificNotationGets or sets whether result values are to display in scientific notation.
DigitsGets or sets the number of significant digits.
ColorSchemeGets or sets the color scheme for the legend.
SemiTransparencyGets or sets whether the legend is semi-transparent.
LogarithmiScaleGets or sets whether the result values are distributed in a logarithmic scale.
HighFidelityGets or sets whether the high fidelity mode is on.

GetLowerBound

Gets the lower bound value of the specified band.

SetLowerBoundSets the lower bound value of the specified band.
GetUpperBoundGets the upper bound value of the specified band.
SetUpperBoundSets the upper bound value of the specified band.
GetBandColorGets the color of the specified band.
SetBandColorSets the color of the specified band.
GetBandColorAutoGets whether the color of the specified band is set to Automatic.
SetBandColorAutoSets the color of the specified band to Automatic.
ResetColorsResets all colors to default values.
ExportLegendExports the legend settings to an XML file.
ResetResets all legend customizations to default values.

This code modifies many result-specific legend settings for the current result object, including whether result values are to display in scientific notation, number of bands, color scheme, and semi-transparency, and it then exports these settings to an XML file:

legendSettings = Ansys.Mechanical.Graphics.Tools.CurrentLegendSettings()
legendSettings.AllScientificNotation = False
legendSettings.Digits = 4
legendSettings.NumberOfBands = 7 
legendSettings.ColorScheme = LegendColorSchemeType.ReverseGrayScale
legendSettings.SemiTransparency = True
legendSettings.SetLowerBound(0, Quantity(2.38e-8,'m'))
legendSettings.SetUpperBound(0, Quantity(3.38e-8,'m'))
legendSettings.SetUpperBound(1, Quantity(4.38e-8,'m'))
legendSettings.SetUpperBound(2, Quantity(5.38e-8,'m'))
legendSettings.SetBandColor(0, Ansys.Mechanical.DataModel.Constants.Colors.Gray)
legendSettings.SetBandColor(1, Ansys.Mechanical.DataModel.Constants.Colors.Blue)
legendSettings.SetBandColor(2, Ansys.Mechanical.DataModel.Constants.Colors.Cyan)
legendSettings.SetBandColor(3, Ansys.Mechanical.DataModel.Constants.Colors.Green)
legendSettings.SetBandColor(4, Ansys.Mechanical.DataModel.Constants.Colors.Yellow)
legendSettings.SetBandColor(5, Ansys.Mechanical.DataModel.Constants.Colors.Red)
legendSettings.SetBandColor(6, Ansys.Mechanical.DataModel.Constants.Colors.White)
legendSettings.ExportLegend("E://file.xml")


Note:  Color can be set in RGB using Ansys.Mechanical.DataModel.Utilities.Colors.RGB:

legendSettings.SetBandColor(0,Ansys.Mechanical.DataModel.Utilities.Colors.RGB(255,0,0))


The following figure shows the legend using the original settings versus the modified settings.