Conversion from Deprecated ParameterType to ForgeTypeId

Conversion from Deprecated ParameterType to ForgeTypeId

stephen_harrison
Advocate Advocate
2,501 Views
6 Replies
Message 1 of 7

Conversion from Deprecated ParameterType to ForgeTypeId

stephen_harrison
Advocate
Advocate

Could somebody please help me out with this conversion from Deprecated ParameterType to ForgeTypeId for Revit 2022 Api? I have read the documentation with the SDK but I am no doubt missing something very obvious

 

The 'old' code snippets I am having difficulty converting are:

ParameterType spParmType = spFamilyListItem.DataType;

ParameterType spFamilyParmType = spFamilyListItem.DataType;

ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(spNameAmend, spFamilyParmType);

ParameterType spParamTypeNoFamily = definition.ParameterType;

DataType = familyParameter.Definition.ParameterType,

if (ParameterType.YesNo == fp.Definition.ParameterType)

What would be the 2022 equivalent for it?

 

It seems like I need to substitute ParameterType for ForgeTypeId and GetDataType() for DataType but this doesn’t work?

 

There must be something very obvious I am overlooking.

Thanks in advance.

0 Likes
Accepted solutions (2)
2,502 Views
6 Replies
Replies (6)
Message 2 of 7

RPTHOMAS108
Mentor
Mentor
Accepted solution

Within the constructor
ExternalDefinitionCreationOptions(String, ForgeTypeId)

 

The ForgeTypeId refers to either:

 

A spec type i.e. Length/Number/YesNo etc.:
e.g. SpecTypeId.Boolean.YesNo

 

or a Category of a Family type parameter:
e.g. Category.GetBuiltInCategoryTypeId

 

To convert from the old ParameterType to ForgeTypeId use:
SpecUtils.GetSpecTypeId(ParameterType)

 

Definition.GetSpecTypeId is obsolete use Definition.GetDataType i.e. I assume the term 'DataType' was introduced as it is more broad covering both spec and family type category.

Message 3 of 7

jeremy_tammik
Alumni
Alumni
Accepted solution

I dealt with all those issues migrating The Building Coder samples and other projects. You should be able to find examples of all required conversions in these posts:

 

 

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

stephen_harrison
Advocate
Advocate

Thank you for the prompt response and explanations.

If I have understood correctly the amendments to my code would look like the following:

 

 

Pre 2022: ParameterType spParmType = spFamilyListItem.DataType;
2022 Code: ForgeTypeId spParmType = spFamilyListItem.DataType;


Pre 2022: ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(string, ParameterType);
2022 Code: ExternalDefinitionCreationOptions option = new ExternalDefinitionCreationOptions(string, ForgeTypeId)


Pre 2022: ParameterType spParamTypeNoFamily = definition.ParameterType;
2022 Code: ForgeTypeId spParamTypeNoFamily = Definition.GetDataType();


Pre 2022: DataType = familyParameter.Definition.ParameterType,
2022 Code: DataType = familyParameter.Definition. GetDataType();


Pre 2022: if (ParameterType.YesNo == fp.Definition.ParameterType)
2022 Code: if (SpecTypeId.Boolean.YesNo == fp.Definition.GetDataType())


Pre 2022:  if (def.ParameterType == ParameterType.FamilyType)
2022 Code:  if (!Category.IsBuiltInCategory(def.GetDataType()))

 

 

 

Again thanks for the assistance.

Message 5 of 7

stephen_harrison
Advocate
Advocate

I have just had an opportunity to try out my solutions and I have clearly missed something as I am getting an error when I run the app in the form off a shared parameter is reporting as a family parameter which leads me to think my error is in the following amended code:

if (!Category.IsBuiltInCategory(def.GetDataType()))

I clearly haven't understood as well as id hoped!!!

0 Likes
Message 6 of 7

RPTHOMAS108
Mentor
Mentor

Don't have enough context to make a judgement e.g. what is: spFamilyListItem etc?

 

Wouldn't assume it is to do with the line you highlighted since a ForgeTypeId either is or isn't representing a built-in category (so logically you would expect that to work either way). Like all things however it may not be anticipating the form of ForgeTypeId you are feeding into it (null etc.).

 

You need to be more descriptive about the line causing the error and what the exact exception message states. There is a process isn't there, you step through and the line that causes the error stands out (throws the exception). Set up a simple example that goes through the process of what you are aiming for and indicates the full context of it. From that I and others will be able to understand what is and isn't being done correctly.

 

None of the above looks that wrong but perhaps you can't use the same approach for all parameter types.

0 Likes
Message 7 of 7

stephen_harrison
Advocate
Advocate

Simple error on my part

if (Category.IsBuiltInCategory(def.GetDataType()))
0 Likes