Hi.
I'm trying to get all famalies categories hosted on the current project and then put in on a combo box. I've this code for searching the families on the project, but the code is bring me all the famillies (Categories, Families and Types). My objective is create 3 Combo boxes, 1 for Categories, 1 for Sub Categories and the last for the Types of the families.
List<Family> lstFamily = new List<Family>( new FilteredElementCollector(docM) .OfClass(typeof(Family)) .Cast<Family>() .Where<Family>(f => f.FamilyPlacementType == FamilyPlacementType.OneLevelBased)); FamilyA.DataSource = lstFamily.ToArray(); FamilyA.DisplayMember = "Name";
Do you have other example to how i can get this information.
Tanks
Dear Carlos,
I am confused by your query.
Your code looks to me as if it should return families, just like you want, and not categories and types, like you say it does.
You could implement two other similar filtered element collectors for the categories and types and all should be well.
Cheers,
Jeremy
Hi jeremytammik!
I'm trying to do is the following:
1. That shows the category Family
2. That shows the Sub Category
3. Then, the type of family
What I seek is generally to filter the information of families, first choose the category, then, with the category already selected, showing me in a combo box the sub category and finally the type.
Other problem that I have is in the last Query, the result is 209 categories of families in the proyect buy I have only 49. I don`t know if I need another filter to the query.
Thanks!
Dear Carlos,
Aha. Thank you for the clarification. I understand better now.
Yes, I think that this can be easily solved by using a sequence of nested filtered element collectors.
Once you have the selected category, you can determine all its subcategories using the Category.SubCategories property.
Yes, there may well be 209 categories defined in the project, and only 49 of them actually being used.
You could determine which categories are in use by iterating over all families in the project, optionally removing all the ones that have no instances placed, and asking each family for its category. That should return the 49 in use. Theoretically, at least. In practice, there will certainly be some surprises somewhere 🙂
When you have the category selected, you can filter for all families whose category matches the given one.
The most efficient way to do so is to use a parameter filter:
http://thebuildingcoder.typepad.com/blog/2010/06/parameter-filter.html
http://thebuildingcoder.typepad.com/blog/2010/06/element-name-parameter-filter-correction.html
Cheers,
Jeremy
Hi,
Below is the small function which will help you
Document m_doc;
m_doc = commandData.Application.ActiveUIDocument.Document;
List<Family> lstFamily = new List<Family>(
new FilteredElementCollector(m_doc)
.OfClass(typeof(Family))
.Cast<Family>());
var csv = new StringBuilder();
foreach (Family lFamily in lstFamily)
{
foreach( FamilySymbol sym in lFamily.Symbols)
{
var newLine1 = string.Format("{0},{1},{2},{3}", lFamily.FamilyCategory.Name, lFamily.Name, sym.Name, Environment.NewLine);
csv.Append(newLine1);
}
}
File.WriteAllText("d:\\abcde.txt", csv.ToString());
return Autodesk.Revit.UI.Result.Succeeded;
Regards,
Rajesh
Can't find what you're looking for? Ask the community or share your knowledge.