Announcements
Due to scheduled maintenance, the Autodesk Community will be inaccessible from 10:00PM PDT on Oct 16th for approximately 1 hour. We appreciate your patience during this time.
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: 

Revit 2021 DisplayUnitType

8 REPLIES 8
SOLVED
Reply
Message 1 of 9
stephen_harrison
3075 Views, 8 Replies

Revit 2021 DisplayUnitType

I hope someone can help but I am struggling to update a section of my code I have been utilising for a few years now but due to it being deprecated in Revit 2021 I need to update it.

I have read the few posts I have found on the subject as well as the Revit SDK Revit Platform API Changes and Additions but I feel as though I am having a senior moment and missing the obvious:

My code snippet is:

 

case StorageType.Double:

double? nullable = t.AsDouble(fp);

if (nullable.HasValue)

{

DisplayUnitType displayUnitType = fp.DisplayUnitType;

value = UnitUtils.ConvertFromInternalUnits(nullable.Value, displayUnitType).ToString();

break;

Note 

t = FamilyType and fp = FamilyParameter

 

Any assistance would be appreciated in order to hopefully put an end to my senior moment!!

Thank you in advance.

8 REPLIES 8
Message 2 of 9

I have heard that expression several times recently... 'senior moment'.

 

I just looked it up, and apparently the first know usage is from 1996:

 

https://www.merriam-webster.com/dictionary/senior%20moment

 

I was not aware of it until just recently...

 

Anyway, maybe this post will help:

 

https://forums.autodesk.com/t5/revit-api-forum/forgetypeid-how-to-use/m-p/9455305

 

Please let us know, and also how you end up migrating your code to eliminate the deprecated API use.

 

Thank you!

 

Cheers

 

Jeremy

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 9

Thank you Jeremy for your prompt response.

You obviously haven't got to that stage in life were senior moments become such a regular occurrence that you start to question how you manage to do anything in the first place!

I regret I have read that post and a few others several times and still cannot see what should be a very obvious solution?

 

 

Message 4 of 9

Not quite, but I'm getting there and working on it.

 

I'll take a look at The Building Coder samples... there may be a similar migration required there...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 9

Yes indeed:

 

https://thebuildingcoder.typepad.com/blog/2020/04/2021-migration-add-in-language-and-bim360-login.ht...

 

https://thebuildingcoder.typepad.com/files/tbc_samples_2021_migr_01.txt

 

CmdDutAbbreviation.cs(37,33,37,48): warning CS0618: 'DisplayUnitType' is obsolete: 'This enumeration is deprecated in Revit 2021 and may be removed in a future version of Revit. Please use the `ForgeTypeId` class instead. Use constant members of the `UnitTypeId` class to replace uses of specific values of this enumeration.'

  

I'll take a look anon...

  



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 9

Thanks Jeremy

Ill keep working on this but look forward to your solution.

 

Regards

Stephen

Message 7 of 9

Senior Moment over, thankfully.

Very embarrassing however how simple the solution was!!

//Pre 2021
                        DisplayUnitType displayUnitType = fp.DisplayUnitType;
                        value = UnitUtils.ConvertFromInternalUnits(nullable.Value, displayUnitType).ToString();
                        //2021
                        ForgeTypeId forgeTypeId = fp.GetUnitTypeId();
                        value = UnitUtils.ConvertFromInternalUnits(nullable.Value, forgeTypeId).ToString();

 

Regards

Stephen

Message 8 of 9

Congratulations on resolving this and thank you for sharing the simple solution.

 

That motivates me to take a look at the deprecated unit API usage warnings generated by The Building Coder samples...

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 9 of 9

I did it the easy way, commenting out everything that looked complicated, and just handling the trivial cases:

 

Eliminated deprecated API usage warnings by removing calls to pre-ForgeTypeId unit functionality:

 

https://github.com/jeremytammik/the_building_coder_samples/compare/2021.0.150.5...2021.0.150.6

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Rail Community


Autodesk Design & Make Report