コード例 #1
0
        public RhinoCommand()
        {
            if (Revit.OnStartup(Revit.ApplicationUI) != Result.Succeeded)
            {
                Availability.Available = false;
                throw new Exception("Failed to startup Rhino");
            }

            Rhinoceros.UpdateDocumentUnits(Rhino.RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);
        }
コード例 #2
0
        public override sealed void ComputeData()
        {
            Rhinoceros.InvokeInHostContext(() => base.ComputeData());

            if (unhandledException is object)
            {
                unhandledException = default;
                ResetData();
            }
        }
コード例 #3
0
 private static Result Pick <TResult>(out TResult value, Func <TResult> picker)
 {
     using (new External.EditScope())
     {
         value = default;
         try { value = Rhinoceros.InvokeInHostContext(picker); }
         catch (Autodesk.Revit.Exceptions.OperationCanceledException) { return(Result.Cancelled); }
         catch (Exception) { return(Result.Failed); }
         return(Result.Succeeded);
     }
 }
コード例 #4
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));
            }

            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);
                }

                return(Result.Succeeded);
            }

            if (AddinOptions.Current.CompactTab)
            {
                data.Application.CreateRibbonTab(Addin.AddinName);
                data.Application.ActivateRibbonTab(Addin.AddinName);
            }

            var result = Start(new RibbonHandler(data.Application));

            if (result == Result.Failed)
            {
                ShowLoadError(data);
            }

            return(result);
        }
コード例 #5
0
        /// <summary>
        /// Gets the active Graphical <see cref="Autodesk.Revit.DB.View"/> of the provided <see cref="Autodesk.Revit.DB.Document"/>.
        /// </summary>
        /// <param name="doc"></param>
        /// <returns>The active graphical <see cref="Autodesk.Revit.DB.View"/></returns>
        public static View GetActiveGraphicalView(this Document doc)
        {
            using (var uiDocument = new Autodesk.Revit.UI.UIDocument(doc))
            {
                var activeView = uiDocument.ActiveGraphicalView;
                if (activeView is null)
                {
                    var openViews = Rhinoceros.InvokeInHostContext(() => uiDocument.GetOpenUIViews()).
                                    Select(x => doc.GetElement(x.ViewId) as View).
                                    Where(x => x.ViewType.IsGraphicalViewType());

                    activeView = openViews.FirstOrDefault();
                }

                return(activeView);
            }
        }
コード例 #6
0
        public override void PostProcessData()
        {
            base.PostProcessData();

            Rhinoceros.InvokeInHostContext
            (
                () =>
            {
                if (SourceCount == 0)
                {
                    RefreshList(NickName);
                }
                else
                {
                    RefreshList(VolatileData.AllData(true));
                }

                // Show elements sorted
                ListItems.Sort((x, y) => string.CompareOrdinal(x.Name, y.Name));

                //base.CollectVolatileData_Custom();
                m_data.Clear();

                var path = new GH_Path(0);
                if (SelectedItems.Count == 0)
                {
                    m_data.AppendRange(new IGH_Goo[0], path);
                }
                else
                {
                    foreach (var item in SelectedItems)
                    {
                        m_data.Append(item.Value, path);
                    }
                }
            }
            );
        }
コード例 #7
0
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     return(Rhinoceros.RunCommandOptions());
 }
コード例 #8
0
 public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
 {
     return(OnCommandCompleted(
                Rhinoceros.RunCommandPackageManager()
                ));
 }
コード例 #9
0
 public override sealed void ComputeData() =>
 Rhinoceros.InvokeInHostContext(() => base.ComputeData());
コード例 #10
0
 public override Result Execute(ExternalCommandData data, ref string message, DB.ElementSet elements)
 {
     Rhinoceros.RunCommandGHFolder(option: "o");
     return(Result.Succeeded);
 }
コード例 #11
0
 public static string GetFamilyName(this ElementType elementType) => Rhinoceros.InvokeInHostContext(() => elementType.FamilyName);
コード例 #12
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);
        }
コード例 #13
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);
        }
コード例 #14
0
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     Rhinoceros.ShowAsync();
     return(Result.Succeeded);
 }
コード例 #15
0
 public override Result Execute(ExternalCommandData data, ref string message, ElementSet elements)
 {
     Rhinoceros.RunScriptAsync("_EditPythonScript", activate: true);
     return(Result.Succeeded);
 }