ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Core.UnitFormats Namespace / IDisplayUnitFormats Interface / SetProjectUnitFormats Method
Example

In This Topic
    SetProjectUnitFormats Method (IDisplayUnitFormats)
    In This Topic
    Sets the list of project unit formats for the current project for the given UnitFormatType.
    Syntax

    Parameters

    availableUnits
    defaultUnit
    Example
    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.
    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...
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also