Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Family Document: Get the "Family Type" parameter selected "Category" Instance

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
GJennings-BM
478 Views, 3 Replies

Family Document: Get the "Family Type" parameter selected "Category" Instance

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.  

3 REPLIES 3
Message 2 of 4
Songohu_85
in reply to: GJennings-BM
Message 3 of 4
GJennings-BM
in reply to: GJennings-BM

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! 🤔

Message 4 of 4
Songohu_85
in reply to: GJennings-BM

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.

Post to forums  

Autodesk Design & Make Report