<?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: Determine the Project Units: Metric or Standard in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/9212164#M78750</link>
    <description>&lt;P&gt;...and it's still an issue...&lt;/P&gt;&lt;P&gt;Document.DisplayUnitSystem will fool you. If the file was created in imperial units and you changed all settings (general, mep, etc.) to metric&amp;nbsp; your units will still be&amp;nbsp;DisplayUnit.IMPERIAL.&lt;/P&gt;&lt;P&gt;That means you are back to Ricky's element parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the project base point (assuming any Revit file has one) to get a length parameter and check if the parameter's display unit is metric to either list the Value in meters or feet.&lt;/P&gt;&lt;P&gt;I also assume that the units in metric files will be meters, centimeters, millimeters, etc., containing "meter" and imperial files won't.&lt;/P&gt;&lt;PRE&gt;double scale = 1;
if (new FilteredElementCollector(doc).OfClass(typeof(BasePoint)).FirstOrDefault() is BasePoint basePoint)
     {
        Parameter paramBasePoint = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
        UnitType unitType = paramBasePoint.Definition.UnitType;
        string sdisplay = paramBasePoint.DisplayUnitType.ToString().ToLower();
        if (sdisplay.Contains("meter"))
           {
               scale = UnitUtils.ConvertFromInternalUnits(1, DisplayUnitType.DUT_METERS);
           }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Dec 2019 15:00:24 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2019-12-19T15:00:24Z</dc:date>
    <item>
      <title>Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/4419879#M78745</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you check if the current documents/projects metrics are Metric or Standard, ie, CM &amp;amp; Metres or Feet &amp;amp; Inches. I need to check if the project units are in Metric, if it isn't then I need to display an error and discontinue the Addin operation. If I dont and the project units are in Standard; when I go to set a pits (FamilyInstance) diameter to 1100(mm) it gets set to 1100 feet.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;instance.get_Parameter("Diameter").SetValueString(diameter.ToString());&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have seen there is a Document.GetUnits() method to get a Units object but its not very clear how to determine the Project Metrics/Measurement Type using this object.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2013 02:43:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/4419879#M78745</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2013-09-12T02:43:42Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/4420925#M78746</link>
      <description>&lt;P&gt;Dear Sam,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The units used internally by Revit are fixed and cannot be changed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you are changing by modifying what you call 'project' units is only affecting the user interface.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you set a parameter representing a length, you always have to specify it in feet:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2011/03/internal-imperial-units.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2011/03/internal-imperial-units.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your length is in millimetres, you need to convert it to feet before setting the parameter value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This has been explained about a thousand times on The Building Coder:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/units" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/units&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It also provides numerous examples of how this conversion can be achieved.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the latest one of these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2013/09/boolean-operations-for-2d-polygons.html#3" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2013/09/boolean-operations-for-2d-polygons.html#3&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this clarifies.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jeremy&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:22:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/4420925#M78746</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2013-09-12T12:22:17Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/5601261#M78747</link>
      <description>&lt;P&gt;Hey Sam, &amp;nbsp;I know this post is old and you've probably figured out your issue. &amp;nbsp;Though Jeremy is right about units in general, if you're looking to get the displayed units on a project level, I've found that using an&amp;nbsp;Element's parameter units works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Metric Project:&lt;/P&gt;&lt;P&gt;elem.get_Parameter("Diameter").DisplayUnitType.ToString()&lt;BR /&gt;"DUT_MILLIMETERS"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Imperial Project:&lt;BR /&gt;elem.get_Parameter("Diameter").DisplayUnitType.ToString()&lt;BR /&gt;"DUT_FRACTIONAL_INCHES"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps someone who might come across this issue.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Apr 2015 13:36:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/5601261#M78747</guid>
      <dc:creator>RickyBell</dc:creator>
      <dc:date>2015-04-21T13:36:37Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/5964846#M78748</link>
      <description>&lt;P&gt;You can also get it from the document object;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;public Result Execute(ExternalCommandData CommandData, ref string message, ElementSet elements)
{
   var units = CommandData.Application.ActiveUIDocument.Document.DisplayUnitSystem;&lt;BR /&gt;   return Result.Succeeded;
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Dec 2015 14:00:31 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/5964846#M78748</guid>
      <dc:creator>SerhanB</dc:creator>
      <dc:date>2015-12-25T14:00:31Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/7419576#M78749</link>
      <description>&lt;P&gt;Lately I suddenly got a lot of documents throwing an exception when accessing&amp;nbsp;Document.DisplayUnitSystem so I'd recomment to wrap this in a try catch. Don't know why this is happening suddenly, never had an issue with this before.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Sep 2017 08:12:25 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/7419576#M78749</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-09-29T08:12:25Z</dc:date>
    </item>
    <item>
      <title>Re: Determine the Project Units: Metric or Standard</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/9212164#M78750</link>
      <description>&lt;P&gt;...and it's still an issue...&lt;/P&gt;&lt;P&gt;Document.DisplayUnitSystem will fool you. If the file was created in imperial units and you changed all settings (general, mep, etc.) to metric&amp;nbsp; your units will still be&amp;nbsp;DisplayUnit.IMPERIAL.&lt;/P&gt;&lt;P&gt;That means you are back to Ricky's element parameters.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the project base point (assuming any Revit file has one) to get a length parameter and check if the parameter's display unit is metric to either list the Value in meters or feet.&lt;/P&gt;&lt;P&gt;I also assume that the units in metric files will be meters, centimeters, millimeters, etc., containing "meter" and imperial files won't.&lt;/P&gt;&lt;PRE&gt;double scale = 1;
if (new FilteredElementCollector(doc).OfClass(typeof(BasePoint)).FirstOrDefault() is BasePoint basePoint)
     {
        Parameter paramBasePoint = basePoint.get_Parameter(BuiltInParameter.BASEPOINT_ELEVATION_PARAM);
        UnitType unitType = paramBasePoint.Definition.UnitType;
        string sdisplay = paramBasePoint.DisplayUnitType.ToString().ToLower();
        if (sdisplay.Contains("meter"))
           {
               scale = UnitUtils.ConvertFromInternalUnits(1, DisplayUnitType.DUT_METERS);
           }
    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 15:00:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/determine-the-project-units-metric-or-standard/m-p/9212164#M78750</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-12-19T15:00:24Z</dc:date>
    </item>
  </channel>
</rss>

