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.
Solved! Go to Solution.
Solved by stephen_harrison. Go to Solution.
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
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?
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...
Yes indeed:
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...
Thanks Jeremy
Ill keep working on this but look forward to your solution.
Regards
Stephen
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
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...
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
Can't find what you're looking for? Ask the community or share your knowledge.