public void LoadRhino()
 {
     if (rhinoCore == null)
     {
         rhinoCore = new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Hidden);
     }
 }
示例#2
0
        async Task <object> StartRhino(dynamic input)
        {
            // WindowStyle.Hidden: OK, with threaded solution.
            // WindowStyle.Normal: OK, with threaded solution.
            // WindowStyle.NoWindow: OK

            try
            {
                // Start Rhino
                // TODO: use input argument variables here
                //var PATH = Environment.GetEnvironmentVariable("PATH");
                //Environment.SetEnvironmentVariable("PATH", PATH + ";" + rhinoSystemDir);
                rhinoCore = new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Hidden);

                // Subscribe to events
                RhinoApp.Idle        += RhinoApp_Idle;
                RhinoApp.Initialized += RhinoApp_Initialized;

                return(null);
            }
            catch (Exception ex)
            {
                Debug.Fail(ex.Message, ex.Source);
                return(ex);
            }
        }
示例#3
0
        internal static Result Shutdown()
        {
            if (core is object)
            {
                // Unload Guests
                CheckOutGuests();

                Revit.ApplicationUI.Idling -= RunScript;

                Command.EndCommand   -= EndCommand;
                Command.BeginCommand -= BeginCommand;

                RhinoDoc.EndOpenDocumentInitialViewUpdate -= EndOpenDocumentInitialViewUpdate;
                RhinoDoc.NewDocument -= OnNewDocument;

                RhinoApp.MainLoop -= MainLoop;

                // Unload RhinoCore
                try
                {
                    core.Dispose();
                    core = null;
                }
                catch (Exception /*e*/)
                {
                    //Debug.Fail(e.Source, e.Message);
                    return(Result.Failed);
                }
            }

            return(Result.Succeeded);
        }
示例#4
0
        internal static Result Shutdown()
        {
            if (core is object)
            {
                RhinoApp.MainLoop    -= MainLoop;
                RhinoDoc.NewDocument -= OnNewDocument;
                Revit.ApplicationUI.ApplicationClosing -= OnApplicationClosing;

                // Unload Guests
                CheckOutGuests();

                // Unload RhinoCore
                try
                {
                    core.Dispose();
                    core = null;
                }
                catch (Exception /*e*/)
                {
                    //Debug.Fail(e.Source, e.Message);
                    return(Result.Failed);
                }
            }

            return(Result.Succeeded);
        }
示例#5
0
        public void Initialize()
        {
            Instance = this;
            // Load Rhino
            try
            {
                var scheme_name = string.Format("BricsCAD.{0}", Application.Version);
                _rhinoCore = new RhinoCore(new[] { $"/scheme={scheme_name}", "/nosplash" }, WindowStyle.Hidden, Application.MainWindow.Handle);
            }
            catch
            {
                // ignored
            }

            var editor = Application.DocumentManager.MdiActiveDocument.Editor;

            if (_rhinoCore == null)
            {
                editor.WriteMessage("\nFailed to start Rhino WIP");
                return;
            }
            var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            editor.WriteMessage($"\nGrasshopper-BricsCAD Connection {version}");
            Application.Idle += onIdle;
            Application.DocumentManager.DocumentDestroyed += OnBcDocDestroyed;
        }
示例#6
0
        public Autodesk.Revit.UI.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.Normal, MainWindowHandle);
            }
            catch (Exception e)
            {
                Debug.Fail(e.Source, e.Message);
                return(Autodesk.Revit.UI.Result.Failed);
            }

            // Register UI
            {
                RibbonPanel ribbonPanel = ApplicationUI.CreateRibbonPanel("Rhinoceros");

                Sample1.CreateUI(ribbonPanel);
                Sample4.CreateUI(ribbonPanel);
            }

            // Add an Idling event handler to notify Rhino when the process is idle
            ApplicationUI.Idling += new EventHandler <IdlingEventArgs>(OnIdle);

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
示例#7
0
        public void Bootstrap()
        {
            const string schemeName       = "Illustrator";
            IntPtr       mainWindowHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;

            _rhinoCore = new RhinoCore(new string[] { $"/scheme={schemeName}", "/nosplash" }, WindowStyle.Normal, mainWindowHandle);
        }
示例#8
0
 public void LaunchRhino()
 {
     if (rhinoCore == null)
     {
         rhinoCore = new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Normal);
         Rhino.Runtime.HostUtils.RegisterNamedCallback("MeshFromGrasshopper", FromGrasshopper);
     }
 }
