GetProjectUnitFormats Method (IDisplayUnitFormats)
Get the current list of unit formats in the current project for the given
UnitFormatType
Get The List of Unit Formats for the Current Project
//Must be on the QueuedTask.Run()
var unit_formats = Enum.GetValues(typeof(UnitFormatType))
.OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("Project units\r\n");
foreach (var unit_format in unit_formats)
{
var units = DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_format);
System.Diagnostics.Debug.WriteLine(unit_format.ToString());
foreach (var display_unit_format in units)
{
var line = $"{display_unit_format.DisplayName}, {display_unit_format.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
System.Diagnostics.Debug.WriteLine("");
}
Get A Specific List of Unit Formats for the Current Project
//Must be on the QueuedTask.Run()
//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance,
//UnitFormatType.Direction, UnitFormatType.Location, UnitFormatType.Page
//UnitFormatType.Symbol2D, UnitFormatType.Symbol3D
var units = DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Distance);
Update Unit Formats for the Project
//UnitFormatType.Angular, UnitFormatType.Area, UnitFormatType.Distance,
//UnitFormatType.Direction, UnitFormatType.Location
var angle_units = DisplayUnitFormats.Instance.GetProjectUnitFormats(UnitFormatType.Angular);
//Edit the display name of each unit - append the abbreviation
foreach (var unit in angle_units)
{
unit.DisplayName = $"{unit.DisplayName} ({unit.Abbreviation})";
}
//apply the changes to the units and set the default to be the first entry
DisplayUnitFormats.Instance.SetProjectUnitFormats(angle_units, angle_units.First());
//The project must be saved to persist the changes...
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.