UnitSymbol.UST_NONE & New Units

UnitSymbol.UST_NONE & New Units

Julian.Wandzilak
Advocate Advocate
586 Views
1 Reply
Message 1 of 2

UnitSymbol.UST_NONE & New Units

Julian.Wandzilak
Advocate
Advocate

Sometime ago I did a Revit API Course on Udemy by Boost Your BIM. Some part of the code were not updated and I had to play with new UnitTypeId. For most of the time it was somehow easy and revit help plus some googling was sufficient. Except setting unit symbol to none. revitApI unit Symbol None.png

 

So I posted below 2 snippets of code:

 

Old way (pre 2022):

 

 

FormatOptions foVolume = units.GetFormatOptions(UnitType.UT_Volume);
foVolume.DisplayUnits = DisplayUnitType.DUT_CUBIC_METERS;
foVolume.UnitSymbol = UnitSymbolType.UST_NONE;

 

 

My brute force way:

 

 

FormatOptions foVolume = units.GetFormatOptions(SpecTypeId.Volume);
foVolume.SetUnitTypeId(UnitTypeId.CubicMeters);
foVolume.SetSymbolTypeId(foVolume.GetValidSymbols()[0]);

 

 

My solution does work, but it doesn't look nice. Is there any better way of doing it?

blog: w7k.pl more about me: Linkedin Profile
My add-ins for Revit: Drafter(180+ scripts) & Leveler
0 Likes
Accepted solutions (1)
587 Views
1 Reply
Reply (1)
Message 2 of 2

mhannonQ65N2
Collaborator
Collaborator
Accepted solution

You can use a ForgeTypeId with an empty string to specify no symbol.

FormatOptions foVolume = units.GetFormatOptions(SpecTypeId.Volume);
foVolume.SetUnitTypeId(UnitTypeId.CubicMeters);
ForgeTypeId emptySymbol = new ForgeTypeId("");
foVolume.SetSymbolTypeId(emptySymbol);