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);
        }
Esempio n. 2
0
        public PreviewServer()
        {
            Instances.CanvasCreatedEventHandler CanvasCreated = default;
            Instances.CanvasCreated += CanvasCreated = (canvas) =>
            {
                Instances.CanvasCreated -= CanvasCreated;
                canvas.DocumentChanged  += ActiveCanvas_DocumentChanged;
            };

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