Esempio n. 1
0
        public override Result Execute(ExternalCommandData data, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            if
            (
                (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)) &&
                (Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
            )
            {
                return(ShowLoadError(data));
            }

            string rhinoTab = Addin.RhinoVersionInfo?.ProductName ?? "Rhinoceros";

            if (Addin.CurrentStatus == Addin.Status.Ready)
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))
                {
                    return(Rhinoceros.RunCommandAbout());
                }

                if
                (
                    Rhinoceros.MainWindow.Visible ||
                    Rhinoceros.MainWindow.ActivePopup?.IsInvalid == false
                )
                {
                    Rhinoceros.MainWindow.BringToFront();
                    return(Result.Succeeded);
                }

                // If no windows are visible we show the Ribbon tab
                return(data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed);
            }

            var result = Result.Failed;

            switch (result = Revit.OnStartup(Revit.ApplicationUI))
            {
            case Result.Succeeded:
                // Update Rhino button Tooltip
                Button.ToolTip         = $"Restores previously visible Rhino windows on top of Revit window";
                Button.LongDescription = $"Use CTRL key to open a Rhino model";

                // Register UI on Revit
                data.Application.CreateRibbonTab(rhinoTab);

                var RhinocerosPanel = data.Application.CreateRibbonPanel(rhinoTab, "Rhinoceros");
                HelpCommand.CreateUI(RhinocerosPanel);
                RhinocerosPanel.AddSeparator();
                CommandRhino.CreateUI(RhinocerosPanel);
                CommandRhinoPreview.CreateUI(RhinocerosPanel);
                CommandPython.CreateUI(RhinocerosPanel);

                var GrasshopperPanel = data.Application.CreateRibbonPanel(rhinoTab, "Grasshopper");
                CommandGrasshopper.CreateUI(GrasshopperPanel);
                CommandGrasshopperPlayer.CreateUI(GrasshopperPanel);
                CommandGrasshopperPreview.CreateUI(GrasshopperPanel);
                CommandGrasshopperRecompute.CreateUI(GrasshopperPanel);
                CommandGrasshopperBake.CreateUI(GrasshopperPanel);

                var SamplesPanel = data.Application.CreateRibbonPanel(rhinoTab, "Samples");
                Samples.Sample1.CreateUI(SamplesPanel);
                Samples.Sample4.CreateUI(SamplesPanel);
                Samples.Sample8.CreateUI(SamplesPanel);

                result = data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed;
                break;

            case Result.Cancelled:
                Button.Enabled = false;

                if (Addin.CurrentStatus == Addin.Status.Unavailable)
                {
                    Button.ToolTip = "Rhino.Inside failed to found a valid copy of Rhino 7 WIP installed.";
                }
                else if (Addin.CurrentStatus == Addin.Status.Obsolete)
                {
                    Button.ToolTip = "Rhino.Inside has expired.";
                }
                else
                {
                    Button.ToolTip = "Rhino.Inside load was cancelled.";
                }

                Button.SetContextualHelp(new ContextualHelp(ContextualHelpType.Url, @"https://www.rhino3d.com/inside/revit"));
                break;

            case Result.Failed:
                Button.Enabled = false;
                Button.ToolTip = "Rhino.Inside failed to load.";
                ShowLoadError(data);
                break;
            }

            return(result);
        }
Esempio n. 2
0
        public override Result Execute(ExternalCommandData data, ref string message, Autodesk.Revit.DB.ElementSet elements)
        {
            var    result   = Result.Failed;
            string rhinoTab = Addin.RhinoVersionInfo?.ProductName ?? "Rhinoceros";

            if (RhinoCommand.Availability.Available)
            {
                if (Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    return(Rhinoceros.RunCommandAbout());
                }

                using (var modal = new Rhinoceros.ModalScope())
                    result = modal.Run(false, true);

                // If no windows are visible we show the Ribbon tab
                if (result == Result.Cancelled)
                {
                    result = data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed;
                }

                return(result);
            }

            result = Addin.CheckSetup();
            if (result != Result.Succeeded)
            {
                return(result);
            }

            result = Revit.OnStartup(Revit.ApplicationUI);
            if (RhinoCommand.Availability.Available = result == Result.Succeeded)
            {
                // Update Rhino button Tooltip
                Button.ToolTip         = $"Restores previously visible Rhino windows on top of Revit window";
                Button.LongDescription = $"Use CTRL key to open a Rhino model";

                // Register UI on Revit
                data.Application.CreateRibbonTab(rhinoTab);

                var RhinocerosPanel = data.Application.CreateRibbonPanel(rhinoTab, "Rhinoceros");
                HelpCommand.CreateUI(RhinocerosPanel);
                RhinocerosPanel.AddSeparator();
                CommandRhino.CreateUI(RhinocerosPanel);
                CommandPython.CreateUI(RhinocerosPanel);

                var GrasshopperPanel = data.Application.CreateRibbonPanel(rhinoTab, "Grasshopper");
                CommandGrasshopper.CreateUI(GrasshopperPanel);
                CommandGrasshopperPlayer.CreateUI(GrasshopperPanel);
                CommandGrasshopperPreview.CreateUI(GrasshopperPanel);
                CommandGrasshopperRecompute.CreateUI(GrasshopperPanel);
                CommandGrasshopperBake.CreateUI(GrasshopperPanel);

                var SamplesPanel = data.Application.CreateRibbonPanel(rhinoTab, "Samples");
                Samples.Sample1.CreateUI(SamplesPanel);
                Samples.Sample4.CreateUI(SamplesPanel);
                Samples.Sample6.CreateUI(SamplesPanel);
                Samples.Sample8.CreateUI(SamplesPanel);
            }

            if (result == Result.Succeeded)
            {
                // Activate Rhinoceros Tab
                result = data.Application.ActivateRibbonTab(rhinoTab) ? Result.Succeeded : Result.Failed;
            }
            else
            {
                // No more loads in this session
                Button.Enabled = false;
                Button.ToolTip = "Failed to load.";
            }

            return(result);
        }
