示例#1
0
        private static bool RegisterSheetUpdater(Document doc, ref SheetManagerConfiguration config)
        {
            bool registered = false;

            try
            {
                Guid         updaterGuid  = Guid.NewGuid();
                SheetUpdater sheetUpdater = new SheetUpdater(addinId, updaterGuid, config);
                sheetUpdater.CollectCustomSheetParamIds(doc);
                sheetUpdater.CollectIdMaps(doc);

                UpdaterRegistry.RegisterUpdater(sheetUpdater, doc);

                ElementClassFilter sheetFilter = new ElementClassFilter(typeof(ViewSheet));
                UpdaterRegistry.AddTrigger(sheetUpdater.GetUpdaterId(), sheetFilter, Element.GetChangeTypeElementAddition());
                UpdaterRegistry.AddTrigger(sheetUpdater.GetUpdaterId(), sheetFilter, Element.GetChangeTypeElementDeletion());
                foreach (ElementId paramId in sheetUpdater.SheetParameters.Keys)
                {
                    UpdaterRegistry.AddTrigger(sheetUpdater.GetUpdaterId(), sheetFilter, Element.GetChangeTypeParameter(paramId));
                }

                if (!sheetUpdaters.ContainsKey(config.ModelId))
                {
                    sheetUpdaters.Add(config.ModelId, sheetUpdater);
                }

                registered = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to register sheet updater.\n" + ex.Message, "Register Sheet Updater", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(registered);
        }
示例#2
0
        private static bool RegisterRevisionUpdater(Document doc, ref SheetManagerConfiguration config)
        {
            bool registered = false;

            try
            {
                Guid            updaterGuid     = Guid.NewGuid();
                RevisionUpdater revisionUpdater = new RevisionUpdater(addinId, updaterGuid, config);
                revisionUpdater.CollectIdMaps(doc);

                UpdaterRegistry.RegisterUpdater(revisionUpdater, doc);

                ElementCategoryFilter revisionFilter = new ElementCategoryFilter(BuiltInCategory.OST_Revisions);
                UpdaterRegistry.AddTrigger(revisionUpdater.GetUpdaterId(), revisionFilter, Element.GetChangeTypeElementAddition());
                UpdaterRegistry.AddTrigger(revisionUpdater.GetUpdaterId(), revisionFilter, Element.GetChangeTypeElementDeletion());
                foreach (ElementId paramId in revisionUpdater.RevisionParameters.Keys)
                {
                    UpdaterRegistry.AddTrigger(revisionUpdater.GetUpdaterId(), revisionFilter, Element.GetChangeTypeParameter(paramId));
                }

                if (!revisionUpdaters.ContainsKey(config.ModelId))
                {
                    revisionUpdaters.Add(config.ModelId, revisionUpdater);
                }
                registered = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to register revision updater.\n" + ex.Message, "Register Revision Updater", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(registered);
        }
示例#3
0
        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;
            }
        }
