UnitFormatType Enumeration
Get The Full List of All Available Unit Formats
//Must be on the QueuedTask.Run()
var unit_formats = Enum.GetValues(typeof(UnitFormatType))
.OfType<UnitFormatType>().ToList();
System.Diagnostics.Debug.WriteLine("All available units\r\n");
foreach (var unit_format in unit_formats)
{
var units = DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(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 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);
Get The List of Default 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("Default project units\r\n");
foreach (var unit_format in unit_formats)
{
var default_unit = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_format);
var line = $"{unit_format.ToString()}: {default_unit.DisplayName}, {default_unit.UnitCode}";
System.Diagnostics.Debug.WriteLine(line);
}
System.Diagnostics.Debug.WriteLine("");
Get A Specific Default Unit Format 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 default_unit = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(
UnitFormatType.Distance);
Set 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
//Get the full list of all available location units
var all_units = DisplayUnitFormats.Instance.GetPredefinedProjectUnitFormats(
UnitFormatType.Location);
//keep units with an even factory code
var list_units = all_units.Where(du => du.UnitCode % 2 == 0).ToList();
//set them as the new location unit collection. A new default is not being specified...
DisplayUnitFormats.Instance.SetProjectUnitFormats(list_units);
//set them as the new location unit collection along with a new default
DisplayUnitFormats.Instance.SetProjectUnitFormats(
list_units, list_units.First());
//Note: UnitFormatType.Page, UnitFormatType.Symbol2D, UnitFormatType.Symbol3D
//cannot be set.
Set the Defaults for the Project Unit Formats
//Must be on the QueuedTask.Run()
var unit_formats = Enum.GetValues(typeof(UnitFormatType)).OfType<UnitFormatType>().ToList();
foreach (var unit_type in unit_formats)
{
var current_default = DisplayUnitFormats.Instance.GetDefaultProjectUnitFormat(unit_type);
//Arbitrarily pick the last unit in each unit format list
var replacement = DisplayUnitFormats.Instance.GetProjectUnitFormats(unit_type).Last();
DisplayUnitFormats.Instance.SetDefaultProjectUnitFormat(replacement);
var line = $"{current_default.DisplayName}, {current_default.UnitName}, {current_default.UnitCode}";
var line2 = $"{replacement.DisplayName}, {replacement.UnitName}, {replacement.UnitCode}";
System.Diagnostics.Debug.WriteLine($"Format: {unit_type.ToString()}");
System.Diagnostics.Debug.WriteLine($" Current default: {line}");
System.Diagnostics.Debug.WriteLine($" Replacement default: {line2}");
}
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...
System.Object
System.ValueType
System.Enum
ArcGIS.Desktop.Core.UnitFormats.UnitFormatType
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3 or higher.