private void GetModelInfo() { try { foreach (Document doc in m_app.Application.Documents) { if (!string.IsNullOrEmpty(doc.Title) && !doc.IsFamilyDocument) { ModelInfo modelInfo = new ModelInfo(doc); if (!modelInfoDictionary.ContainsKey(modelInfo.RevitDocumentID)) { modelInfo.GoogleSheetID = GoogleDriveUtil.GetGoogleSheetId(modelInfo); if (!string.IsNullOrEmpty(modelInfo.GoogleSheetID)) { verifiedUser = true; modelInfo.LinkInfoCollection = GoogleSheetUtil.GetLinkInfo(modelInfo.GoogleSheetID); } modelInfo.ViewDictionary = GetDraftingViewInfo(doc); modelInfoDictionary.Add(modelInfo.RevitDocumentID, modelInfo); } } } } catch (Exception ex) { MessageBox.Show("Failed to get the model information.\n" + ex.Message, "Get Model Information", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonFix_Click(object sender, RoutedEventArgs e) { try { if (comboBoxSource.SelectedIndex > -1 && comboBoxRecipient.SelectedIndex > -1) { if (m_mode == ModelManagerMode.ProjectReplication) { ViewMapClass viewMapClass = new ViewMapClass((ModelInfo)comboBoxSource.SelectedItem, (ModelInfo)comboBoxRecipient.SelectedItem, (bool)checkBoxCreateLinks.IsChecked); FixLinkWindow fixLinkWindow = new FixLinkWindow(viewMapClass); Nullable <bool> dlResult = fixLinkWindow.ShowDialog(); if (dlResult == true) { progressBar.Visibility = System.Windows.Visibility.Visible; statusLable.Visibility = System.Windows.Visibility.Visible; viewMapClass = fixLinkWindow.FixedViewMap; bool updatedViewDictionary = projectView.FixViewDictionary(viewMapClass); modelInfoDictionary = projectView.ModelInfoDictionary; ModelInfo recipientInfo = modelInfoDictionary[viewMapClass.RecipientInfo.RevitDocumentID]; bool updatedGoogleSheet = GoogleSheetUtil.WriteLinkIfo(recipientInfo.GoogleSheetID, recipientInfo.LinkInfoCollection); bool updatedLinkStatus = projectView.UpdateLinkStatus(recipientInfo); //update google spreadsheet RefreshModelInfo(comboBoxSource.SelectedIndex, comboBoxRecipient.SelectedIndex); progressBar.Visibility = System.Windows.Visibility.Hidden; statusLable.Visibility = System.Windows.Visibility.Hidden; } } } } catch (Exception ex) { MessageBox.Show("Failed to fix links.\n" + ex.Message, "Fix Links", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public bool UpdateDraftingViews(ModelInfo sourceInfo, ModelInfo recipientInfo, TreeView treeViewSource, TreeView treeViewRecipient, bool createSheet, bool createLinks, TextBlock statusLable, ProgressBar progressBar) { bool result = false; try { List <int> sourceViewIds = new List <int>(); List <PreviewMap> previewMapList = new List <PreviewMap>(); ViewMapClass vmc = new ViewMapClass(sourceInfo, recipientInfo, createLinks); Dictionary <int, ViewProperties> sourceViews = vmc.SourceViews; Dictionary <int, ViewProperties> recipientViews = vmc.RecipientViews; List <TreeViewModel> treeviewModels = treeViewSource.ItemsSource as List <TreeViewModel>; foreach (TreeViewModel rootNode in treeviewModels) { foreach (TreeViewModel secondNode in rootNode.Children) { foreach (TreeViewModel viewNode in secondNode.Children) { if (viewNode.IsChecked == true) { int viewId = 0; if (int.TryParse(viewNode.Tag.ToString(), out viewId)) { if (sourceViews.ContainsKey(viewId) && !sourceViewIds.Contains(viewId)) { ViewProperties viewSource = sourceViews[viewId]; if (viewSource.DependantViews.Count > 0) { foreach (int dependentId in viewSource.DependantViews.Keys) { if (!sourceViewIds.Contains(dependentId)) { ViewProperties dependentSource = viewSource.DependantViews[dependentId]; ViewProperties dependentRecipient = null; LinkInfo dependantlinkInfo = new LinkInfo(); if (null != dependentSource.LinkedView) { dependentRecipient = dependentSource.LinkedView; var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == dependentId && info.DestItemId == dependentRecipient.ViewId select info; if (linkInfoList.Count() > 0) { dependantlinkInfo = linkInfoList.First(); } } PreviewMap dependantView = new PreviewMap(); dependantView.SourceModelInfo = sourceInfo; dependantView.RecipientModelInfo = recipientInfo; dependantView.SourceViewProperties = dependentSource; dependantView.RecipientViewProperties = dependentRecipient; dependantView.ViewLinkInfo = dependantlinkInfo; dependantView.IsEnabled = true; sourceViewIds.Add(dependentId); previewMapList.Add(dependantView); } } } ViewProperties viewRecipient = null; LinkInfo linkInfo = new LinkInfo(); if (null != viewSource.LinkedView) { viewRecipient = viewSource.LinkedView; var linkInfoList = from info in vmc.LinkInfoList where info.SourceItemId == viewId && info.DestItemId == viewRecipient.ViewId && info.ItemStatus != LinkItemStatus.Deleted select info; if (linkInfoList.Count() > 0) { linkInfo = linkInfoList.First(); } } PreviewMap preview = new PreviewMap(); preview.SourceModelInfo = sourceInfo; preview.RecipientModelInfo = recipientInfo; preview.SourceViewProperties = viewSource; preview.RecipientViewProperties = viewRecipient; preview.ViewLinkInfo = linkInfo; preview.IsEnabled = true; sourceViewIds.Add(viewId); previewMapList.Add(preview); } } } } } } if (previewMapList.Count > 0) { PreviewWindow pWindow = new PreviewWindow(previewMapList, createSheet); if (true == pWindow.ShowDialog()) { previewMapList = pWindow.PreviewMapList; progressBar.Visibility = System.Windows.Visibility.Visible; statusLable.Visibility = System.Windows.Visibility.Visible; bool updatedDictionary = UpdateRecipientViewDictionary(recipientInfo, previewMapList); bool updatedGoogleSheet = GoogleSheetUtil.WriteLinkIfo(recipientInfo.GoogleSheetID, recipientInfo.LinkInfoCollection); bool updatedLinkStatus = UpdateLinkStatus(recipientInfo); progressBar.Visibility = System.Windows.Visibility.Hidden; statusLable.Visibility = System.Windows.Visibility.Hidden; } } else { MessageBox.Show("Please select at least one source item to duplicate views.", "Select a Source Item", MessageBoxButton.OK, MessageBoxImage.Information); result = false; } result = true; } catch (Exception ex) { MessageBox.Show("Failed to update drafting views.\n" + ex.Message, "Update Drafting Views", MessageBoxButton.OK, MessageBoxImage.Warning); } return(result); }