Announcements

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Get All Parameters from model elements

jazlik
Contributor

Get All Parameters from model elements

jazlik
Contributor
Contributor

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!

0 Likes
Reply
Accepted solutions (1)
320 Views
2 Replies
Replies (2)

caroline.gitonga
Autodesk
Autodesk
Accepted solution

Hi @jazlik

Kindly, have a look at this forum thread as advised by Jeremy on the issue: https://forums.autodesk.com/t5/revit-api-forum/check-if-a-category-contains-any-element/td-p/8759761

Ideally, your approach seems quite right. You my loop through the retrieved list of categories, using FilteredElementCollector  to get the count of elements in each category

Carol Gitonga, Developer Advocacy and Support, ADN Open
0 Likes

jazlik
Contributor
Contributor

Thanks!

I guess I was littering blog with another similar post. Thanks anyway! I will look!

0 Likes