ArcGIS Pro 3.1 API Reference Guide
ArcGIS.Desktop.Core.UnitFormats Namespace / IDisplayUnitFormats Interface / GetDefaultProjectUnitFormat Method
Example

In This Topic
    GetDefaultProjectUnitFormat Method (IDisplayUnitFormats)
    In This Topic
    Gets the default unit format in the current project for the given UnitFormatType.
    Syntax
    DisplayUnitFormat GetDefaultProjectUnitFormat( 
       UnitFormatType defaultFormatType
    )
    Function GetDefaultProjectUnitFormat( _
       ByVal defaultFormatType As UnitFormatType _
    ) As DisplayUnitFormat

    Parameters

    defaultFormatType

    Return Value

    Example
    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 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}");
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3.0 or higher.
    See Also