retrieve model objects from document

retrieve model objects from document

Anonymous
Not applicable
2,416 Views
9 Replies
Message 1 of 10

retrieve model objects from document

Anonymous
Not applicable

Hi, I am trying to write an add-in which can go through all the model objects and analytical model objects and validate their names. Here the "model objects" and "analytical model objects" corresponds to the categorization that revit does in its Object Style Control Panel as follows: 

QQ图片20190424194703.png
 
I am wondering if there's a quick way to select these elements. 
 
Best wishes.
0 Likes
2,417 Views
9 Replies
Replies (9)
Message 2 of 10

Anonymous
Not applicable

Hi, Please use CategoryType Property of Category Class (as parameter to pass FilteredElementCollector) where you can loop through enumeration values:

http://www.revitapidocs.com/2015/eb96f224-a134-50e6-57e8-32bcb13bee7d.htm

 

 

0 Likes
Message 3 of 10

recepagah12
Advocate
Advocate

What you want to access is simply, Revit Model Element Categories. Also, what do you mean validate their names?

You can simply access all elements of a category with Filtered Element Collector. Can you explain more accurately and clearly what you want to achieve. So, the advice will be more pinpoint.

 

I hope this helps,

Recep.

0 Likes
Message 4 of 10

Anonymous
Not applicable

thank you sir. Actually the goal is very simple: according to the project requirement, every physical element of the model should have a ruled name system, and my mission is to find if there is any element that do not obey the rule. Thus the most important thing is to iterate throughout all physical elements of the model.  

0 Likes
Message 5 of 10

jeremytammik
Autodesk
Autodesk

The Building Coder lists a number of approaches to select all model elements or visible 3D elements in the FilteredElementCollector topic group:

 

https://thebuildingcoder.typepad.com/blog/about-the-author.html#5.9

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 6 of 10

Anonymous
Not applicable

Thank you. I should find out my answer in your website.

0 Likes
Message 7 of 10

Anonymous
Not applicable

Hi I just tried to filter out the elements using code snippets as follows:

 

IList<Element> GetAllElements(Document doc)
            {
              
                FilteredElementCollector ElementCollector = new FilteredElementCollector(doc);
                IEnumerable<Element> ElementsCollection =
                    ElementCollector.WhereElementIsNotElementType().WhereElementIsViewIndependent();
                    
                IList <Element> AllModelElements = new List<Element>();

                foreach (Element e in ElementsCollection)
                {

                    if ((null != e.Category)
                    && (null != e.LevelId)
                    && (null != e.get_Geometry(new Options()))
                    )
                    {
                        if (e.Category.CategoryType == CategoryType.Model)
                        {
                            AllModelElements.Add(e);
                        }
                        
                    }
                }
                return AllModelElements;
            }

most of the results are what I want, which belong to the CategoryType.Model. However, the results contain a category named "Legend Components".  According to the code, I am quite sure that this "legend components" belong to CategoryType.Model. But from the Visibility/Graphical panel in revit I can't find this category in model categories. I doubt if there are any other categories like this one which should be excluded from my results, and what filter should I use to exclude these categories.

0 Likes
Message 8 of 10

Anonymous
Not applicable

not sure whether this will solve your problem entirely, but if your question is to exclude some BuiltInCategory you can use:

ElementCollector = new FilteredElementCollector(doc).Excluding(new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_LegendComponents).ToElementIds()).ToElements();

 

0 Likes
Message 9 of 10

Anonymous
Not applicable

thank you. this method surely could solve this issue. but what I am concerned is that this method only exclude the legend component. the critical question is exactly which categories the categoryType.Model include. I thought it only includes the model objects however it has more categories than that. 

0 Likes
Message 10 of 10

Anonymous
Not applicable

Hi, I just tried this method and strangely, when I use the exclude filter, I got none rather  than a collection of legend components:

 

QQ图片20190428094337.pngQQ截图20190428094359.png
0 Likes