public static bool CreateUI(ScriptPkg pkg, RibbonHandler ribbon)
        {
            // --------------------------------------------------------------------
            // FIND SCRIPTS
            // --------------------------------------------------------------------
            var items = pkg.FindLinkedItems();

            // --------------------------------------------------------------------
            // CREATE ASSEMBLY
            // --------------------------------------------------------------------
            // generate assembly containing script command types
            var lsa = new LinkedScriptAssembly();

            // create types for all the scripts in the structure
            ProcessLinkedScripts(items, (script) =>
            {
                script.ScriptCommandType = lsa.MakeScriptCommandType(script);
            });

            // save and load the created assembly
            lsa.SaveAndLoad();

            // --------------------------------------------------------------------
            // CREATE UI
            // --------------------------------------------------------------------
            RibbonPanel panel;

            try { panel = ribbon.CreateAddinPanel(pkg.Name); }
            catch { return(false); }

            // Currently only supporting two levels in the UI:
            // 1) Pushbuttons on panel for every LinkedScript at the root level
            // 2) Pulldowns containing pushbuttons for all the LinkedScripts recursively found under their directory
            // Lets make the pulldowns first so they are first on the panel
            items.OfType <LinkedItemGroup>().ToList().ForEach((group) =>
            {
                var pullDownData = new PulldownButtonData(group.Name, group.Name)
                {
                    Image      = ImageBuilder.LoadRibbonButtonImage("Ribbon.Grasshopper.GhFolder.png", true),
                    LargeImage = ImageBuilder.LoadRibbonButtonImage("Ribbon.Grasshopper.GhFolder.png"),
                    ToolTip    = group.Tooltip,
                };
                if (panel.AddItem(pullDownData) is PulldownButton pulldown)
                {
                    ProcessLinkedScripts(group.Items, (script) =>
                    {
                        AddPullDownButton(pulldown, script, lsa);
                    });
                }
            });
            // now make pushbuttons
            items.OfType <LinkedScript>().ToList().ForEach((script) =>
            {
                AddPanelButton(panel, script, lsa);
            });

            return(true);
        }
Beispiel #2
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);
        }