Revit 2021 DisplayUnitType

Revit 2021 DisplayUnitType

stephen_harrison
Advocate Advocate
3,888 Views
8 Replies
Message 1 of 9

Revit 2021 DisplayUnitType

stephen_harrison
Advocate
Advocate

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.

0 Likes
Accepted solutions (1)
3,889 Views
8 Replies
Replies (8)
Message 2 of 9

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 3 of 9

stephen_harrison
Advocate
Advocate

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?

 

 

0 Likes
Message 4 of 9

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 5 of 9

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 6 of 9

stephen_harrison
Advocate
Advocate

Thanks Jeremy

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

 

Regards

Stephen

0 Likes
Message 7 of 9

stephen_harrison
Advocate
Advocate
Accepted solution

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

0 Likes
Message 8 of 9

jeremytammik
Autodesk
Autodesk

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

0 Likes
Message 9 of 9

jeremytammik
Autodesk
Autodesk

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

0 Likes