public RoomUpdaterWindow(UIApplication app) { m_app = app; m_doc = m_app.ActiveUIDocument.Document; InitializeComponent(); this.Title = "Room Updater v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); projectParameters = GetProjectParameters(); DisplayCategories(); parameterMapList = RoomUpdaterDataStorageUtil.GetParameterMaps(m_doc); if (parameterMapList.Count > 0) { dataGridParamMap.ItemsSource = parameterMapList; } }
private void buttonApply_Click(object sender, RoutedEventArgs e) { try { if (parameterMapList.Count > 0) { errorMessages = new StringBuilder(); statusLable.Text = "Writing parameters values..."; progressBar.Visibility = System.Windows.Visibility.Visible; UpdateProgressBarDelegate updatePbDelegate = new UpdateProgressBarDelegate(progressBar.SetValue); using (TransactionGroup group = new TransactionGroup(m_doc)) { group.Start("Write Revit Elements Parameters"); foreach (ParameterMapProperties pmp in parameterMapList) { List <SpatialElementProperties> spatialElementsList = FindSpatialElements(pmp, (bool)checkBoxLink.IsChecked); progressBar.Minimum = 0; progressBar.Maximum = spatialElementsList.Count; progressBar.Value = 0; double value = 0; foreach (SpatialElementProperties sep in spatialElementsList) { value++; List <Element> revitElements = FindRevitElements(pmp, sep); if (revitElements.Count > 0) { bool written = WriteParameter(pmp, sep, revitElements); } Dispatcher.Invoke(updatePbDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, value }); } } if (groupExist) { MessageBox.Show("Elements in groups were skipped and prameter values were not written.", "Groups Exist", MessageBoxButton.OK, MessageBoxImage.Information); } group.Assimilate(); } bool saved = RoomUpdaterDataStorageUtil.StoreParameterMaps(m_doc, parameterMapList); statusLable.Text = "Completed."; progressBar.Visibility = System.Windows.Visibility.Hidden; if (!string.IsNullOrEmpty(errorMessages.ToString())) { RoomUpdaterErrorWindow errorWindow = new RoomUpdaterErrorWindow(errorMessages.ToString()); if (errorWindow.ShowDialog() == true) { errorMessages = new StringBuilder(); } } } } catch (Exception ex) { MessageBox.Show("Failed to apply parameters maps.\n" + ex.Message, "Apply Parameter Maps", MessageBoxButton.OK, MessageBoxImage.Warning); statusLable.Text = ""; } }