示例#9
0
        public void Main(ref cSapModel Model)
        {
            if (rhinoCore == null)
            {             // Load Rhino
                try
                {
                    var schemeName = "SAP";
                    rhinoCore = new RhinoCore(new string[] { $"/scheme={schemeName}", "/nosplash" }, WindowStyle.Normal, Process.GetCurrentProcess().MainWindowHandle);
                }
                catch (Exception e)
                {
                    Debug.Fail(e.Source, e.Message);
                    return;
                }
            }


            // RhinoCommon code
            var sphere = new Rhino.Geometry.Sphere(Point3d.Origin, 12000);
            var brep   = sphere.ToBrep();
            var mp     = MeshingParameters.Default;
            var meshes = Rhino.Geometry.Mesh.CreateFromBrep(brep, mp);

            foreach (var mesh in meshes.ToList())
            {
                for (int i = 0; i < mesh.Faces.Count; i++)
                {
                    Point3f a;
                    Point3f b;
                    Point3f c;
                    Point3f d;

                    mesh.Faces.GetFaceVertices(i, out a, out b, out c, out d);

                    List <Point3f> vertices = new List <Point3f>();
                    vertices.Add(a); vertices.Add(b); vertices.Add(c);
                    if (c != d)
                    {
                        vertices.Add(d);
                    }

                    List <string> points = new List <string>();

                    foreach (var v in vertices)
                    {
                        string p = string.Empty;
                        Model.PointObj.AddCartesian(v.X, v.Y, v.Z, ref p);
                        points.Add(p);
                    }

                    string   area = string.Empty;
                    string[] pts  = points.ToArray();
                    Model.AreaObj.AddByPoint(points.Count, ref pts, ref area);
                }
            }
        }
示例#10
0
        internal static Result Startup()
        {
            if (core is null)
            {
                // Load RhinoCore
                try
                {
                    core = new RhinoCore
                           (
                        new string[]
                    {
                        "/nosplash",
                        "/notemplate",
                        $"/scheme={SchemeName}",
                        $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}"
                    },
                        Rhino.Runtime.InProcess.WindowStyle.Hidden
                           );
                }
                catch (Exception)
                {
                    return(Result.Failed);
                }

                RhinoApp.MainLoop += MainLoop;

                RhinoDoc.NewDocument += OnNewDocument;
                RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate;

                Command.BeginCommand += BeginCommand;
                Command.EndCommand   += EndCommand;

                // Alternative to /runscript= Rhino command line option
                Revit.ApplicationUI.Idling += RunScript;

                // Reset document units
                UpdateDocumentUnits(RhinoDoc.ActiveDoc);
                UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);

                Type[] types = default;
                try { types = Assembly.GetCallingAssembly().GetTypes(); }
                catch (ReflectionTypeLoadException ex) { types = ex.Types?.Where(x => x is object).ToArray(); }

                // Look for Guests
                guests = types.
                         Where(x => typeof(IGuest).IsAssignableFrom(x)).
                         Where(x => !x.IsInterface).
                         Select(x => new GuestInfo(x)).
                         ToList();

                CheckInGuests();
            }

            return(Result.Succeeded);
        }
示例#11
0
 protected override void OnHandleCreated(EventArgs e)
 {
     if (rhinoCore == null)
     {
         // rhinoCore = new Rhino.Runtime.InProcess.RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Hidden, Handle);
         rhinoCore = new Rhino.Runtime.InProcess.RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.Normal);
         // TODO: determine whether to load automatically or on-demand
         LoadGH();
     }
     base.OnHandleCreated(e);
 }
示例#12
0
 public async Task <object> StartRhino(dynamic input)
 {
     try
     {
         rhinoCore = new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.NoWindow);
         return("Rhino has started.");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
示例#13
0
        protected override void BeginPlay()
        {
            base.BeginPlay();

            FMessage.Log(ELogVerbosity.Warning, "Hello from C# (" + this.GetType().ToString() + ":BeginPlay)");

            //Run Rhino.Inside no UI
            if (rhinoCore == null)
            {
                rhinoCore = new RhinoCore(new string[] { "/NOSPLASH" }, WindowStyle.NoWindow);
                FMessage.Log(ELogVerbosity.Warning, DoSomething());
            }
        }
示例#14
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);
        }
示例#15
0
 protected override void OnHandleDestroyed(EventArgs e)
 {
     if (definition != null)
     {
         definition.Dispose();
         definition = null;
     }
     if (rhinoCore != null)
     {
         rhinoCore.Dispose();
         rhinoCore = null;
     }
     base.OnHandleDestroyed(e);
 }
示例#16
0
        internal static Result Startup()
        {
            if (core is null)
            {
                // Load RhinoCore
                try
                {
                    core = new RhinoCore
                           (
                        new string[]
                    {
                        "/nosplash",
                        "/notemplate",
                        $"/scheme={SchemeName}",
                        $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}"
                    },
                        WindowStyle.Hidden,
                        Revit.MainWindowHandle
                           );
                }
                catch (Exception /*e*/)
                {
                    //Debug.Fail(e.Source, e.Message);
                    return(Result.Failed);
                }

                // Look for Guests
                guests = Assembly.GetCallingAssembly().GetTypes().
                         Where(x => typeof(IGuest).IsAssignableFrom(x)).
                         Where(x => !x.IsInterface).
                         Select(x => new GuestInfo(x)).
                         ToList();

                Revit.ApplicationUI.ApplicationClosing += OnApplicationClosing;
                RhinoDoc.NewDocument += OnNewDocument;
                Rhino.Commands.Command.BeginCommand += BeginCommand;
                Rhino.Commands.Command.EndCommand   += EndCommand;
                RhinoApp.MainLoop += MainLoop;

                // Reset document units
                UpdateDocumentUnits(RhinoDoc.ActiveDoc);

                CheckInGuests();
            }

            UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);
            return(Result.Succeeded);
        }
示例#17
0
        public Autodesk.Revit.UI.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(Autodesk.Revit.UI.Result.Failed);
            }

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

                UI.RhinoCommand.CreateUI(ribbonPanel);
                UI.GrasshopperCommand.CreateUI(ribbonPanel);
                ribbonPanel.AddSeparator();
                Sample1.CreateUI(ribbonPanel);
                Sample4.CreateUI(ribbonPanel);
                ribbonPanel.AddSeparator();
                UI.APIDocsCommand.CreateUI(ribbonPanel);
            }

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

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
        internal static Result Startup()
        {
            if (core is null)
            {
                // Load RhinoCore
                try
                {
                    core = new RhinoCore
                           (
                        new string[]
                    {
                        "/nosplash",
                        "/notemplate",
                        "/captureprintcalls",
                        "/stopwatch",
                        $"/scheme={SchemeName}",
                        $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}"
                    },
                        WindowStyle.Hidden
                           );
                }
                catch
                {
                    Addin.CurrentStatus = Addin.Status.Failed;
                    return(Result.Failed);
                }
                finally
                {
                    StartupLog = RhinoApp.CapturedCommandWindowStrings(true);
                    RhinoApp.CommandWindowCaptureEnabled = false;
                }

                MainWindow = new WindowHandle(RhinoApp.MainWindowHandle());
                External.ActivationGate.AddGateWindow(MainWindow.Handle);

                RhinoApp.MainLoop += MainLoop;

                RhinoDoc.NewDocument += OnNewDocument;
                RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate;

                Command.BeginCommand += BeginCommand;
                Command.EndCommand   += EndCommand;

                // Alternative to /runscript= Rhino command line option
                RunScriptAsync
                (
                    script:   Environment.GetEnvironmentVariable("RhinoInside_RunScript"),
                    activate: Addin.StartupMode == AddinStartupMode.AtStartup
                );

                // Add DefaultRenderAppearancePath to Rhino settings if missing
                {
                    var DefaultRenderAppearancePath = System.IO.Path.Combine
                                                      (
                        Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFilesX86),
                        "Autodesk Shared",
                        "Materials",
                        "Textures"
                                                      );

                    if (!Rhino.ApplicationSettings.FileSettings.GetSearchPaths().Any(x => x.Equals(DefaultRenderAppearancePath, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        Rhino.ApplicationSettings.FileSettings.AddSearchPath(DefaultRenderAppearancePath, -1);
                    }

                    // TODO: Add also AdditionalRenderAppearancePaths content from Revit.ini if missing ??
                }

                // Reset document units
                UpdateDocumentUnits(RhinoDoc.ActiveDoc);
                UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);

                Type[] types = default;
                try { types = Assembly.GetCallingAssembly().GetTypes(); }
                catch (ReflectionTypeLoadException ex) { types = ex.Types?.Where(x => x is object).ToArray(); }

                // Look for Guests
                guests = types.
                         Where(x => typeof(IGuest).IsAssignableFrom(x)).
                         Where(x => !x.IsInterface && !x.IsAbstract && !x.ContainsGenericParameters).
                         Select(x => new GuestInfo(x)).
                         ToList();

                CheckInGuests();
            }

            return(Result.Succeeded);
        }
示例#19
0
        internal static Result Startup()
        {
            if (core is null)
            {
                // Load RhinoCore
                try
                {
                    core = new RhinoCore
                           (
                        new string[]
                    {
                        "/nosplash",
                        "/notemplate",
                        $"/scheme={SchemeName}",
                        $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}"
                    },
                        Rhino.Runtime.InProcess.WindowStyle.Hidden,
                        Revit.MainWindowHandle
                           );

                    WindowVisible = false;
                }
                catch (Exception)
                {
                    return(Result.Failed);
                }

                Revit.ApplicationUI.ApplicationClosing += OnApplicationClosing;
                RhinoDoc.NewDocument += OnNewDocument;
                Rhino.Commands.Command.BeginCommand += BeginCommand;
                Rhino.Commands.Command.EndCommand   += EndCommand;
                RhinoApp.MainLoop += MainLoop;

                // Reset document units
                UpdateDocumentUnits(RhinoDoc.ActiveDoc);

                try
                {
                    // Look for Guests
                    guests = Assembly.GetCallingAssembly().GetTypes().
                             Where(x => typeof(IGuest).IsAssignableFrom(x)).
                             Where(x => !x.IsInterface).
                             Select(x => new GuestInfo(x)).
                             ToList();

                    CheckInGuests();
                }
                catch (ReflectionTypeLoadException e)
                {
                    using
                    (
                        var taskDialog = new TaskDialog(MethodBase.GetCurrentMethod().DeclaringType.FullName)
                    {
                        Title = "Exception thrown",
                        MainIcon = TaskDialogIcons.IconError,
                        AllowCancellation = true,
                        MainInstruction = "Unable to load one or more of the requested types.",
                        MainContent = "Click on 'Show details' for more info"
                    }
                    )
                    {
                        var expandedContent = string.Empty;
                        int length          = Math.Min(e.Types.Length, e.LoaderExceptions.Length);
                        for (int i = 0; i < length; i++)
                        {
                            if (e.Types[i] is null)
                            {
                                if (expandedContent != string.Empty)
                                {
                                    expandedContent += Environment.NewLine;
                                }

                                expandedContent += $"- {e.LoaderExceptions[i].Message}";
                            }
                        }

                        taskDialog.ExpandedContent = expandedContent;
                        taskDialog.Show();
                    }
                }
            }

            UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);
            return(Result.Succeeded);
        }
示例#20
0
        internal static Result Startup()
        {
            if (core is null)
            {
                // Load RhinoCore
                try
                {
                    core = new RhinoCore
                           (
                        new string[]
                    {
                        "/nosplash",
                        "/notemplate",
                        "/captureprintcalls",
                        "/stopwatch",
                        $"/scheme={SchemeName}",
                        $"/language={Revit.ApplicationUI.ControlledApplication.Language.ToLCID()}"
                    },
                        WindowStyle.Hidden
                           );
                }
                catch
                {
                    Addin.CurrentStatus = Addin.Status.Failed;
                    return(Result.Failed);
                }
                finally
                {
                    StartupLog = RhinoApp.CapturedCommandWindowStrings(true);
                    RhinoApp.CommandWindowCaptureEnabled = false;
                }

                MainWindow = new WindowHandle(RhinoApp.MainWindowHandle());
                External.ActivationGate.AddGateWindow(MainWindow.Handle);

                RhinoApp.MainLoop += MainLoop;

                RhinoDoc.NewDocument += OnNewDocument;
                RhinoDoc.EndOpenDocumentInitialViewUpdate += EndOpenDocumentInitialViewUpdate;

                Command.BeginCommand += BeginCommand;
                Command.EndCommand   += EndCommand;

                // Alternative to /runscript= Rhino command line option
                RunScriptAsync
                (
                    script:   Environment.GetEnvironmentVariable("RhinoInside_RunScript"),
                    activate: Addin.StartupMode == AddinStartupMode.AtStartup
                );

                // Reset document units
                UpdateDocumentUnits(RhinoDoc.ActiveDoc);
                UpdateDocumentUnits(RhinoDoc.ActiveDoc, Revit.ActiveDBDocument);

                Type[] types = default;
                try { types = Assembly.GetCallingAssembly().GetTypes(); }
                catch (ReflectionTypeLoadException ex) { types = ex.Types?.Where(x => x is object).ToArray(); }

                // Look for Guests
                guests = types.
                         Where(x => typeof(IGuest).IsAssignableFrom(x)).
                         Where(x => !x.IsInterface).
                         Select(x => new GuestInfo(x)).
                         ToList();

                CheckInGuests();

                //Enable Revit window back
                WindowHandle.ActiveWindow = Revit.MainWindow;
            }

            return(Result.Succeeded);
        }