- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey!
I guess this idea was mentioned here a few times, but I quite do not find anything specific for my case.
I would like to find all categories of elements which are "present" in a model. So I would like to find only these categories that have elements instance in a model.
I think I went from backwards as first I get all the categories from the model:
First I wanted to get all categories in a document:
public List<Category> GetAllCategoriesInDocument()
{
Categories categories = Doc.Settings.Categories;
List <Category> listOfCategories = new List<Category>();
foreach (Category category in categories)
{
// Check if the category is valid and can be used in the model
if (category != null && category.AllowsBoundParameters)
{
listOfCategories.Add(category);
}
}
return listOfCategories;
}
Then I wanted to get all parameters from these categories, using first element in model
public List<Parameter> GetAllParametersOfGivenCategoryFromFirstElement(Category category)
{
ElementFilter elementCategoryFilter = new ElementCategoryFilter((BuiltInCategory)category.Id.IntegerValue);
Element element = new FilteredElementCollector(Doc).WherePasses(elementCategoryFilter).ToElements().First();
return (List<Parameter>)element.GetOrderedParameters();
}
It just occured to me that it will not work as not all categories are going to have elements in the model! Surprise 😄
So I followed a few posts here and get to jeremy github(Lab2_2_ModelElements):
https://github.com/jeremytammik/AdnRevitApiLabsXtra/blob/master/XtraCs/Labs2.cs#L506-L686
However, I am not quite sure whether getting all model elements is the correct approach?
Thank you for your help!
Solved! Go to Solution.