示例#4
0
        public static bool RegisterUpdaters(Document doc, SheetManagerConfiguration config)
        {
            bool registered = false;

            try
            {
                bool sheetUpdaterRegistered    = false;
                bool revisionUpdaterRegistered = false;

                if (File.Exists(config.DatabaseFile))
                {
                    IList <UpdaterInfo> registeredUpdaters = UpdaterRegistry.GetRegisteredUpdaterInfos(doc);
                    var sheetUpdaterFound = from updater in registeredUpdaters where updater.UpdaterName == "SheetDBUpdater" select updater;
                    if (sheetUpdaterFound.Count() == 0)
                    {
                        sheetUpdaterRegistered = RegisterSheetUpdater(doc, ref config);
                    }

                    var revisionUpdaterFound = from updater in registeredUpdaters where updater.UpdaterName == "RevisionDBUpdater" select updater;
                    if (revisionUpdaterFound.Count() == 0)
                    {
                        revisionUpdaterRegistered = RegisterRevisionUpdater(doc, ref config);
                    }
                }
                if (sheetUpdaterRegistered && revisionUpdaterRegistered)
                {
                    registered = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to register updaters.\n" + ex.Message, "Register Updaters", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(registered);
        }
        public SettingWindow(Document doc, SheetManagerConfiguration config)
        {
            m_doc         = doc;
            configuration = config;

            InitializeComponent();
            DisplayItems();
        }
示例#6
0
        public static bool UnregisterUpdaters(Document doc, SheetManagerConfiguration config)
        {
            bool unregistered = false;

            try
            {
                IList <UpdaterInfo> registeredUpdaters = UpdaterRegistry.GetRegisteredUpdaterInfos(doc);
                var sheetUpdaterInfo = from updater in registeredUpdaters where updater.UpdaterName == "SheetDBUpdater" select updater;
                if (sheetUpdaterInfo.Count() > 0)
                {
                    foreach (UpdaterInfo info in sheetUpdaterInfo)
                    {
                        string    addInfo   = info.AdditionalInformation;
                        Guid      guid      = new Guid(addInfo);
                        UpdaterId updaterId = new UpdaterId(addinId, guid);
                        if (UpdaterRegistry.IsUpdaterRegistered(updaterId, doc))
                        {
                            if (sheetUpdaters.ContainsKey(config.ModelId))
                            {
                                sheetUpdaters[config.ModelId].CloseDataManager();
                                sheetUpdaters.Remove(config.ModelId);
                            }
                            UpdaterRegistry.UnregisterUpdater(updaterId, doc);
                            unregistered = true;
                        }
                    }
                }

                var revisionUpdaterInfo = from updater in registeredUpdaters where updater.UpdaterName == "RevisionDBUpdater" select updater;
                if (revisionUpdaterInfo.Count() == 0)
                {
                    foreach (UpdaterInfo info in revisionUpdaterInfo)
                    {
                        string    addInfo   = info.AdditionalInformation;
                        Guid      guid      = new Guid(addInfo);
                        UpdaterId updaterId = new UpdaterId(addinId, guid);
                        if (UpdaterRegistry.IsUpdaterRegistered(updaterId, doc))
                        {
                            if (revisionUpdaters.ContainsKey(config.ModelId))
                            {
                                revisionUpdaters[config.ModelId].CloseDataManager();
                                revisionUpdaters.Remove(config.ModelId);
                            }
                            UpdaterRegistry.UnregisterUpdater(updaterId, doc);

                            unregistered = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to unregister updaters.\n" + ex.Message, "Unregister Updaters", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(unregistered);
        }
示例#7
0
        public RevisionUpdater(AddInId addInId, Guid updaterGuid, SheetManagerConfiguration config)
        {
            m_appId         = addInId;
            m_updaterId     = new UpdaterId(m_appId, updaterGuid);
            linkedProjectId = config.ModelId;
            configuration   = config;

            dataManager = new UpdaterDataManager(configuration.DatabaseFile);
            CollectRevisionParamIds();
        }
示例#8
0
        public SheetUpdater(AddInId addInId, Guid updaterGuid, SheetManagerConfiguration config)
        {
            m_appId         = addInId;
            m_updaterId     = new UpdaterId(m_appId, updaterGuid);
            linkedProjectId = config.ModelId;
            configuration   = config;

            dataManager        = new UpdaterDataManager(configuration.DatabaseFile);
            rvtSheetParameters = dataManager.GetSheetParameters();

            //update project id
            CollectSheetParamIds();
        }
        public static bool StoreConfiguration(Document doc, SheetManagerConfiguration config)
        {
            bool stored = false;

            try
            {
                if (null == configSchema)
                {
                    configSchema = CreateConfigSchema();
                }

                if (null != configSchema)
                {
                    DataStorage savedStorage = GetStorage(doc, configSchema);
                    if (null == savedStorage)
                    {
                        savedStorage = DataStorage.Create(doc);
                    }
                    if (null != savedStorage)
                    {
                        using (Transaction trans = new Transaction(doc))
                        {
                            trans.Start("Store Storage");
                            try
                            {
                                Entity entity = new Entity(configSchemaId);
                                entity.Set <Guid>(s_ModelId, config.ModelId);
                                entity.Set <string>(s_CentralPath, config.CentralPath);
                                entity.Set <ElementId>(s_TitleBlcokId, config.TitleblockId);
                                entity.Set <bool>(s_IsPlaceHolder, config.IsPlaceholder);
                                entity.Set <string>(s_DatabaseFile, config.DatabaseFile);
                                entity.Set <bool>(s_AutoUpdate, config.AutoUpdate);
                                savedStorage.SetEntity(entity);
                                trans.Commit();
                            }
                            catch (Exception ex)
                            {
                                trans.RollBack();
                                string message = ex.Message;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to sotre configuration.\n" + ex.Message, "Store Configuration", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(stored);
        }
示例#10
0
        public static SheetManagerConfiguration GetConfiguration(Document doc)
        {
            SheetManagerConfiguration config = new SheetManagerConfiguration();

            try
            {
                if (null == configSchema)
                {
                    configSchema = CreateConfigSchema();
                }

                if (null != configSchema)
                {
                    IList <DataStorage> savedStorage = GetStorage(doc, configSchema);
                    if (savedStorage.Count > 0)
                    {
                        DataStorage storage = savedStorage.First();
                        Entity      entity  = storage.GetEntity(configSchema);
                        config.ModelId       = entity.Get <Guid>(configSchema.GetField(s_ModelId));
                        config.CentralPath   = entity.Get <string>(configSchema.GetField(s_CentralPath));
                        config.TitleblockId  = entity.Get <ElementId>(configSchema.GetField(s_TitleBlcokId));
                        config.IsPlaceholder = entity.Get <bool>(configSchema.GetField(s_IsPlaceHolder));
                        config.DatabaseFile  = entity.Get <string>(configSchema.GetField(s_DatabaseFile));
                        config.AutoUpdate    = entity.Get <bool>(configSchema.GetField(s_AutoUpdate));
                    }
                    else
                    {
                        config.ModelId     = Guid.NewGuid();
                        config.CentralPath = GetCentralFilePath(doc);

                        //default title block
                        FilteredElementCollector collector  = new FilteredElementCollector(doc);
                        List <ElementId>         elementIds = collector.OfCategory(BuiltInCategory.OST_TitleBlocks).WhereElementIsElementType().ToElementIds().ToList();
                        if (elementIds.Count > 0)
                        {
                            config.TitleblockId = elementIds.First();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to get the information of sheet settings.\n" + ex.Message, "Get Sheet Settings", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(config);
        }
示例#11
0
 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);
     }
 }
示例#12
0
        public void ShowWindow(UIApplication uiapp)
        {
            try
            {
                if (mainWindow != null)
                {
                    return;
                }

                var doc         = uiapp.ActiveUIDocument.Document;
                var centralPath = RevitUtil.GetCentralFilePath(doc);
                SheetManagerConfiguration config;
                if (configDictionary.ContainsKey(centralPath))
                {
                    config = configDictionary[centralPath];
                }
                else
                {
                    config = new SheetManagerConfiguration(doc);
                    configDictionary.Add(config.CentralPath, config);
                }

                var viewModel = new AddInViewModel(config)
                {
                    Handler = new SheetManagerHandler(uiapp)
                };
                viewModel.ExtEvent = ExternalEvent.Create(viewModel.Handler);

                SheetUpdater.IsSheetManagerOn    = true;
                RevisionUpdater.IsSheetManagerOn = true;

                mainWindow = new MainWindow
                {
                    DataContext = viewModel
                };
                mainWindow.Closed += WindowClosed;
                mainWindow.Show();
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }
示例#13
0
 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);
     }
 }
示例#14
0
        public void DocumentOpened(object sender, DocumentOpenedEventArgs args)
        {
            try
            {
                var doc = args.Document;
                if (null == doc)
                {
                    return;
                }

                var sheetConfig = new SheetManagerConfiguration(doc);
                if (doc.IsWorkshared)
                {
                    if (!ServerUtilities.GetByCentralPath(sheetConfig.CentralPath, "configurations/centralpath",
                                                          out Configuration configFound))
                    {
                        return;
                    }
                    if (null != configFound)
                    {
                        foreach (var updater in configFound.Updaters)
                        {
                            if (updater.UpdaterName != "Sheet Tracker")
                            {
                                continue;
                            }

                            sheetConfig.AutoUpdate   = updater.IsUpdaterOn;
                            sheetConfig.DatabaseFile = configFound.SheetDatabase;
                            break;
                        }
                    }
                }

                if (sheetConfig.AutoUpdate && !string.IsNullOrEmpty(sheetConfig.DatabaseFile))
                {
                    if (File.Exists(sheetConfig.DatabaseFile))
                    {
                        //update project info
                        var dbManager    = new UpdaterDataManager(sheetConfig.DatabaseFile);
                        var projects     = dbManager.GetLinkedProjects();
                        var projectFound = projects.Where(x => x.FilePath == sheetConfig.CentralPath).ToList();
                        if (projectFound.Any())
                        {
                            var linkedProject = projectFound.First();
                            sheetConfig.ModelId = linkedProject.Id;
                        }
                        else
                        {
                            var dbOpened = SheetDataWriter.OpenDatabase(sheetConfig.DatabaseFile);
                            if (dbOpened)
                            {
                                var linkedProject = new LinkedProject(sheetConfig.ModelId)
                                {
                                    FilePath      = sheetConfig.CentralPath,
                                    ProjectNumber = doc.ProjectInformation.Number,
                                    ProjectName   = doc.ProjectInformation.Name,
                                    LinkedBy      = Environment.UserName,
                                    LinkedDate    = DateTime.Now
                                };
                                SheetDataWriter.ChangeLinkedProject(linkedProject, CommandType.INSERT);
                                SheetDataWriter.CloseDatabse();
                            }
                        }

                        UpdaterUtil.RegisterUpdaters(doc, sheetConfig);
                    }
                }

                if (!configDictionary.ContainsKey(sheetConfig.CentralPath))
                {
                    configDictionary.Add(sheetConfig.CentralPath, sheetConfig);
                }
            }
            catch (Exception ex)
            {
                Log.AppendLog(LogMessageType.EXCEPTION, ex.Message);
            }
        }