<?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: Converting from Internal Units to Meters or Millimeters in Revit API 2023 or 2024 in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025601#M11507</link>
    <description>&lt;P&gt;Many thanks to Jonathan for the helpful answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yup, you basically have two choices: DIY or use the official Revit API support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, I am a fan of DIY and retaining total control (and responsibility). Not always the most efficient way to go, though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, again, I mostly just have to deal with very simple units, such as the length issue you describe. You can look at The Building Coder samples to see how I handle it there for various situations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, the Util class includes a region for Unit handling:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/Util.cs#L1206-L1411" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/Util.cs#L1206-L1411&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main part of interest to you is at the beginning of that region:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private const double _inchToMm = 25.4;
        private const double _footToMm = 12 * _inchToMm;
        private const double _footToMeter = _footToMm * 0.001;
        private const double _sqfToSqm = _footToMeter * _footToMeter;
        private const double _cubicFootToCubicMeter = _footToMeter * _sqfToSqm;

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to millimetres.
        /// &amp;lt;/summary&amp;gt;
        public static double FootToMm(double length)
        {
            return length * _footToMm;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to millimetres,
        ///     rounded to the closest millimetre.
        /// &amp;lt;/summary&amp;gt;
        public static int FootToMmInt(double length)
        {
            //return (int) ( _feet_to_mm * d + 0.5 );
            return (int) Math.Round(_footToMm * length,
                MidpointRounding.AwayFromZero);
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to metres.
        /// &amp;lt;/summary&amp;gt;
        public static double FootToMetre(double length)
        {
            return length * _footToMeter;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in millimetres to feet.
        /// &amp;lt;/summary&amp;gt;
        public static double MmToFoot(double length)
        {
            return length / _footToMm;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given point or vector from millimetres to feet.
        /// &amp;lt;/summary&amp;gt;
        public static XYZ MmToFoot(XYZ v)
        {
            return v.Divide(_footToMm);
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given volume in feet to cubic meters.
        /// &amp;lt;/summary&amp;gt;
        public static double CubicFootToCubicMeter(double volume)
        {
            return volume * _cubicFootToCubicMeter;
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Jun 2023 08:46:54 GMT</pubDate>
    <dc:creator>jeremy_tammik</dc:creator>
    <dc:date>2023-06-11T08:46:54Z</dc:date>
    <item>
      <title>Converting from Internal Units to Meters or Millimeters in Revit API 2023 or 2024</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025099#M11505</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Untitled-1.jpg" style="width: 600px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/1225939i7AB920D2BDE37A48/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Untitled-1.jpg" alt="Untitled-1.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I'm new to Revit API and&amp;nbsp; facing an issue while trying to convert values from internal units to meters or millimeters in the Revit API. Specifically, when I attempt to modify a parameter by entering a value like 15, I expect it to represent 15 meters. However, the code seems to convert this value to 15 feet, which is equivalent to approximately 4.572 meters.&lt;/P&gt;&lt;P&gt;I would greatly appreciate any guidance or suggestions on how to correctly convert values from internal units (feet) to meters or millimeters in the Revit API with a class for units. I want to ensure that my parameter modifications are accurately reflected in the desired unit system.&lt;/P&gt;&lt;P&gt;Thank you in advance for your assistance!&lt;/P&gt;&lt;P&gt;attaching a picture explaining what is going on .&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 21:37:46 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025099#M11505</guid>
      <dc:creator>hamza_rahahleh9</dc:creator>
      <dc:date>2023-06-10T21:37:46Z</dc:date>
    </item>
    <item>
      <title>Re: Converting from Internal Units to Meters or Millimeters in Revit API 2023 or 2024</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025544#M11506</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;You need to use the UnitUtils class&amp;nbsp;&amp;nbsp;&lt;A href="https://www.revitapidocs.com/2023/128dd879-fea8-5d7b-1eb2-d64f87753990.htm" target="_blank" rel="noopener"&gt;https://www.revitapidocs.com/2023/128dd879-fea8-5d7b-1eb2-d64f87753990.htm&lt;/A&gt;&amp;nbsp;.&lt;/P&gt;&lt;P&gt;This explains the change that happened in r2022 well &lt;A href="https://archi-lab.net/handling-the-revit-2022-unit-changes/" target="_blank" rel="noopener"&gt;https://archi-lab.net/handling-the-revit-2022-unit-changes/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;This also -&amp;nbsp;&lt;A href="https://thebuildingcoder.typepad.com/blog/2021/04/pdf-export-forgetypeid-and-multi-target-add-in.html#2" target="_blank"&gt;https://thebuildingcoder.typepad.com/blog/2021/04/pdf-export-forgetypeid-and-multi-target-add-in.html#2&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Best , Jonathan&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 07:42:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025544#M11506</guid>
      <dc:creator>jonathan.taVCBM2</dc:creator>
      <dc:date>2023-06-11T07:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: Converting from Internal Units to Meters or Millimeters in Revit API 2023 or 2024</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025601#M11507</link>
      <description>&lt;P&gt;Many thanks to Jonathan for the helpful answer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yup, you basically have two choices: DIY or use the official Revit API support.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, I am a fan of DIY and retaining total control (and responsibility). Not always the most efficient way to go, though.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, again, I mostly just have to deal with very simple units, such as the length issue you describe. You can look at The Building Coder samples to see how I handle it there for various situations:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, the Util class includes a region for Unit handling:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/Util.cs#L1206-L1411" target="_blank"&gt;https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/Util.cs#L1206-L1411&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The main part of interest to you is at the beginning of that region:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;        private const double _inchToMm = 25.4;
        private const double _footToMm = 12 * _inchToMm;
        private const double _footToMeter = _footToMm * 0.001;
        private const double _sqfToSqm = _footToMeter * _footToMeter;
        private const double _cubicFootToCubicMeter = _footToMeter * _sqfToSqm;

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to millimetres.
        /// &amp;lt;/summary&amp;gt;
        public static double FootToMm(double length)
        {
            return length * _footToMm;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to millimetres,
        ///     rounded to the closest millimetre.
        /// &amp;lt;/summary&amp;gt;
        public static int FootToMmInt(double length)
        {
            //return (int) ( _feet_to_mm * d + 0.5 );
            return (int) Math.Round(_footToMm * length,
                MidpointRounding.AwayFromZero);
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in feet to metres.
        /// &amp;lt;/summary&amp;gt;
        public static double FootToMetre(double length)
        {
            return length * _footToMeter;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given length in millimetres to feet.
        /// &amp;lt;/summary&amp;gt;
        public static double MmToFoot(double length)
        {
            return length / _footToMm;
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given point or vector from millimetres to feet.
        /// &amp;lt;/summary&amp;gt;
        public static XYZ MmToFoot(XYZ v)
        {
            return v.Divide(_footToMm);
        }

        /// &amp;lt;summary&amp;gt;
        ///     Convert a given volume in feet to cubic meters.
        /// &amp;lt;/summary&amp;gt;
        public static double CubicFootToCubicMeter(double volume)
        {
            return volume * _cubicFootToCubicMeter;
        }&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2023 08:46:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/converting-from-internal-units-to-meters-or-millimeters-in-revit/m-p/12025601#M11507</guid>
      <dc:creator>jeremy_tammik</dc:creator>
      <dc:date>2023-06-11T08:46:54Z</dc:date>
    </item>
  </channel>
</rss>

