Conversion from internal to Revit type for UnitType

Conversion from internal to Revit type for UnitType

alexandru.marin2MMTV
Explorer Explorer
1,565 Views
3 Replies
Message 1 of 4

Conversion from internal to Revit type for UnitType

alexandru.marin2MMTV
Explorer
Explorer

Hello!

 

I need to upgrade an application to be supported on Revit 2022 and I have a problem with UnitType that is no longer available in Autodesk.Revit.DB. 

I have a conversion method:

 

public static Autodesk.Revit.DB.UnitType ToRevit(this Model.UnitType unitType)
		{
			if (Enum.IsDefined(typeof(Autodesk.Revit.DB.UnitType), (int)unitType))
				return (Autodesk.Revit.DB.UnitType)unitType;
			else
				return Autodesk.Revit.DB.UnitType.UT_Undefined;
		}

 where the  Model.UnitType is an internal created enum that contains the following:

public enum UnitType
	{
		Unknown = -2,
		Length = 0,
		Angle = 3,
		Mass = 98
	}

 

Does someone have an idea of how I can update the method using ForgeTypeId that is used now in Revit 2022?

 

Thank You!

0 Likes
1,566 Views
3 Replies
Replies (3)
Message 2 of 4

jeremy_tammik
Alumni
Alumni

I believe this has already been discussed here in the forum. Can you please search for "unittype forgetypeid" and see whether you immediately find the threads I am thinking of? I tried it myself and it works for me.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes
Message 3 of 4

alexandru.marin2MMTV
Explorer
Explorer

Hello Jeremy!

I already did this but I couldn't find a solution that worked for my problem and this is why I created this post with the specific issue in hope that maybe someone could give a hint.

 

Thank you for your response.

0 Likes
Message 4 of 4

jeremy_tammik
Alumni
Alumni

Ok.

  

Well, as you say, the problem is that Autodesk.Revit.DB.UnitType no longer exists in the Revit 2022 API.

  

Depending on how you are using the return value of your method, you may be able to rewrite it to return a ForgeTypeId instead.

 

Take a look at 

 

https://thebuildingcoder.typepad.com/blog/2021/04/pdf-export-forgetypeid-and-multi-target-add-in.htm...

 

It says: 

 

"For context, the ForgeTypeId properties directly in the SpecTypeId class identify the measurable data types, like SpecTypeId.Length or SpecTypeId.Mass. "

 

That is a quote from one of the forum discussions I pointed out.

  

That looks like a very good match with your Model.UnitType definition.

   

I think it will be easy to convert your method to use the appropriateForgeTypeId or SpecTypeId values.

 

However, as said, you will have to modify the places where the return value is use accordingly as well.

  

 

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes