private void buttonRooms_Click(object sender, RoutedEventArgs e) { try { selectedSource = SourceType.Rooms; CollectMassInfo(selectedSource); List <Room> sourceRooms = new List <Room>(); if ((bool)checkBoxSelected.IsChecked) { UIDocument uidoc = m_app.ActiveUIDocument; Selection selection = uidoc.Selection; ICollection <ElementId> selectedIds = selection.GetElementIds(); if (selectedIds.Count > 0) { FilteredElementCollector collector = new FilteredElementCollector(m_doc, selection.GetElementIds()); ElementClassFilter classFilter = new ElementClassFilter(typeof(DirectShape), true); sourceRooms = collector.OfCategory(BuiltInCategory.OST_Rooms).WherePasses(classFilter).ToElements().Cast <Room>().ToList(); if (sourceRooms.Count > 0) { CollectRoomsInfo(sourceRooms, Autodesk.Revit.DB.Transform.Identity); } } } else { if (modelDictionary.Count > 0) { foreach (RevitDocumentProperties rdp in modelDictionary.Values) { FilteredElementCollector collector = new FilteredElementCollector(rdp.DocumentObj); ElementClassFilter classFilter = new ElementClassFilter(typeof(DirectShape), true); List <Room> rooms = collector.OfCategory(BuiltInCategory.OST_Rooms).WherePasses(classFilter).ToElements().Cast <Room>().ToList(); if (rooms.Count > 0) { if (rdp.IsLinked) { foreach (int linkId in rdp.LinkedInstances.Keys) { LinkedInstanceProperties lip = rdp.LinkedInstances[linkId]; CollectRoomsInfo(rooms, lip.TransformValue); } } else { CollectRoomsInfo(rooms, Autodesk.Revit.DB.Transform.Identity); } } } } } if (roomDictionary.Count > 0) { this.DialogResult = true; } else { MessageBox.Show("Rooms don't exist in the current Revit project.", "Empty Rooms", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to gather information of rooms.\n" + ex.Message, "Room Selected", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonFloors_Click(object sender, RoutedEventArgs e) { try { selectedSource = SourceType.Floors; CollectMassInfo(selectedSource); List <Floor> sourceFloors = new List <Floor>(); if ((bool)checkBoxSelected.IsChecked) { UIDocument uidoc = m_app.ActiveUIDocument; Selection selection = uidoc.Selection; ICollection <ElementId> selectedIds = selection.GetElementIds(); if (selectedIds.Count > 0) { FilteredElementCollector collector = new FilteredElementCollector(m_doc, selection.GetElementIds()); sourceFloors = collector.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().Cast <Floor>().ToList(); if (sourceFloors.Count > 0) { CollectFloorsInfo(sourceFloors, Autodesk.Revit.DB.Transform.Identity); // host model only } } } else { if (modelDictionary.Count > 0) { foreach (RevitDocumentProperties rdp in modelDictionary.Values) { FilteredElementCollector collector = new FilteredElementCollector(rdp.DocumentObj); List <Floor> floors = collector.OfCategory(BuiltInCategory.OST_Floors).WhereElementIsNotElementType().Cast <Floor>().ToList(); if (floors.Count > 0) { if (rdp.IsLinked) { foreach (int linkId in rdp.LinkedInstances.Keys) { LinkedInstanceProperties lip = rdp.LinkedInstances[linkId]; CollectFloorsInfo(floors, lip.TransformValue); } } else { CollectFloorsInfo(floors, Autodesk.Revit.DB.Transform.Identity); } } } } } if (floorDictionary.Count > 0) { this.DialogResult = true; } else { MessageBox.Show("Floors don't exist in the current Revit project.", "Empty Floor", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to gather information of floors.\n" + ex.Message, "Floors Selected", MessageBoxButton.OK, MessageBoxImage.Warning); } }