Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Collect Rooms in Linked Docs in Active View

Message 1 of 5
4291 Views, 4 Replies

Collect Rooms in Linked Docs in Active View


        public static List<Element> RoomsInView(DocumentSet docs, View view)
            List<Element> riv = new List<Element>();
            foreach (Document dc in docs)
                FilteredElementCollector viewElementCollector = new FilteredElementCollector(dc, view.Id);
                ElementCategoryFilter roomFilter = new ElementCategoryFilter(BuiltInCategory.OST_Rooms);
            return riv;


The code above doesn't work because the FilteredElementCollector(doc, viewId) expects the viewId to be from the same document I guess?


Is there a way to collect rooms in Linked Documents that are visible in a view that belongs to the current document? Any workaround?


Message 2 of 5
in reply to: redhotbim

Yes, the filtered element collector definitely expects the view id to be from the same document that the collector is instantiated for.


Yes, of course there is a workaround. There always is. It is just a question of how much effort it takes, and how efficient it turns out to be.


In this case, you can simply collect the rooms from the linked document and add some other criterion to select the ones you want.


Here is an example of instantiating filtered element collectors for all linked documents (I think):


Now you may ask:


What criterion?




You tell me, please.


By the way, here is another example related to filtering for rooms in linked documents:


Good luck!


Happy weekend to all.





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

Message 3 of 5
in reply to: jeremytammik

Thank you very much Jeremy!


I guess I've found my criterion.. DirectShape it is.. I just love it 🙂

Message 4 of 5
in reply to: jeremytammik

Dear mr Tammik,


I had a problem on my desktop computer that i couldn't debug my code in visual studio 2015, <<some said that revit is only compatible with VS 2010, is that right?! >> .Finally I moved to my laptop computer and the debugger was working properly, anyway my code was right except a minor mistake in the GetAllRooms(); function that made my program not to collect anyrooms from the document so the count was 0 and that's why it didn't draw any floors.


I attached my new method for collecting the rooms from the doc and it worked properly.

public List<Room> GetAllRooms(Document document) { FilteredElementCollector roomCollect = new FilteredElementCollector(document); roomCollect.OfCategory(BuiltInCategory.OST_Rooms); Room room = null; foreach (Element elem in roomCollect) { room = elem as Room; if(room != null) { projectRooms.Add(room); } } return projectRooms; }


I would like to thank you for your reply and I hope I can learn a lot from you.


Kind RegardsSmiley Happy,


Message 5 of 5
in reply to: amrshaalan

Dear Amr,


Congratulations on finding and fixing the problem.


Debugging helps, doesn't it?  🙂


To answer your new question, please take a look at the Revit API Developer Guide:


Development Requirements

The Autodesk Revit API requires the Microsoft .NET Framework v4.5. To edit and debug your API applications, you need an interactive development environment such as Microsoft Visual Studio 2012 Professional or one of the MS Visual Studio Express Editions for C# or Visual Basic.NET. (Visual Studio Professional is recommended, as Express editions do not support DLL debugging.) When developing with the Autodesk Revit API, ensure that your project references two DLLs: RevitAPI.dll and RevitAPIUI.dll contained in the Autodesk Revit Program directory.


Merry Xmas and a Happy New Year to you!

Best regards,




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

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups

Rail Community