Python AddParameter method question for Revit2023

Python AddParameter method question for Revit2023

f_cat
Participant Participant
386 Views
2 Replies
Message 1 of 3

Python AddParameter method question for Revit2023

f_cat
Participant
Participant

Hello, 

 

My question is very similar to this post but could not solve my problem.

https://forums.autodesk.com/t5/revit-api-forum/how-to-use-forgetypeid-to-add-family-parameters-to-a-...

 

To add material parameter as family type parameter, here is my python code for Revit2020;

 

material_param = family_doc.FamilyManager.AddParameter("material_name",DB.BuiltInParameterGroup.PG_MATERIALS, DB.ParameterType.Material, False)

 

And I arranged it for 2023  but error occurs is this;

 

materialgroupTypeId = GroupTypeId.Materials

familyCategory= Category.GetBuiltInCategoryTypeId(BuiltInCategory.OST_Materials)

material_param = fam_doc.FamilyManager.AddParameter("material_name_string", materialgroupTypeId, familyCategory, False)

 

The error message came out when the code run is this;

 

Runtime error (ArgumentException): Not a spec
Parameter name: specTypeId

 

I created it based on the method

AddParameter(String, BuiltInParameterGroup, Category, Boolean)

 

however, should I be using

AddParameter(String, ForgeTypeId, ForgeTypeId, Boolean)

instead?

 

Would anyone be able to offer some advice?

 

Kato

0 Likes
Accepted solutions (1)
387 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

For FamilyManager.AddParameter(String, ForgeTypeId, ForgeTypeId, Boolean)

 

Use SpecTypeId.Reference.Material for spec arg. (2nd ForgeTypeId).

 

And GroupTypeId.Materials (or some other group) for Group arg. (1st ForgeTypeId).

 

The overload you was trying to use is for controlling type of nested family.

0 Likes
Message 3 of 3

f_cat
Participant
Participant

Thank you RPTHOMAS108,

 

Now I understand the construction of the method.

You saved my life!!!

 

Have a goood day!

 

0 Likes