<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11536691#M24370</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have similar problem, but for some reason I cannot get the same results when following &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1035859"&gt;@RPTHOMAS108&lt;/a&gt;&amp;nbsp;solution:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; double total_thickness_in = 12.2 / 304.8;
 FormatOptions FO = new FormatOptions();
FO.UseDefault = false;
FO.Accuracy = 0.0001;
FO.SuppressTrailingZeros = true;
FormatValueOptions format = new FormatValueOptions();
format.SetFormatOptions(FO);
string total_thickness_mm = UnitFormatUtils.Format(doc.GetUnits(), SpecTypeId.Length, total_thickness_in, true, format);&lt;/LI-CODE&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;0.0122&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;expected: 12.20&lt;/P&gt;&lt;P&gt;I don't want to set &lt;STRONG&gt;&lt;EM&gt;SetUnitTypeID&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;to Milimeters as I want to use default units set in document:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="atissed_0-1667848146773.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1137122i0CCD2BD190550681/image-size/medium?v=v2&amp;amp;px=400" role="button" title="atissed_0-1667848146773.png" alt="atissed_0-1667848146773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2022 19:12:00 GMT</pubDate>
    <dc:creator>atis.sed</dc:creator>
    <dc:date>2022-11-07T19:12:00Z</dc:date>
    <item>
      <title>Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/10545377#M24368</link>
      <description>&lt;P&gt;I am trying to create a user interface where a user can insert thickness.&lt;BR /&gt;I want to display the unit next to the text (which is converted from double).&amp;nbsp;&lt;BR /&gt;The approach I used is as follows:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;ForgeTypeId LengthUnit = SpecTypeId.Length;&lt;BR /&gt;var formatOpt = Doc.GetUnits().GetFormatOptions(LengthUnit);&lt;BR /&gt;ForgeTypeId unitType = formatOptions.GetUnitTypeId();&lt;BR /&gt;FormatValueOptions formateValueOptions = new FormatValueOptions();&lt;BR /&gt;formateValueOptions.AppendUnitSymbol = true;&lt;BR /&gt;string formatedValue = UnitFormatUtils.Format(Doc.GetUnits(), LengthUnitType, d, true, formateValueOptions);&lt;BR /&gt;&lt;BR /&gt;The issue is that it works while the number is non-decimal number, ex:&amp;nbsp; &amp;nbsp; 12 mm&lt;BR /&gt;while the unit symbol dissapears when the number has decimal unit ex:&amp;nbsp; &amp;nbsp;12.2&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Is there a way I can make it work for all decimals ang numericals?&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 13:47:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/10545377#M24368</guid>
      <dc:creator>waleed.hany</dc:creator>
      <dc:date>2021-08-14T13:47:35Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/10546029#M24369</link>
      <description>&lt;P&gt;Not sure what you mean by that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Private Function Obj_210814b(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result
   Dim UIDoc As UIDocument = commandData.Application.ActiveUIDocument
   If UIDoc Is Nothing Then Return Result.Cancelled Else
   Dim IntDoc As Document = UIDoc.Document

   Dim val As Double = 12.2 / 304.8

   Dim formateValueOptions As New FormatValueOptions
   formateValueOptions.AppendUnitSymbol = True
   Dim Unts As Units = IntDoc.GetUnits
   Dim Ops As FormatOptions = Unts.GetFormatOptions(SpecTypeId.Length)
   Ops.UseDefault = False
   Ops.Accuracy = 0.01
   Ops.SetUnitTypeId(UnitTypeId.Millimeters)
   Ops.SetSymbolTypeId(SymbolTypeId.Mm)
   formateValueOptions.SetFormatOptions(Ops)

   Debug.WriteLine(UnitFormatUtils.Format(Unts, SpecTypeId.Length, val, True, formateValueOptions))

   Ops.Accuracy = 1
   formateValueOptions.SetFormatOptions(Ops)

   Debug.WriteLine(UnitFormatUtils.Format(Unts, SpecTypeId.Length, val, True, formateValueOptions))

   Return Result.Succeeded
End Function&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;12.20 mm
12 mm&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They need to address capitalisation of Mm since that representation is for a &lt;A href="https://en.wikipedia.org/wiki/Metric_prefix" target="_self"&gt;megametre not a millimetre&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Aug 2021 23:53:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/10546029#M24369</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2021-08-14T23:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11536691#M24370</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have similar problem, but for some reason I cannot get the same results when following &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1035859"&gt;@RPTHOMAS108&lt;/a&gt;&amp;nbsp;solution:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt; double total_thickness_in = 12.2 / 304.8;
 FormatOptions FO = new FormatOptions();
FO.UseDefault = false;
FO.Accuracy = 0.0001;
FO.SuppressTrailingZeros = true;
FormatValueOptions format = new FormatValueOptions();
format.SetFormatOptions(FO);
string total_thickness_mm = UnitFormatUtils.Format(doc.GetUnits(), SpecTypeId.Length, total_thickness_in, true, format);&lt;/LI-CODE&gt;&lt;P&gt;The output is:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;0.0122&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;expected: 12.20&lt;/P&gt;&lt;P&gt;I don't want to set &lt;STRONG&gt;&lt;EM&gt;SetUnitTypeID&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;to Milimeters as I want to use default units set in document:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="atissed_0-1667848146773.png" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1137122i0CCD2BD190550681/image-size/medium?v=v2&amp;amp;px=400" role="button" title="atissed_0-1667848146773.png" alt="atissed_0-1667848146773.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 19:12:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11536691#M24370</guid>
      <dc:creator>atis.sed</dc:creator>
      <dc:date>2022-11-07T19:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537042#M24371</link>
      <description>&lt;P&gt;You are converting 12.2mm to ft (internal units for length) in the sense that you are dividing 12.2 by 304.8.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In terms of output you are getting what you are asking for i.e. 0.0122m is 12.2mm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also from above image your current document units for length are mm and the square brackets indicate the symbol isn't set.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your main error is that you are not getting the format options i.e. after you get the units from the document (defaults) you should get the format options from the units (not create new format options).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Unts.GetFormatOptions(SpecTypeId.Length)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I were writing the above again, I would get rid of lines related to FormatValueOptions. You can do most of what you want with Units and FormatOptions i.e. I believe that if you change the FormatOptions of the input units then you don't really need to use the overload with the FormatValueOptions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;FormatValueOptions contains&amp;nbsp;AppendUnitSymbol which overrides what is in the FormatOptions (it is false by default meaning use FormatOptions).&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2022 22:23:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537042#M24371</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-11-07T22:23:38Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537792#M24372</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am converting&amp;nbsp;&lt;SPAN&gt;12.2mm to ft&amp;nbsp;just for testing purposes, because Revits internal units are in ft.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then I am using&amp;nbsp;&lt;EM&gt;FormatValueOptions&amp;nbsp;&lt;/EM&gt;to set rounding to 0.1 for this Method. Because although rounding is set to 0 in my Document, I want to change that to 0.1 .&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;In my final Method I get value from Wall layer thickness which is let's say 152.4mm but is rounded to 152mm.&amp;nbsp;&amp;nbsp;So I want to change Accuracy by setting custom&amp;nbsp;&lt;EM&gt;FormatValueOptions.&amp;nbsp;&lt;/EM&gt;But setting Accuracy just to &lt;STRONG&gt;&lt;EM&gt;0.1&lt;/EM&gt; &lt;/STRONG&gt;gives me output of &lt;STRONG&gt;0.2mm&amp;nbsp;&lt;/STRONG&gt;instead of &lt;STRONG&gt;152.4mm&lt;/STRONG&gt; which is very strange...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 08:00:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537792#M24372</guid>
      <dc:creator>atis.sed</dc:creator>
      <dc:date>2022-11-08T08:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537955#M24373</link>
      <description>&lt;P&gt;152.4 is half a ft so your input into the function should be 0.5. There is no reason to consider it being 152.4 you are just taking the value in internal units from the wall layer of 0.5 and feeding that into the function. The output is then in whatever units are used in the FormatOptions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Depending on midpoint rounding 0.1524 rounded to 0.1 is 0.2 (it seems your output units are likely still in m for some reason).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0) Get units from document Document.GetUnits&lt;/P&gt;&lt;P&gt;1) &lt;U&gt;Get the format options from the Units Units.GetFormatOptions(SpecTypeId)&lt;/U&gt;&lt;/P&gt;&lt;P&gt;2) Change the unit format options&lt;/P&gt;&lt;P&gt;3) Put the changed unit FormatOptions back: Units.SetFormatOptions(ForgeTypeId, FormatOptions)&lt;/P&gt;&lt;P&gt;4) Use UnitFormatUtils(Units, ForgeTypeId, Double, Boolean)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;0) Get units from document Document.GetUnits&lt;/P&gt;&lt;P&gt;1) &lt;U&gt;Get the format options from the Units Units.GetFormatOptions(SpecTypeId)&lt;/U&gt;&lt;/P&gt;&lt;P&gt;2) Change the unit format options&lt;/P&gt;&lt;P&gt;3) Put the changed unit FormatOptions back: FormatValueOptions.SetFormatOptions(FormatOptions)&lt;/P&gt;&lt;P&gt;4) Use UnitFormatUtils(Units, ForgeTypeId, Double, Boolean, FormatValueOptions)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You've not fully done either of these processes above, the thing you haven't done is the thing I underlined above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When you use 'new FormatOptions' consider the defaults as not being taken from the document, there is no argument for document so how can it know which document you are dealing with? It doesn't even know which spec it is formatting unless you provide that similar to below but again how the units in that relate to units in a document when it is created in isolation is vague (so I wouldn't use it).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Refer also to the difference between:&lt;/P&gt;&lt;P&gt;New FormatOptions&lt;/P&gt;&lt;P&gt;New FormatOptions(ForgeTypeId)&lt;/P&gt;&lt;P&gt;Noted in RevitAPI.chm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The majority of the time you want to just format units the way that they are formatted for the user in the UI. So you pass the Units from the Document into the function without change. Doing something else often requires reinventing the UI of the unit formatting settings. For example, what if your user is using Imperial not Metric are you going to then allow them to decide between ft/inches/ft and fractional inches with settings for all the rounded fractions etc. Are you going to invent an alternative unit settings interface for all of that or just avoid people that use that in North America? By dealing with units independently you are kind of building in cultural limitations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, a classic issue for me is that level elevations should be in m but if the default for length is mm I need to do something special because there is no distinction between Elevation and Length in the unit system. The metric level head magically deals with this contradiction: it has a label that displays the Elevation in m even though there is nothing to suggest it should do that (since spec for Elevation parameter is length which is in mm).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cases like that is what I would use it for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 08 Nov 2022 10:45:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11537955#M24373</guid>
      <dc:creator>RPTHOMAS108</dc:creator>
      <dc:date>2022-11-08T10:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to display unit symbol next to number in case of dicemal number using FormatValueOptions</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11538309#M24374</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Great point. Just have to stick with document settings.&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1035859"&gt;@RPTHOMAS108&lt;/a&gt;&amp;nbsp;wrote:&lt;P&gt;The majority of the time you want to just format units the way that they are formatted for the user in the UI. So you pass the Units from the Document into the function without change. Doing something else often requires reinventing the UI of the unit formatting settings. For example, what if your user is using Imperial not Metric are you going to then allow them to decide between ft/inches/ft and fractional inches with settings for all the rounded fractions etc. Are you going to invent an alternative unit settings interface for all of that or just avoid people that use that in North America? By dealing with units independently you are kind of building in cultural limitations.&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 08 Nov 2022 12:35:21 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/unable-to-display-unit-symbol-next-to-number-in-case-of-dicemal/m-p/11538309#M24374</guid>
      <dc:creator>atis.sed</dc:creator>
      <dc:date>2022-11-08T12:35:21Z</dc:date>
    </item>
  </channel>
</rss>

