Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get Length units of a Revit file

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
george1985
297 Views, 4 Replies

Get Length units of a Revit file

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.

4 REPLIES 4
Message 2 of 5
jeremy_tammik
in reply to: george1985

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.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 3 of 5
Mohamed_Arshad
in reply to: george1985

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 🙂

 

Thanks & Regards,
Mohamed Arshad K
Message 4 of 5
george1985
in reply to: jeremy_tammik

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:

george1985_0-1726049117668.png

 

If you further check the Units class, and you will see outdated information. UnitType does not exist since Revit 2021.1:

george1985_2-1726049284759.png




@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.

Message 5 of 5
george1985
in reply to: george1985

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.

Post to forums  

Rail Community


Autodesk Design & Make Report