Message 1 of 6
Not applicable
04-10-2013
02:06 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello,
I posted this before but deleted it because I messed up the code and couldn't edit for some reason. So anyway, my problem is this:
I'm trying to collect all rooms that exist in a specified view, and I'm using a FilteredElementCollector to do so. I'm calling the constructor that takes a ViewID.
Below is the entirety of my function. It fails in the inner loop at the line "FilteredElementCollector collLinked = new FilteredElementCollector(linkedDoc, viewID);". This approach works just fine when collecting family instances by view, but against rooms I get the strange error "viewId is not a view." Any ideas?
Thanks!
public static List<Room> LoadRoomsFromRevitByView(ElementId viewID)
{
List<Room> ReturnRooms = new List<Room>();
FilteredElementCollector collector = new FilteredElementCollector(ProjectInfo.ProjectDocument);
IList<Element> elems = collector.OfCategory(BuiltInCategory.OST_RvtLinks).OfClass(typeof(RevitLinkType)).ToElements();
foreach (Element e in elems)
{
RevitLinkType linkType = e as RevitLinkType;
String s = String.Empty;
foreach (Document linkedDoc in ProjectInfo.ProjectApplication.Documents)
{
if (linkedDoc.Title.Equals(linkType.Name))
{
try
{
FilteredElementCollector collLinked = new FilteredElementCollector(linkedDoc, viewID);
IList<Element> linkedRooms = collLinked.OfClass(typeof(SpatialElement)).ToElements();
foreach (SpatialElement eleRoom in linkedRooms)
{
Room room = eleRoom as Room;
if (room != null)
ReturnRooms.Add(room);
}
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
continue;
}
}
}
}
FilteredElementCollector collRooms = new FilteredElementCollector(ProjectInfo.ProjectDocument, viewID);
IList<Element> mainRooms = collRooms.OfClass(typeof(SpatialElement)).ToElements();
foreach (SpatialElement eleRoom in mainRooms)
{
Room room = eleRoom as Room;
if (room != null)
ReturnRooms.Add(room);
}
return ReturnRooms;
}
Solved! Go to Solution.