Esempio n. 3
0
        internal static Result Start(RibbonHandler ribbon)
        {
            var result = Result.Failed;
            var button = RestoreButton(CommandName);

            switch (result = Revit.OnStartup(Revit.ApplicationUI))
            {
            case Result.Succeeded:
                // Update Rhino button Tooltip
                button.ToolTip         = $"Restores previously visible Rhino windows on top of Revit window";
                button.LongDescription = $"Use CTRL key to open a Rhino model";
                // hide the button title
                if (button.GetAdwndRibbonButton() is Autodesk.Windows.RibbonButton adwndRadioButton)
                {
                    adwndRadioButton.ShowText = false;
                }

                var assemblies = AppDomain.CurrentDomain.GetAssemblies();

                // Register UI on Revit
                if (assemblies.Any(x => x.GetName().Name == "RhinoCommon"))
                {
                    rhinoPanel = ribbon.CreateAddinPanel(Addin.RhinoVersionInfo?.ProductName ?? "Rhinoceros");
                    CommandRhino.CreateUI(rhinoPanel);
                    CommandImport.CreateUI(rhinoPanel);
                    CommandToggleRhinoPreview.CreateUI(rhinoPanel);
                    CommandPython.CreateUI(rhinoPanel);
                    CommandRhinoOptions.CreateUI(rhinoPanel);
                }

                if (assemblies.Any(x => x.GetName().Name == "Grasshopper"))
                {
                    grasshopperPanel = ribbon.CreateAddinPanel("Grasshopper");
                    CommandGrasshopper.CreateUI(grasshopperPanel);
                    CommandGrasshopperPreview.CreateUI(grasshopperPanel);
                    CommandGrasshopperSolver.CreateUI(grasshopperPanel);
                    CommandGrasshopperRecompute.CreateUI(grasshopperPanel);
                    CommandGrasshopperBake.CreateUI(grasshopperPanel);
                    grasshopperPanel.AddSeparator();
                    CommandGrasshopperPlayer.CreateUI(grasshopperPanel);
                    grasshopperPanel.AddSlideOut();
                    CommandGrasshopperPackageManager.CreateUI(grasshopperPanel);
                    CommandGrasshopperFolders.CreateUI(grasshopperPanel);

                    // Script Packages UI
                    UpdateScriptPkgUI(ribbon);

                    // setup listeners, and in either case, update the packages ui
                    // listed for changes in installed packages
                    CommandGrasshopperPackageManager.CommandCompleted += CommandGrasshopperPackageManager_CommandCompleted;
                    // listen for changes to user-script paths in options
                    AddinOptions.ScriptLocationsChanged += AddinOptions_ScriptLocationsChanged;
                }

                UpdateRibbonCompact();

                result = Result.Succeeded;
                break;

            case Result.Cancelled:
                button.Enabled = false;

                if (Addin.CurrentStatus == Addin.Status.Unavailable)
                {
                    button.ToolTip = "Rhino.Inside failed to found a valid copy of Rhino 7 WIP installed.";
                }
                else if (Addin.CurrentStatus == Addin.Status.Obsolete)
                {
                    button.ToolTip = "Rhino.Inside has expired.";
                }
                else
                {
                    button.ToolTip = "Rhino.Inside load was cancelled.";
                }

                button.SetContextualHelp(new ContextualHelp(ContextualHelpType.Url, @"https://www.rhino3d.com/inside/revit"));
                break;

            case Result.Failed:
                button.Enabled = false;
                button.ToolTip = "Rhino.Inside failed to load.";
                return(Result.Failed);
            }
            return(result);
        }