Collect Rooms in Linked Docs in Active View

Collect Rooms in Linked Docs in Active View

redhotbim
Explorer Explorer
5,446 Views
4 Replies
Message 1 of 5

Collect Rooms in Linked Docs in Active View

redhotbim
Explorer
Explorer

 

        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);
                viewElementCollector.WhereElementIsNotElementType();
                viewElementCollector.WherePasses(roomFilter);
                riv.AddRange(viewElementCollector.ToElements());
            }
            return riv;
        }

 

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

http://forums.autodesk.com/t5/revit-api/viewid-is-not-a-view-filteredelementcollector-on-rooms/td-p/...

 

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

Thanks..

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

jeremytammik
Autodesk
Autodesk
Accepted solution

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):

 

http://forums.autodesk.com/t5/revit-api/hide-elements-in-linked-file/td-p/5777305

 

Now you may ask:

 

What criterion?

 

Hah.

 

You tell me, please.

 

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

 

http://forums.autodesk.com/t5/revit-api/viewid-is-not-a-view-filteredelementcollector-on-rooms/td-p/...

 

Good luck!

 

Happy weekend to all.

 

Cheers,

 

Jeremy



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

Message 3 of 5

redhotbim
Explorer
Explorer

Thank you very much Jeremy!

 

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

 

http://youtu.be/GrjgbDcgy6M

0 Likes
Message 4 of 5

amrshaalan
Participant
Participant

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,

Amr, 

0 Likes
Message 5 of 5

jeremytammik
Autodesk
Autodesk

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:

 

http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-FEF0ED40-8658-4C69-934D-7F83FB5D5B63

 

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

 



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