How to retreive unit symbols (ex. length) from document using revit api?

How to retreive unit symbols (ex. length) from document using revit api?

waleed.hany
Contributor Contributor
1,079 Views
5 Replies
Message 1 of 6

How to retreive unit symbols (ex. length) from document using revit api?

waleed.hany
Contributor
Contributor

Is there a way to get the units (units of length as an example) from document as symbol (ex. mm or ft) using revit api?
Thanks 

0 Likes
1,080 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

Hi, as far as I know the units are internally represented as ft (in general, unit used are imperial units). So, when you retrieve them they will be in that unit.

You can convert to other units using

 

//Get distance between two points
double dist = p1.DistanceTo(p2); //in ft
double distInMeters = UnitUtils.ConvertFromInternalUnits(measure, UnitTypeId.Meters))); //in m

 

You can change Meters for other types of measurements.

I wish this helps,

Jose Antonio Lorencio Abril

0 Likes
Message 3 of 6

waleed.hany
Contributor
Contributor

Hello Jose
Thanks for the insight
At the moment What I want to achive is retriving the unit used in the document as symbol

waleedhany_1-1628980548704.png
For example in that case it would return "mm"
is there a direct way to achiving that ?
Thanks

 

 

 

 

0 Likes
Message 4 of 6

Anonymous
Not applicable

Sorry, I'm not aware of any way for achieving that. Good luck!

Message 5 of 6

mhannonQ65N2
Collaborator
Collaborator

If you really want to know what (if any) text is displayed at the end of a displayed value (e.g. 21.34 mm, 11 m/s), you can call UnitFormatUtils.Format and look at the end of the string it returns.

Message 6 of 6

rschmittUHALU
Explorer
Explorer

@waleed.hany you can get the FormatOptions for each SpecTypeId (unit types like distance or volume) with this code

Units units = doc.GetUnits();
FormatOptions options = units.GetFormatOptions(SpecTypeId.Distance);
options.Accuracy;
options.RoundingMethod;
options.SupresssTrailingZeros; 
...

but i dont see a way to get the unit annotation like "mm" or "in"

0 Likes