How to get the Length units of the currently opened Revit file - via Revit api?
I found a similar topic, but without an answer.
I am not sure how to obtain length units from this Units object.
Units units = doc.GetUnits();
I would be very grateful for some code snippet, in any programming language.
Thank you in advance for the help.
Solved! Go to Solution.
Solved by Mohamed_Arshad. Go to Solution.
GetUnits is documented. Please read the documentation on it:
https://www.revitapidocs.com/2024/9ed56178-e9ae-b4bc-1c0e-e6a867ae3557.htm
Note that it returns a Units object containing the document's default settings for formatting numbers with units.
Note the word formatting.
Also note that all lengths in the Revit database are stored in imperial feet:
https://thebuildingcoder.typepad.com/blog/2011/03/internal-imperial-units.html
That cannot be changed, so there is no purpose in asking a Revit file for its length units; the answer will always be the same: imperial feet, consisting of 12 inches a 25.4 millimetres.
Hi @george1985
You need to use the format option to get the particular Unit like Length. Kindly check the below code snippet for additional reference.
Reference Code Snippet
///The Sample will get Length Unit from the projec and get the unit name and display to the user.
Units units = doc.GetUnits();
FormatOptions option = units.GetFormatOptions(SpecTypeId.Length);
ForgeTypeId unitTypeIs = option.GetUnitTypeId(); //Length Unit
string unitName = LabelUtils.GetLabelForUnit(unitTypeIs);
TaskDialog.Show("Information", unitName);
Hope this will helps 🙂
Hi @jeremy_tammik ,
Have you even read my post?
You used the same GetUnits link, which I have in my post.
@jeremy_tammik wrote:GetUnits is documented. Please read the documentation on it:
https://www.revitapidocs.com/2024/9ed56178-e9ae-b4bc-1c0e-e6a867ae3557.htm
Note that it returns a Units object containing the document's default settings for formatting numbers with units.
Note the word formatting.
GetUnits is not documented. Click on the link you yourself copy-pasted, and you will only see "Gets the Units object" text. That's all:
If you further check the Units class, and you will see outdated information. UnitType does not exist since Revit 2021.1:
@jeremy_tammik wrote:Also note that all lengths in the Revit database are stored in imperial feet:
https://thebuildingcoder.typepad.com/blog/2011/03/internal-imperial-units.html
That cannot be changed, so there is no purpose in asking a Revit file for its length units; the answer will always be the same: imperial feet, consisting of 12 inches a 25.4 millimetres.
Another misleading information. It has nothing to do with my question.
Nowhere in my post, I ask how Revit internally records units in its database.
I would appreciate if you would refrain from replying, if you don't know the answer.
Such replies of yours, just shed bad light on our Autodesk support.
Hi @Mohamed_Arshad ,
Brilliant!
Thank you very much for the shared knowledge and solution.
Can't find what you're looking for? Ask the community or share your knowledge.