Beispiel #1
0
        LoadReturnCode IGuest.OnCheckIn(ref string errorMessage)
        {
            string message = null;

            try
            {
                if (!LoadComponents())
                {
                    message = "Failed to load Revit Grasshopper components.";
                }
            }
            catch (Exception e)
            {
                message = e.Message;
            }

            if (!(message is null))
            {
                errorMessage = message;
                return(LoadReturnCode.ErrorShowDialog);
            }

            // Register PreviewServer
            previewServer = new PreviewServer();
            previewServer.Register();

            Revit.DocumentChanged      += OnDocumentChanged;
            Revit.ApplicationUI.Idling += OnIdle;

            return(LoadReturnCode.Success);
        }
Beispiel #2
0
        void IGuest.OnCheckOut()
        {
            Revit.DocumentChanged -= OnDocumentChanged;

            // Unregister PreviewServer
            previewServer?.Unregister();
            previewServer = null;
        }
Beispiel #3
0
        void IGuest.OnCheckOut()
        {
            Revit.ApplicationUI.Idling -= OnIdle;
            Revit.DocumentChanged      -= OnDocumentChanged;

            // Unregister PreviewServer
            previewServer?.Unregister();
            previewServer = null;
        }
        LoadReturnCode IGuest.OnCheckIn(ref string errorMessage)
        {
            string message = null;

            try
            {
                if (!LoadStartupAssemblies())
                {
                    message = "Failed to load Revit Grasshopper components.";
                }
            }
            catch (FileNotFoundException e) { message = $"{e.Message}{Environment.NewLine}{e.FileName}"; }
            catch (Exception e)             { message = e.Message; }

            if (!(message is null))
            {
                errorMessage = message;
                return(LoadReturnCode.ErrorShowDialog);
            }

            // Register PreviewServer
            previewServer = new PreviewServer();
            previewServer.Register();

            Revit.DocumentChanged += OnDocumentChanged;

            External.ActivationGate.Enter += ActivationGate_Enter;
            External.ActivationGate.Exit  += ActivationGate_Exit;

            RhinoDoc.BeginOpenDocument += BeginOpenDocument;
            RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate;

            Instances.CanvasCreatedEventHandler Canvas_Created = default;
            Instances.CanvasCreated += Canvas_Created = (canvas) =>
            {
                Instances.CanvasCreated            -= Canvas_Created;
                Instances.DocumentEditor.Activated += DocumentEditor_Activated;
                canvas.DocumentChanged             += ActiveCanvas_DocumentChanged;
            };

            Instances.CanvasDestroyedEventHandler Canvas_Destroyed = default;
            Instances.CanvasDestroyed += Canvas_Destroyed = (canvas) =>
            {
                Instances.CanvasDestroyed          -= Canvas_Destroyed;
                canvas.DocumentChanged             -= ActiveCanvas_DocumentChanged;
                Instances.DocumentEditor.Activated -= DocumentEditor_Activated;
            };

            Instances.DocumentServer.DocumentAdded += DocumentServer_DocumentAdded;

            return(LoadReturnCode.Success);
        }
Beispiel #5
0
        public Result OnStartup(UIControlledApplication applicationUI)
        {
            ApplicationUI = applicationUI;

#if REVIT_2019
            MainWindowHandle = ApplicationUI.MainWindowHandle;
#else
            MainWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
#endif

            // Load Rhino
            try
            {
                var schemeName = ApplicationUI.ControlledApplication.VersionName.Replace(' ', '-');
                rhinoCore = new RhinoCore(new string[] { $"/scheme={schemeName}", "/nosplash" }, WindowStyle.Hidden, MainWindowHandle);
            }
            catch (Exception e)
            {
                Debug.Fail(e.Source, e.Message);
                return(Result.Failed);
            }

            // Reset document units
            UI.RhinoCommand.ResetDocumentUnits(Rhino.RhinoDoc.ActiveDoc);

            // Register UI on Revit
            {
                var ribbonPanel = ApplicationUI.CreateRibbonPanel("Rhinoceros");

                UI.RhinoCommand.CreateUI(ribbonPanel);
                UI.GrasshopperCommand.CreateUI(ribbonPanel);
                UI.PythonCommand.CreateUI(ribbonPanel);
                ribbonPanel.AddSeparator();
                Samples.Sample1.CreateUI(ribbonPanel);
                Samples.Sample4.CreateUI(ribbonPanel);
                Samples.Sample6.CreateUI(ribbonPanel);
                ribbonPanel.AddSeparator();
                UI.HelpCommand.CreateUI(ribbonPanel);
            }

            // Register some events
            ApplicationUI.Idling += OnIdle;
            ApplicationUI.ControlledApplication.DocumentChanged += OnDocumentChanged;

            // Register GrasshopperPreviewServer
            grasshopperPreviewServer = new GH.PreviewServer();
            grasshopperPreviewServer.Register();

            return(Result.Succeeded);
        }
Beispiel #6
0
        void IGuest.OnCheckOut()
        {
            RhinoDoc.EndOpenDocumentInitialViewUpdate -= EndOpenDocumentInitialViewUpdate;
            RhinoDoc.BeginOpenDocument -= BeginOpenDocument;

            External.ActivationGate.Exit  -= ModalScope_Exit;
            External.ActivationGate.Enter -= ModalScope_Enter;

            Revit.DocumentChanged -= OnDocumentChanged;

            // Unregister PreviewServer
            previewServer?.Unregister();
            previewServer = null;
        }
Beispiel #7
0
        LoadReturnCode IGuest.OnCheckIn(ref string errorMessage)
        {
            if (!LoadComponents())
            {
                errorMessage = "Failed to load Revit Grasshopper components.";
                return(LoadReturnCode.ErrorShowDialog);
            }

            // Register PreviewServer
            previewServer = new PreviewServer();
            previewServer.Register();

            Revit.DocumentChanged += OnDocumentChanged;

            return(LoadReturnCode.Success);
        }
Beispiel #8
0
        public Result OnShutdown(UIControlledApplication applicationUI)
        {
            // Unregister GrasshopperPreviewServer
            grasshopperPreviewServer?.Unregister();
            grasshopperPreviewServer = null;

            // Unregister some events
            ApplicationUI.ControlledApplication.DocumentChanged -= OnDocumentChanged;
            ApplicationUI.Idling -= OnIdle;

            // Unload Rhino
            try
            {
                rhinoCore.Dispose();
            }
            catch (Exception e)
            {
                Debug.Fail(e.Source, e.Message);
                return(Result.Failed);
            }

            ApplicationUI = null;
            return(Result.Succeeded);
        }