public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp    = commandData.Application;
            Application   revitApp = uiApp.Application;
            UIDocument    uiDoc    = uiApp.ActiveUIDocument;
            Document      dbDoc    = null;

            if (uiDoc != null)
            {
                dbDoc = uiDoc.Document;
            }

            IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();
            AutoOptionsSettings    aOSettings   = settingsRepo.LoadAutoOptions();

            AutoOptionsConfigWindow configWindow = new AutoOptionsConfigWindow(aOSettings, commandData);
            Boolean?saveChanges = configWindow.ShowDialog();

            if (saveChanges.Value)
            {
                aOSettings.LastUpdate = DateTime.Now;
                settingsRepo.WriteAutoOptions(aOSettings);
                //Access the dispatcher and point it to the new settings
                AutoOptionsDispatcher dispatcher = AutoOptionsDispatcher.Instance;
                dispatcher.SetOptions(aOSettings);
            }

            return(Result.Succeeded);
        }
Пример #2
0
        Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            ////todo: this sets the ResourceAssembly of Revit itself, so it will break other addins that try to set or access the ResourceAssembly
            if (System.Windows.Application.ResourceAssembly == null)
            {
                System.Windows.Application.ResourceAssembly = Assembly.GetExecutingAssembly();
            }

            //Set up tab and panel
            String tabName = "DK";

            try //an exception will be thrown if the tab already exists
            {
                application.CreateRibbonTab(tabName);
            }
            catch (Autodesk.Revit.Exceptions.ArgumentException e)
            {
                //ignore
            }

            //setup the ui on the Ribbon
            PushButtonData AutoOptionsConfigCommandPushButtonData =
                new PushButtonData(
                    "AutoOptionsConfigCommandButton", //name of the button
                    "Auto Options",                   //text on the button
                    FileLocations.AssemblyFullPath,
                    "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommand"
                    );

            AutoOptionsConfigCommandPushButtonData.AvailabilityClassName =
                "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommandAvailability";
            AutoOptionsConfigCommandPushButtonData.LargeImage =
                new BitmapImage(new Uri("pack://application:,,,/resources/ao_large.jpg"));

            RibbonPanel AutoOptionsRibbonPanel = application.CreateRibbonPanel(tabName, "Auto Options");

            AutoOptionsRibbonPanel.AddItem(AutoOptionsConfigCommandPushButtonData);

            //assign the dispatcher object using the singleton instance. The singleton will be initialized at this time
            dispatcher = AutoOptionsDispatcher.Instance;
            //load the settings to use in this session
            IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();

            dispatcher.SetOptions(settingsRepo.LoadAutoOptions());
            //register the event handler
            application.ControlledApplication.FailuresProcessing += dispatcher.AutoOptionsFailureHandler;

            return(Result.Succeeded);
        }
