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:
| Property | Description |
|---|---|
NumberOfBands | Gets or sets the number of bands on the legend. |
AllScientificNotation | Gets or sets whether result values are to display in scientific notation. |
Digits | Gets or sets the number of significant digits. |
ColorScheme | Gets or sets the color scheme for the legend. |
SemiTransparency | Gets or sets whether the legend is semi-transparent. |
LogarithmiScale | Gets or sets whether the result values are distributed in a logarithmic scale. |
HighFidelity | Gets or sets whether the high fidelity mode is on. |
|
|
Gets the lower bound value of the specified band. |
SetLowerBound | Sets the lower bound value of the specified band. |
GetUpperBound | Gets the upper bound value of the specified band. |
SetUpperBound | Sets the upper bound value of the specified band. |
GetBandColor | Gets the color of the specified band. |
SetBandColor | Sets the color of the specified band. |
GetBandColorAuto | Gets whether the color of the specified band is set to
Automatic. |
SetBandColorAuto | Sets the color of the specified band to
Automatic. |
ResetColors | Resets all colors to default values. |
ExportLegend | Exports the legend settings to an XML file. |
Reset | Resets 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.