private void buttonCreateByList_Click(object sender, RoutedEventArgs e) { try { if (SetToolSettings()) { List <RoomElevationProperties> selectedRooms = new List <RoomElevationProperties>(); List <TreeviewModel> treeviewModels = treeViewRoom.ItemsSource as List <TreeviewModel>; foreach (TreeviewModel roomNode in treeviewModels) { if (roomNode.IsChecked == true) { if (null != roomNode.RoomProperties) { RoomElevationProperties rep = roomNode.RoomProperties; selectedRooms.Add(rep); } } } if (selectedRooms.Count > 0) { progressBar.Visibility = System.Windows.Visibility.Visible; statusLable.Visibility = System.Windows.Visibility.Visible; statusLable.Text = "Creating Elevation Views . . ."; progressBar.Minimum = 0; progressBar.Maximum = selectedRooms.Count; progressBar.Value = 0; double value = 0; UpdateProgressBarDelegate updatePdDelegate = new UpdateProgressBarDelegate(progressBar.SetValue); foreach (RoomElevationProperties rep in selectedRooms) { ElevationCreator creator = new ElevationCreator(m_app, rep, toolSettings, linkedDocuments); if (creator.CheckExisting()) { if (creator.CreateElevationByList()) { RoomElevationProperties roomProperties = new RoomElevationProperties(creator.RoomProperties); if (roomDictionary.ContainsKey(roomProperties.RoomId)) { roomDictionary.Remove(roomProperties.RoomId); } roomDictionary.Add(roomProperties.RoomId, roomProperties); } } value += 1; Dispatcher.Invoke(updatePdDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, value }); } statusLable.Text = "Ready"; progressBar.Visibility = System.Windows.Visibility.Hidden; treeViewRoom.ItemsSource = null; treeViewRoom.ItemsSource = TreeviewModel.SetTreeView(roomDictionary, toolSettings.IsLinkedRoom); if (LogMessageBuilder.GetLogMessages().Length > 0) { LogMessageBox logMessageBox = new LogMessageBox(); logMessageBox.Show(); } } } } catch (Exception ex) { MessageBox.Show("Failed to start creating elevation views by rooms lists.\n" + ex.Message, "Elevation Creator: CreateByRoomList", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void SelectRoomAndWall(bool hostRoom, bool hostWall) { try { Reference selectedRoom = null; Room roomElement = null; XYZ pickPoint = null; if (hostRoom) { selectedRoom = uidoc.Selection.PickObject(ObjectType.Element, new RoomElementFilter(), "Select a room from the host model to create an elevation view."); if (null != selectedRoom) { roomElement = m_doc.GetElement(selectedRoom.ElementId) as Room; } } else { selectedRoom = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Select a room from linked models to create an elevation view."); if (null != selectedRoom) { foreach (LinkedInstanceProperties lip in linkedDocuments.Values) { Element element = lip.LinkedDocument.GetElement(selectedRoom.LinkedElementId); if (null != element) { roomElement = element as Room; break; } } } } if (null != selectedRoom) { pickPoint = uidoc.Selection.PickPoint("Pick a point to locate the elevation mark."); if (null != pickPoint) { Reference selectedWall = null; Wall wallElement = null; if (hostWall) { selectedWall = uidoc.Selection.PickObject(ObjectType.Element, new WallSelectionFilter(), "Select a wall from the host model to rotate an elevation view perpendicular to the wall."); if (null != selectedWall) { wallElement = m_doc.GetElement(selectedWall.ElementId) as Wall; } } else { selectedWall = uidoc.Selection.PickObject(ObjectType.LinkedElement, "Select a wall from linked models to rotate an elevation view perpendicular to the wall."); if (null != selectedWall) { foreach (LinkedInstanceProperties lip in linkedDocuments.Values) { Element element = lip.LinkedDocument.GetElement(selectedWall.LinkedElementId); if (null != element) { wallElement = element as Wall; break; } } } } if (null != roomElement && null != wallElement && null != pickPoint) { int roomId = roomElement.Id.IntegerValue; RoomElevationProperties rep = null; if (roomDictionary.ContainsKey(roomId)) { rep = roomDictionary[roomId]; } else { rep = new RoomElevationProperties(roomElement); } ElevationCreator elevationCreator = new ElevationCreator(m_app, rep, wallElement, toolSettings, linkedDocuments); elevationCreator.PickPoint = pickPoint; if (elevationCreator.CreateElevationByWall()) { MessageBoxResult dr = MessageBox.Show("Would you like to continue to select a room and a wall for the elevation view?", "Select a Room and a Wall", MessageBoxButton.YesNo, MessageBoxImage.Question); if (dr == MessageBoxResult.Yes) { SelectRoomAndWall(hostRoom, hostWall); } } } } } } catch (Exception ex) { MessageBox.Show("Errors occured while selecting rooms and walls.\n" + ex.Message, "Select Rooms and Walls", MessageBoxButton.OK, MessageBoxImage.Warning); } }