How to use ForgeTypeId to add family parameters to a family in Revit API 2023?

How to use ForgeTypeId to add family parameters to a family in Revit API 2023?

jay.lei
Participant Participant
1,546 Views
2 Replies
Message 1 of 3

How to use ForgeTypeId to add family parameters to a family in Revit API 2023?

jay.lei
Participant
Participant

Hi! I am updating add-in codes for Revit 2021 to Revit 2023.  I found that the function that I used for adding a family parameter with a given name in Revit 2021 was removed in Revit 2023.

 

In the codes for Revit 2021, I used "AddParameter(String, BuiltInParameterGroup, ParameterType, Boolean)".  This function worked well, but was removed from Revit API 2023.  

 

In the codes for Revit 2023, it seems that I have to use "AddParameter(String, ForgeTypeId, ForgeTypeId, Boolean)".  What ForgeTypeIds should I use in this function for adding a family parameter?

 

Below is my codes for Revit API 2021.  thanks!

Document familyDoc = doc.EditFamily(loadedFamily);
FamilyManager familyMgr = familyDoc.FamilyManager;
using (Transaction tx1 = new Transaction(familyDoc))
{
    try
    {
        tx1.Start("AddCedWorksetToFamily");

        FamilyParameter CedWorksetParameter = familyMgr.AddParameter("CedWorkset", BuiltInParameterGroup.PG_DATA, ParameterType.Text, true);  //An instance parameter
        FamilyParameter CedFamilyTypeParameter = familyMgr.AddParameter("CedFamilyType", BuiltInParameterGroup.PG_DATA, ParameterType.Text, false);  //Not an instance parameter

        FamilyTypeSet familyTypes = familyMgr.Types;
        FamilyTypeSetIterator familyTypesItor = familyTypes.ForwardIterator();
        familyTypesItor.Reset();
        while (familyTypesItor.MoveNext())
        {
            FamilyType familyType = familyTypesItor.Current as FamilyType;
            familyMgr.CurrentType = familyType;
            familyMgr.Set(CedWorksetParameter, "Refrigeration");
            familyMgr.Set(CedFamilyTypeParameter, "Refrigeration");
        }

        tx1.Commit();
    }
    catch (Exception e)
    {
        if (tx1 != null) tx1.RollBack();
        TaskDialog.Show("Loading family", e.Message);
    }
}

 

Accepted solutions (1)
1,547 Views
2 Replies
Replies (2)
Message 2 of 3

RPTHOMAS108
Mentor
Mentor
Accepted solution

You can find out which subset of ForgeTypeId objects to use in the method overload i.e.

 

public FamilyParameter AddParameter(
	string parameterName,
	ForgeTypeId groupTypeId,
	ForgeTypeId specTypeId,
	bool isInstance
)

 

So

GroupTypeId.Data

SpecTypeId.String.Text

Would be equivalent to what you had previously I believe.

 

Message 3 of 3

jay.lei
Participant
Participant

Thanks!  RPTHOMAS108.  I used the "GroupTypeId.Data" and "SpecTypeId.String.Text".  It worked!

0 Likes