public void ShowWindow(UIApplication uiapp) { try { if (mainWindow == null) { Document doc = uiapp.ActiveUIDocument.Document; SheetManagerConfiguration config = DataStorageUtil.GetConfiguration(doc); AddInViewModel viewModel = new AddInViewModel(config); viewModel.Handler = new SheetManagerHandler(uiapp); viewModel.ExtEvent = ExternalEvent.Create(viewModel.Handler); SheetUpdater.IsSheetManagerOn = true; RevisionUpdater.IsSheetManagerOn = true; mainWindow = new MainWindow(); mainWindow.DataContext = viewModel; mainWindow.Closed += WindowClosed; mainWindow.Show(); } } catch (Exception ex) { string message = ex.Message; } }
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_app = commandData.Application; m_doc = m_app.ActiveUIDocument.Document; UserWindow userWindow = new UserWindow(); if ((bool)userWindow.ShowDialog()) { string projectFileId = DataStorageUtil.GetProjectFileId(m_doc).ToString(); if (AppCommand.Instance.Configurations.ContainsKey(projectFileId)) { DTMConfigurations config = AppCommand.Instance.Configurations[projectFileId]; AdminViewModel viewModel = new AdminViewModel(config); AdminWindow adminWindow = new AdminWindow(); adminWindow.DataContext = viewModel; if ((bool)adminWindow.ShowDialog()) { config = adminWindow.ViewModel.Configuration; AppCommand.Instance.Configurations.Remove(projectFileId); AppCommand.Instance.Configurations.Add(projectFileId, config); AppCommand.Instance.ApplyConfiguration(m_doc, config); } } } } catch (Exception ex) { string exMessage = ex.Message; MessageBox.Show("Failed to execute Admin Command.\n" + ex.Message, "Admin Command", MessageBoxButton.OK, MessageBoxImage.Warning); } return(Result.Succeeded); }
private void DisplayDocuments() { try { if (m_mode == ModelManagerMode.ProjectReplication) { comboBoxSource.ItemsSource = modelInfoDictionary.Values; comboBoxSource.DisplayMemberPath = "DocTitle"; comboBoxSource.SelectedIndex = 0; comboBoxRecipient.ItemsSource = modelInfoDictionary.Values; comboBoxRecipient.DisplayMemberPath = "DocTitle"; string docId = DataStorageUtil.ReadSettings(m_doc).RevitDocumentId; if (!string.IsNullOrEmpty(docId)) { comboBoxRecipient.SelectedItem = modelInfoDictionary[docId]; if (comboBoxRecipient.SelectedIndex == comboBoxSource.SelectedIndex && comboBoxSource.Items.Count > 1) { comboBoxSource.SelectedIndex = 1; } } } } catch (Exception ex) { MessageBox.Show("Failed to display the lists of documents.\n" + ex.Message, "Display Documents", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void StoreToolSettings() { using (var trans = new Transaction(ActiveDoc)) { trans.Start("Store Settings"); try { DataStorageUtil.UpdateLinkedDatabase(ActiveDoc, DatabaseFile); trans.Commit(); } catch (Exception) { trans.RollBack(); } } }
public void DocumentClosing(object sender, DocumentClosingEventArgs args) { try { Document doc = args.Document; if (null != doc) { //unregister updater SheetManagerConfiguration config = DataStorageUtil.GetConfiguration(doc); bool unregistered = UpdaterUtil.UnregisterUpdaters(doc, config); } } catch (Exception ex) { MessageBox.Show("Failed to unregister updater.\n" + ex.Message, "Sheet Manager : Unregister Updater", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void Execute(UpdaterData data) { try { Document doc = data.GetDocument(); Guid docId = DataStorageUtil.GetProjectFileId(doc); List <ElementId> addedElementIds = data.GetAddedElementIds().ToList(); foreach (ElementId id in addedElementIds) { Element element = doc.GetElement(id); if (null != element) { AddCategoryCache(docId, element); } } List <ElementId> modifiedElementIds = data.GetModifiedElementIds().ToList(); foreach (ElementId id in modifiedElementIds) { Element element = doc.GetElement(id); if (null != element) { RunCategoryActionItems(docId, data, element); } } List <ElementId> deletedElementIds = data.GetDeletedElementIds().ToList(); foreach (ElementId id in deletedElementIds) { //Process Failure var infoFound = from info in reportingElements where info.DocId == docId && info.ReportingElementId == id select info; if (infoFound.Count() > 0) { ReportFailure(infoFound.First()); } } } catch (Exception ex) { string message = ex.Message; MessageBox.Show("Failed to execute updater.\n" + ex.Message, "DTM Updater", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public MainWindow(ExternalEvent exEvent, BCFHandler handler) { m_event = exEvent; m_handler = handler; viewModel = new WindowViewModel(m_event, m_handler); DataContext = viewModel; //get database file string databaseFile = DataStorageUtil.ReadLinkedDatabase(m_handler.ActiveDoc); if (!string.IsNullOrEmpty(databaseFile)) { if (File.Exists(databaseFile)) { bool opened = viewModel.BCFView.OpenDatabase(databaseFile); } } InitializeComponent(); this.Title = "SmartBCF AddIn v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); }
public void UnregisterDTMUpdaterOnClose(object source, DocumentClosingEventArgs args) { try { if (null != args.Document) { Document doc = args.Document; dtmUpdater.Unregister(doc); Guid projectFileId = DataStorageUtil.GetProjectFileId(doc); if (configurations.ContainsKey(projectFileId.ToString())) { configurations.Remove(projectFileId.ToString()); } } } catch (Exception ex) { string message = ex.Message; MessageBox.Show("Failed to unregister on close.\n" + ex.Message, "Unregister DTM Updater", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_app = commandData.Application; m_doc = m_app.ActiveUIDocument.Document; KeynotePanel keynoteWindow = new KeynotePanel(); KeynoteConfiguration configuration = DataStorageUtil.GetConfiguration(m_doc); configuration.ProjectId = "4b5dcbfe-c438-4fb8-a9f9-cbc7537e8fc9"; configuration.KeynoteSetId = "02234469-3d3d-44f3-9aea-0eb1a5d286f7"; keynoteWindow.DataContext = new KeynoteViewModel(m_app, configuration); if ((bool)keynoteWindow.ShowDialog()) { } } catch (Exception ex) { message = ex.Message; } return(Result.Succeeded); }
public void DocumentOpened(object sender, DocumentOpenedEventArgs args) { try { Document doc = args.Document; if (null != doc) { SheetManagerConfiguration config = DataStorageUtil.GetConfiguration(doc); if (config.AutoUpdate && !string.IsNullOrEmpty(config.DatabaseFile)) { if (File.Exists(config.DatabaseFile)) { //register updater bool registered = UpdaterUtil.RegisterUpdaters(doc, config); } } } } catch (Exception ex) { MessageBox.Show("Failed to trigger the document opened event.\n" + ex.Message, "Document Opened Event", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private DTMConfigurations GetConfiguration(Document doc) { DTMConfigurations config = new DTMConfigurations(); try { string projectFileId = DataStorageUtil.GetProjectFileId(doc).ToString(); string centralPath = FileInfoUtil.GetCentralFilePath(doc); if (projectFileId == Guid.Empty.ToString()) { //first time use List <ProjectFile> items = ServerUtil.GetProjectFiles("centralpath/" + centralPath); if (items.Count > 0) { //import file info by central path ProjectFile projectFile = items.First(); bool found = ServerUtil.GetConfiguration(projectFile._id, out config); projectFileId = projectFile._id; } else { //create file info projectFileId = Guid.NewGuid().ToString(); Project projectInfo = FileInfoUtil.GetProjectInfo(centralPath); List <Project> projects = ServerUtil.GetProjects(""); var projectFound = from p in projects where p.ProjectNumber == projectInfo.ProjectNumber && p.ProjectName == projectInfo.ProjectName select p; if (projectFound.Count() > 0) { projectInfo = projectFound.First(); } else { projectInfo._id = Guid.NewGuid().ToString(); } ProjectFile pFile = new ProjectFile(projectFileId, centralPath, projectInfo._id, projectInfo); config.ProjectFileInfo = pFile; ProjectUpdater pUpdater = new ProjectUpdater(Guid.NewGuid().ToString(), DTMUpdater.updaterGuid.ToString(), dtmUpdater.GetUpdaterName(), addInGuid.ToString(), addInName, false, pFile._id); foreach (string categoryName in updaterCategories) { CategoryTrigger catTrigger = new CategoryTrigger(Guid.NewGuid().ToString(), categoryName, pUpdater._id, false, Environment.UserName, DateTime.Now); pUpdater.CategoryTriggers.Add(catTrigger); } config.ProjectUpdaters.Add(pUpdater); string content = ""; string errMsg = ""; HttpStatusCode status = ServerUtil.PostConfiguration(out content, out errMsg, config); } bool stored = DataStorageUtil.StoreProjectFileId(doc, new Guid(projectFileId)); } else { bool found = ServerUtil.GetConfiguration(projectFileId, out config); } } catch (Exception ex) { string message = ex.Message; MessageBox.Show("Failed to get configuration.\n" + ex.Message, "Get Configuration from Database", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return(config); }
internal void RefreshTriggers(Document doc, ProjectUpdater pUpdater) { try { Guid docId = DataStorageUtil.GetProjectFileId(doc); UpdaterRegistry.RemoveDocumentTriggers(updaterId, doc); var elementsToDelete = from eInfo in reportingElements where eInfo.DocId == docId select eInfo; if (elementsToDelete.Count() > 0) { List <ReportingElementInfo> elementsInfo = elementsToDelete.ToList(); foreach (ReportingElementInfo eInfo in elementsInfo) { reportingElements.Remove(eInfo); } } foreach (CategoryTrigger trigger in pUpdater.CategoryTriggers) { if (trigger.IsEnabled) { ElementCategoryFilter catFilter = new ElementCategoryFilter(catDictionary[trigger.CategoryName]); UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeAny()); if (trigger.CategoryName == "Grids") { GridUtils.CollectGridExtents(doc, docId); if (GridUtils.gridParameters.ContainsKey(docId)) { foreach (ElementId paramId in GridUtils.gridParameters[docId]) { UpdaterRegistry.AddTrigger(updaterId, catFilter, Element.GetChangeTypeParameter(paramId)); } } FilteredElementCollector collector = new FilteredElementCollector(doc); List <Element> elements = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList(); foreach (Element element in elements) { ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, element.Id, element.UniqueId); reportingElements.Add(reportingInfo); } } else if (trigger.CategoryName == "Views") { FilteredElementCollector collector = new FilteredElementCollector(doc); List <View> views = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().Cast <View>().ToList(); var viewTemplates = from view in views where view.IsTemplate select view; if (viewTemplates.Count() > 0) { foreach (Element view in viewTemplates) { ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, view.Id, view.UniqueId); reportingElements.Add(reportingInfo); } } } else { FilteredElementCollector collector = new FilteredElementCollector(doc); List <Element> elements = collector.WherePasses(catFilter).WhereElementIsNotElementType().ToElements().ToList(); foreach (Element element in elements) { ReportingElementInfo reportingInfo = new ReportingElementInfo(docId, trigger._id, trigger.CategoryName, element.Id, element.UniqueId); reportingElements.Add(reportingInfo); } } } } if (registeredUpdaters.ContainsKey(docId)) { registeredUpdaters.Remove(docId); } registeredUpdaters.Add(docId, pUpdater); } catch (Exception ex) { string message = ex.Message; MessageBox.Show("Failed to refresh triggers\n" + ex.Message, "DTM Updater", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void Execute(UIApplication app) { try { m_doc = app.ActiveUIDocument.Document; switch (Request.Take()) { case RequestId.None: return; case RequestId.ReadLinkedFileInfo: break; case RequestId.UpdateLinkedFileInfo: bool updated = DataStorageUtil.UpdateLinkedBCFFileInfo(m_doc, bcfFileDictionary); Dictionary <string, Dictionary <string, IssueEntry> > dictionary = new Dictionary <string, Dictionary <string, IssueEntry> >(); int numCat = categoryNames.Count; AbortFlag.SetAbortFlag(false); progressWindow = new ProgressWindow("Loading BCF issues and images..."); progressWindow.Show(); foreach (string markupId in bcfFileDictionary.Keys) { LinkedBcfFileInfo bcfInfo = bcfFileDictionary[markupId]; if (bcfDictionary.ContainsKey(markupId)) { dictionary.Add(markupId, bcfDictionary[markupId]); } else { Dictionary <string, IssueEntry> issueDictionary = GetBCFIssueInfo(m_doc, bcfInfo); if (issueDictionary.Count > 0) { dictionary.Add(markupId, issueDictionary); } } } if (progressWindow.IsActive) { progressWindow.Close(); } bcfDictionary = dictionary; if (numCat != categoryNames.Count) { System.IO.MemoryStream stream = BCFParser.CreateCategoryStream(categoryNames); if (null != stream) { Google.Apis.Drive.v2.Data.File file = FileManager.UpdateSpreadsheet(stream, categorySheetId, bcfProjectId); } List <BuiltInCategory> bltCategories = catDictionary.Values.ToList(); bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories); foreach (string catName in categoryNames) { var catFound = from category in categoryInfoList where category.CategoryName == catName select category; if (catFound.Count() == 0) { CategoryInfo catInfo = new CategoryInfo(catName, true); categoryInfoList.Add(catInfo); } } } if (null != walkerWindow) { walkerWindow.BCFFileDictionary = bcfFileDictionary; walkerWindow.BCFDictionary = bcfDictionary; walkerWindow.CategoryInfoList = categoryInfoList; walkerWindow.CurrentIndex = 0; walkerWindow.DisplayLinkedBCF(); } bool updatedId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false); if (null != walkerWindow) { walkerWindow.SchemeInfo = schemeInfo; walkerWindow.DisplayColorscheme(schemeInfo); } break; case RequestId.ReadProjectId: bcfProjectId = ParameterUtil.GetBCFProjectId(app); break; case RequestId.UpdateProjectId: bool updatedProjectId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); break; case RequestId.ReadBCFParameterInfo: break; case RequestId.UpdateBCFParameterInfo: bool updatedParameters = ParameterUtil.UpdateBCFParameters(m_doc, currentElement, selectedIssue, selectedComment); break; case RequestId.UpdateAction: bool actionUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Action, currentElement.Action); break; case RequestId.UpdateResponsibility: bool responsibilityUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Responsibility, currentElement.ResponsibleParty); break; case RequestId.CreateIssue: break; case RequestId.UpdateViews: IsolateElement(isIsolateOn, m_doc); CreateSectionBox(isSectionBoxOn, m_doc); HighlightElement(isHighlightOn, m_doc); break; case RequestId.UpdateParameterByComment: UpdateParameters(m_doc); break; } } catch (Exception ex) { MessageBox.Show("Failed to execute an external event.\n" + ex.Message, "Execute Event", MessageBoxButton.OK, MessageBoxImage.Warning); } return; }
public WalkerHandler(UIApplication uiapp) { try { m_app = uiapp; m_doc = uiapp.ActiveUIDocument.Document; View3D view3d = m_doc.ActiveView as View3D; if (null != view3d) { activeView = view3d; } else { FilteredElementCollector collector = new FilteredElementCollector(m_doc); List <View3D> view3ds = collector.OfClass(typeof(View3D)).ToElements().Cast <View3D>().ToList(); var viewfound = from view in view3ds where view.IsTemplate == false && view.IsPerspective == false && view.ViewName == "{3D}" select view; if (viewfound.Count() > 0) { activeView = viewfound.First(); using (Transaction trans = new Transaction(m_doc, "Open 3D View")) { try { trans.Start(); uiapp.ActiveUIDocument.ActiveView = activeView; trans.Commit(); } catch { trans.RollBack(); } } } } bcfProjectId = ParameterUtil.GetBCFProjectId(m_app); if (!string.IsNullOrEmpty(bcfProjectId)) { googleFolders = FileManager.FindGoogleFolders(bcfProjectId); if (null != googleFolders.ColorSheet) { bcfColorSchemeId = googleFolders.ColorSheet.Id; } if (null != googleFolders.CategorySheet) { categorySheetId = googleFolders.CategorySheet.Id; } if (!string.IsNullOrEmpty(bcfColorSchemeId) && !string.IsNullOrEmpty(categorySheetId)) { schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false); } bcfFileDictionary = DataStorageUtil.ReadLinkedBCFFileInfo(m_doc, bcfProjectId); bcfDictionary = GetBCFDictionary(m_doc); List <BuiltInCategory> bltCategories = catDictionary.Values.ToList(); bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories); foreach (string catName in categoryNames) { CategoryInfo catInfo = new CategoryInfo(catName, true); categoryInfoList.Add(catInfo); } } else { MessageBox.Show("Please enter a BCF Project Id in Project Information.", "Empty BCF Project Id", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to initialize External Event handler.\n" + ex.Message, "External Event Handler", MessageBoxButton.OK, MessageBoxImage.Warning); } }