Handling Value Precision and Units in Revit Plugin Development

Handling Value Precision and Units in Revit Plugin Development

igorevih033
Observer Observer
511 Views
3 Replies
Message 1 of 4

Handling Value Precision and Units in Revit Plugin Development

igorevih033
Observer
Observer

Добрый вечер. Не могли бы вы мне помочь? Я разработал плагин для Revit на C# и столкнулся со следующей проблемой: мне нужно было прочитать значение числового параметра ( parameter.AsDouble() ), но когда я читаю его таким образом, я могу получить значение в разных единицах измерения (например, футы, квадратные футы). , как понимается число и т. д.), что для меня неприемлемо, так как мне нужно записать точное значение в конкретное поле другого параметра. Также есть метод параметр.AsValueString() , который позволяет мне считывать значение непосредственно в нужных элементах измерения, но в некоторых параметрах он округляет значение. Например, вместо 0,8 он возвращает 1, что важно, например, если я измеряю в миллиметрах.Как мне с этим пережить? *Я разрабатываю плагины на 2023 год, но они также должны работать и с более ранними версиями с 2019 по 2021 год.

0 Likes
512 Views
3 Replies
Replies (3)
Message 2 of 4

moturi.magati.george
Autodesk
Autodesk

Hi @igorevih033,

 

Revit uses imperial units internally i.e. feet for length.
You can get the internal imperial units and convert them to the metric units. Revit API has a method 
ConvertFromInternalUnits exposed that you can use for the same.


There is also a blog post that explains how to convert the same on the link below:
https://help.autodesk.com/view/RVT/2023/ENU/?guid=Revit_API_Revit_API_Developers_Guide_Introduction_...

2022> https://www.revitapidocs.com/2024/60c6aac3-8306-c56e-b62f-b7011b9ad7b6.htm
2021< https://www.revitapidocs.com/2021.1/9cc2c0ea-f59f-9d76-ce19-ae7eede03bbd.htm


  Moturi George,     Developer Advocacy and Support,  ADN Open
0 Likes
Message 3 of 4

jeremy_tammik
Alumni
Alumni

Just for my own understanding, I passed this into Google translate. Here is what it returns:

  

Good evening. Can you help me? I developed a Revit plugin in C# and ran into the following problem: I needed to read the value of a numeric parameter ( parameter.AsDouble() ), but when I read it this way, I can get the value in different units (eg feet, square feet). , how the number is understood, etc.), which is unacceptable for me, since I need to write the exact value into a specific field of another parameter. There is also a parameter.AsValueString() method that allows me to read the value directly into the desired dimension members, but in some parameters it rounds the value. For example, instead of 0.8 it returns 1, which is important, for example, if I measure in millimeters. How can I deal with this? *I'm developing plugins for 2023, but they should also work with older versions from 2019 to 2021.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Dear Igor, 

  

The answer is simple: do not use AsValueString!

  

For a floating-point value, read it as the double number that it is using AsDouble. That will return the exact value stored in the database with no inaccuracy or rounding except the normal unavoidable precision issues dealing with real numbers on a digital computer.

  

The number returned by AsDouble can then be passed into the receiving end parameter using Set.

  

More details here:

  

    

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes