Get all elements from linked model.

Get all elements from linked model.

Anonymous
Not applicable
6,522 Views
4 Replies
Message 1 of 5

Get all elements from linked model.

Anonymous
Not applicable

I can get elements of type wall using this code snippet. But I need to get all types of element from link document. Can anyone please help?

 

foreach (Document linkedDoc in uiApp.Application.Documents)
{
                 if (element.Name.Contains(linkedDoc.Title))
                 {

                         FilteredElementCollector linkElementCollector = new FilteredElementCollector(linkedDoc);
                         IList<Element> linkedWalls = linkElementCollector.OfClass(typeof(Wall)).ToElements();     //  <------------------Filter applied here.

                         foreach (Element e in linkElementCollector)
                         {
                         }

                  }

}

Many thanks.

0 Likes
Accepted solutions (1)
6,523 Views
4 Replies
Replies (4)
Message 2 of 5

jeremytammik
Autodesk
Autodesk

You can replace the filter for Wall instances by any other filter of your choice.

 

If you really want to filter for all elements, which is not recommended, you have to apply a little trick.

 

That trick and many related aspects are explained here by The Building Coder:

 

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

 

best regards,

 

Jeremy

 

 

 



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

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thanks you very much and now I realised why it was not recommended to filter all elements because it returns each elements.

But my problem is I want to get elements from linked model and only physical entities available in linked model. Like Wall, floor etc. now the issue, it is not prefixed that how many types of elements available in linked model So I need to implement any generic method which retrieve all physical entities.

Here physical entities mean what I am seeing in linked model.

 

I tried this: 

FilteredElementCollector linkElementCollector = new FilteredElementCollector(linkedDoc, View.Id);

But returns error that viewid is not view.

 

Many thanks.     

0 Likes
Message 4 of 5

jeremytammik
Autodesk
Autodesk
Accepted solution

Filtering for a view only works in the document that owns that view.

 

The Building Coder has discussed the topic of retrieving model elements only numerous times. Look at the entries in the topic group I pointed you to:

 

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

 

Did you look at that at all?

 

Cheers,

 

Jeremy

 



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

Message 5 of 5

Anonymous
Not applicable

Great. Thank you very much @jeremytammik. You are awesome. 

0 Likes