Пример #3
0
        Result IExternalApplication.OnStartup(UIControlledApplication application)
        {
            ////FileLocations.AddInDirectory = application.ControlledApplication.AllUsersAddinsLocation + @"\AutoOptions\";
            //String msg = String.Empty;
            ////todo: this sets the ResourceAssembly of Revit itself, so it will break other addins that try to set or access the ResourceAssembly
            if (System.Windows.Application.ResourceAssembly == null)
            {
                //msg += "Resource Assembly is Null -- Setting\n";
                System.Windows.Application.ResourceAssembly = Assembly.GetExecutingAssembly();
            }
            //msg += "Resource Assembly: " + System.Windows.Application.ResourceAssembly.FullName + "\nExecuting Assembly: " + Assembly.GetExecutingAssembly().FullName + "\n";
            //TaskDialog.Show("AutoOptions", msg);


            //setup the ui on the Ribbon
            PushButtonData AutoOptionsConfigCommandPushButtonData =
                new PushButtonData(
                    "AutoOptionsConfigCommandButton", //name of the button
                    "Auto Options",                   //text on the button
                    FileLocations.AssemblyFullPath,
                    "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommand"
                    );

            AutoOptionsConfigCommandPushButtonData.AvailabilityClassName =
                "DougKlassen.Revit.AutoOptions.Commands.AutoOptionsConfigCommandAvailability";
            AutoOptionsConfigCommandPushButtonData.LargeImage =
                new BitmapImage(new Uri("pack://application:,,,/resources/ao_large.jpg"));

            RibbonPanel AutoOptions2014RibbonPanel = application.CreateRibbonPanel("Auto Options");

            AutoOptions2014RibbonPanel.AddItem(AutoOptionsConfigCommandPushButtonData);

            //assign the dispatcher object using the singleton instance. The singleton will be initialized at this time
            dispatcher = AutoOptionsDispatcher.Instance;
            //load the settings to use in this session
            IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();

            dispatcher.SetOptions(settingsRepo.LoadAutoOptions());
            //register the event handler
            application.ControlledApplication.FailuresProcessing += dispatcher.AutoOptionsFailureHandler;



            return(Result.Succeeded);
        }
        /// <summary>
        /// This is an event handler that responds to a failure according to the current settings
        /// </summary>
        /// <param name="sender">The sending object, i.e. the Revit application</param>
        /// <param name="e">The event arguments</param>
        public void AutoOptionsFailureHandler(Object sender, Autodesk.Revit.DB.Events.FailuresProcessingEventArgs e)
        {
            //don't process if handling is turned off
            if (currentSettings.HandlingActive == false)
            {
                return;
            }

            //update the uiApp reference
            Application RevitApp = sender as Application;

            uiApp = new UIApplication(RevitApp);

            FailuresAccessor fa = e.GetFailuresAccessor();
            //this is the action that will be taken to attempt resolution. Default is to continue the default Revit failure processing
            FailureProcessingResult action = FailureProcessingResult.Continue;

            foreach (FailureMessageAccessor fma in fa.GetFailureMessages())
            {
                AutoFailureHandlingOptions aFOpts = currentSettings.AllFailureOptions
                                                    .Where(x => x.FailureGuid == fma.GetFailureDefinitionId().Guid)
                                                    .FirstOrDefault();

                if (aFOpts != null)
                {
                    //Show the CatchFailures dialog if a failure was caught
                    if (currentSettings.InteractiveModeEnabled)
                    {
                        try
                        {
                            //todo: clone to allow roll-back?
                            FailureCatcherWindow failWin = new FailureCatcherWindow(currentSettings, aFOpts, uiApp);

                            Boolean?result = failWin.ShowDialog();

                            if (result.Value)
                            {
                                //Write changes to the .ini
                                currentSettings.LastUpdate = DateTime.Now;
                                IAutoOptionsRepository settingsRepo = new AutoOptionsConfigFileRepo();
                                settingsRepo.WriteAutoOptions(currentSettings);
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("ex", ex.Message + "\n" + ex.StackTrace);
                            throw;
                        }
                    }

                    FailureResolutionOption selectedResolution = aFOpts.SelectedResolution;
                    if (selectedResolution is AutoOptionsResolution)
                    {
                        try
                        {
                            switch (((AutoOptionsResolution)selectedResolution).Resolution)
                            {
                            case AutoOptionsResolutionType.NoAction:
                                break;

                            case AutoOptionsResolutionType.DeleteAffected:
                                fa.DeleteElements(fma.GetFailingElementIds().ToList());
                                action = FailureProcessingResult.ProceedWithCommit;
                                break;

                            case AutoOptionsResolutionType.CancelTransaction:
                                //todo: not working, being overwritten?
                                action = FailureProcessingResult.ProceedWithRollBack;
                                e.SetProcessingResult(action);
                                fa.RollBackPendingTransaction();
                                return;

                            case AutoOptionsResolutionType.HideWarning:
                                //todo: check if actually is a warning?
                                fa.DeleteWarning(fma);
                                break;

                            default:
                                break;
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Dispatcher", ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                        }
                    }
                    else if (selectedResolution is RevitResolution)
                    {
                        try
                        {
                            FailureResolutionType fRT = ((RevitResolution)selectedResolution).Resolution;

                            if (fma.HasResolutionOfType(fRT))
                            {
                                fma.SetCurrentResolutionType(fRT);
                                fa.ResolveFailure(fma);
                                action = FailureProcessingResult.ProceedWithCommit;
                            }
                            else
                            {
                                TaskDialog.Show("AutoOptions", "The selected automatic resolution \n***" + aFOpts.SelectedResolution.FriendlyCaption + " (" + fRT + ")***\ncan't be used");
                            }
                        }
                        catch (Exception ex)
                        {
                            TaskDialog.Show("Dispatcher", ex.Message + "\n" + ex.Source + "\n" + ex.StackTrace);
                        }
                    }
                }
            }

            e.SetProcessingResult(action);
        }