Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Unit Format

Message 1 of 6
510 Views, 5 Replies

Get Unit Format

Hello Community,
   It possible to get the Unit Format using Revit API? Kindly refer the below image for additional Information.

It is possible to get the Format Number, which is marked as Yellow?


Can anybody help me to fix this issue.

@jeremytammik @jeremy_tammik @naveen.kumar.t @RPTHOMAS108 @ricaun 

Thanks & Regards,
Mohamed Arshad K
Message 2 of 6

Hi @Mohamed_Arshad,

This question might be similar to another question which has been handled on this forum before by @RPTHOMAS108 . Kindly have a look at the link below:

  Moturi George,     Developer Advocacy and Support,  ADN Open
Message 3 of 6

Thanks to George for the suggestion. However, this question is probably very much simpler than the one discussed in the other thread. Please just take a look at the official Revit SDK sample Units


The Units sample provides the following functionality:


  • Display the decimal symbol type, digit grouping symbol, digit grouping amount of current project units and users can set them then get the displaying format sample.
  • List all the units in current project and display each unit’s format sample by unit group.
  • List all the available Unit Discipline of current project
  • Classify the project units by the Unit Discipline/unit group
  • When users select one Unit Discipline in the list box to display the corresponding project units name (such as Length or Area) and its format sample. 
  • Display the format options of each unit type and users can set it then get the displaying format sample.
  • When user click the format button then show the format dialog
  • The format information includes the display unit type (such as DUT_KIP_FEET_PER_DEGREE_PER_FOOT), the unit symbol type (such as UST_NONE), and the accuracy (such as 0.2). 


You might also want to read up on the topic by browsing some of The Building Coder articles in the Units category:



Jeremy Tammik, Developer Advocacy and Support, The Building Coder, Autodesk Developer Network, ADN Open
Message 4 of 6

Hi @jeremy_tammik  & 

    Thank you for your answers. And Sorry for the delayed reply., I have tried as many aspects as possible to get the exact value from Units Format UI.


   As @jeremy_tammik  suggested, First I refer the Units.csproj from Revit SDK. In that SDK Project a static value was formatted to get the appropriate value using UnitsFormatUtils method. The value which is formatted that is not matching with the Revit's Units Format UI. Kindly check the below Image.

Reference Image:




The value shown in the Revit's Units Format cannot be obtained using direct formatting as shown in the SDK@jeremy_tammik  can you please suggest any other ways to get the format unit & value from Revit UI, that will be helpful to me 🙂

@naveen.kumar.t @RPTHOMAS108 @jeremy_tammik @jeremytammik 


Thanks & Regards,
Mohamed Arshad K
Message 5 of 6

I don't think you will exactly achieve the same as in the UI easily.


Firstly 12.35 <> 12345

If you review the default imperial units (no project template) you'll see the spec for distance and length both have units of ft however:

'Distance 1234[']'

'Length 1' - 5 11/32"

So we know that 1ft <> 1234ft so clearly there will be no single input value that suits

The square brackets indicate that the units are set to not have the unit symbol at the end


Likewise we have UnitType of Degrees and SlopeDegrees (both are degrees) so both will need to be 12.345 to match UI. You'll have to pick out units such as these to decide what value goes in to match the UI.


After running the below which is likely the nearest you'll get to replicating the values in the UI you still have to check if you should be using 1.2345 or 12.345 or 123.45 or 12345 etc. for a specific unit.


Private Function Obj_230729a(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result
        Dim UIApp As UIApplication = commandData.Application
        Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
        If UIDoc Is Nothing Then Return Result.Cancelled Else
        Dim IntDoc As Document = UIDoc.Document

        Dim Units As Units = IntDoc.GetUnits
        Const n1234 As Double = 1234.56789

        Dim Out As New Dictionary(Of String, List(Of String))

        For Each Item As ForgeTypeId In SpecUtils.GetAllSpecs
            If UnitUtils.IsMeasurableSpec(Item) = False Then
                Continue For
            End If
            Dim D As ForgeTypeId = UnitUtils.GetDiscipline(Item)

            Dim SpecName As String = LabelUtils.GetLabelForSpec(Item)
            Dim DispName As String = LabelUtils.GetLabelForDiscipline(D)

            Dim FO As FormatOptions = Units.GetFormatOptions(Item)
            Dim Str As String
            Dim V As Double = n1234
            Dim Ut As ForgeTypeId = FO.GetUnitTypeId
            If Ut = UnitTypeId.Degrees OrElse Ut = UnitTypeId.Percentage OrElse Ut = UnitTypeId.SlopeDegrees Then
                V /= 100
            End If
            V = UnitUtils.ConvertToInternalUnits(V, FO.GetUnitTypeId)
            Str = UnitFormatUtils.Format(Units, Item, V, False)

            If Out.ContainsKey(DispName) = False Then
                Out.Add(DispName, New List(Of String))
            End If
            Dim L As List(Of String) = Out(DispName)
            L.Add($"{SpecName} {Str}")
        For Each item As KeyValuePair(Of String, List(Of String)) In Out
            For i = 0 To item.Value.Count - 1
        Return Result.Succeeded

    End Function


Message 6 of 6
in reply to: RPTHOMAS108

Should add that the code as is will not add the square brackets part.


If you want to add the square brackets you will have to use




An empty identifier string indicates no symbol set


So if you encounter that you would manually add the default symbol in brackets after the value to replicate what is in the UI.

From FormatOptions.GetValidSymbols select one of the symbols that isn't the (non symbol) empty string.


The point of the square brackets is to identify what units are set for a spec.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups

Rail Community