Hello,
I am writing an add-in that will collect family parameter data within a Family Document. I have come to a challenge that I cannot yet solve. When creating family parameters, the user can select <family type>. They are then prompted to select a "Category" to assign with the parameter. (i.e. Type of Parameter becomes "Family type: Structural Connections").
While reading all family parameters, I can get the ParameterType as "FamilyType", but I cannot determine a method to get the assigned Category. I have checked Revit Lookup and Visual Studio extensively.
Thank you for any insights you can offer.
Solved! Go to Solution.
Solved by GJennings-BM. Go to Solution.
Hello, here you go:
https://www.revitapidocs.com/2023/1c008d27-9e61-362c-308c-8b718ee0f8df.htm
Thank you @Songohu_85 for the link. I had to take a different approach, but it all works perfectly now.
Below is the code and I hope it helps others in the community.
After collecting all of the family parameters, I did the following lines of code to get the selected instance Category of the parameter type "FamilyType":
// where "fp" is the family parameter
string familyParameterName = fp.Definition.Name;
FamilyParameter familyTypeParameter = familyManager.get_Parameter(familyParameterName);
ElementId familyTypeElementId = familyManager.CurrentType.AsElementId(familyTypeParameter);
Element familyTypeElement = familyDocument.GetElement(familyTypeElementId);
Category category = familyTypeElement.Category;
string categoryName = category?.Name ?? "N/A";
As you can see it is very straight forward and not convoluted at all! 🤔
Hi GJennings-BM,
Good your solution works!
If family parameter is of "family type: category" then you can directly get BuiltInCategory from ForgeTypeId so I'd do it this way:
FamilyManager fmgr = Document.FamilyManager;
foreach (FamilyParameter fp in fmgr.Parameters)
{
ForgeTypeId ftid = fp.Definition.GetDataType();
if(Category.IsBuiltInCategory(ftid))
{
BuiltInCategory category = Category.GetBuiltInCategory(ftid);
TaskDialog.Show("Info", Enum.GetName(typeof(BuiltInCategory), category));
}
}
Can't find what you're looking for? Ask the community or share your knowledge.