コード例 #1
0
ファイル: Utils.cs プロジェクト: nomenconfusa/RhinoLink
 // This is the property that GH components use to acquire the link to the kernel, which is
 // held in the WolframScripting Rhino plugin.
 public static IKernelLink GetLink()
 {
     lock (pluginLock)
     {
         if (link == null)
         {
             link = (IKernelLink)RhinoApp.GetPlugInObject("WolframScripting");
         }
         return(link);
     }
 }
コード例 #2
0
ファイル: Noah.cs プロジェクト: i-noah/noah-n
        public static void LaunchGrasshopper()
        {
            if (!(RhinoApp.GetPlugInObject("Grasshopper") is GH_RhinoScriptInterface gh))
            {
                return;
            }

            if (gh.IsEditorLoaded())
            {
                return;
            }

            gh.DisableBanner();
            gh.LoadEditor();

            Instances.AutoHideBanner = false;
            Instances.AutoShowBanner = false;
            Instances.ComponentServer.DestroyLoadingUI();
        }
コード例 #3
0
ファイル: NoahServer.cs プロジェクト: KaivnD/noah-plugin
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            if (!(RhinoApp.GetPlugInObject("Grasshopper") is GH_RhinoScriptInterface Grasshopper))
            {
                return(Result.Cancel);
            }

            GetOption go = null;

            while (true)
            {
                var port     = new OptionInteger(Port, 1024, 65535);
                var toggle   = new OptionToggle(ShowEditor, "Hide", "Show");
                var debugger = new OptionToggle(Debug, "Off", "On");

                go = new GetOption();

                go.SetCommandPrompt("Noah Server");
                go.AddOption("Connect");
                go.AddOption("Stop");
                go.AddOption("Observer");
                go.AddOptionInteger("Port", ref port);
                go.AddOptionToggle("Editor", ref toggle);
                go.AddOptionToggle("Debug", ref debugger);
                go.AddOption("Workspace");

                GetResult result = go.Get();
                if (result != GetResult.Option)
                {
                    break;
                }

                ShowEditor = toggle.CurrentValue;
                Debug      = debugger.CurrentValue;

                string whereToGo = go.Option().EnglishName;

                if (whereToGo == "Connect")
                {
                    if (Port == 0)
                    {
                        RhinoApp.WriteLine("Please set Port you want to connect!");
                        continue;
                    }

                    if (WorkDir == null)
                    {
                        RhinoApp.WriteLine("Noah can not work without workspace!");
                        continue;
                    }

                    if (Client == null)
                    {
                        try
                        {
                            Grasshopper.DisableBanner();

                            if (!Grasshopper.IsEditorLoaded())
                            {
                                Grasshopper.LoadEditor();
                            }

                            Client               = new NoahClient(Port, WorkDir);
                            Client.InfoEvent    += Client_MessageEvent;
                            Client.ErrorEvent   += Client_ErrorEvent;
                            Client.WarningEvent += Client_WarningEvent;
                            Client.DebugEvent   += Client_DebugEvent;
                        }
                        catch (Exception ex)
                        {
                            RhinoApp.WriteLine("Error: " + ex.Message);
                        }

                        Client.Connect();
                    }
                    else
                    {
                        Client.Reconnect();
                    }

                    if (Debug)
                    {
                        try
                        {
                            if (Logger == null)
                            {
                                Panels.OpenPanel(LoggerPanel.PanelId);
                            }
                            Logger = Panels.GetPanel <LoggerPanel>(doc);
                        }
                        catch (Exception ex)
                        {
                            RhinoApp.WriteLine("Error: " + ex.Message);
                        }
                    }

                    if (ShowEditor)
                    {
                        Grasshopper.ShowEditor();
                    }

                    break;
                }

                if (whereToGo == "Stop")
                {
                    if (Port == 0)
                    {
                        continue;
                    }

                    if (Client != null)
                    {
                        Client.Close();
                    }
                    break;
                }

                if (whereToGo == "Workspace")
                {
                    RhinoGet.GetString("Noah Workspace", false, ref WorkDir);
                }

                if (whereToGo == "Observer")
                {
                    if (Port == 0)
                    {
                        RhinoApp.WriteLine("Server connecting need a port!");
                        continue;
                    }

                    Process.Start("http://localhost:" + Port + "/data/center");
                    break;
                }

                if (whereToGo == "Port")
                {
                    Port = port.CurrentValue;
                    RhinoApp.WriteLine("Port is set to " + Port.ToString());
                    continue;
                }
            }

            return(Result.Nothing);
        }
コード例 #4
0
        /// <summary>
        /// RunCommand override
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Verify that Grasshopper is installed
            string gh_path = Rhino.PlugIns.PlugIn.PathFromId(m_gh_guid);

            if (string.IsNullOrEmpty(gh_path) && File.Exists(gh_path))
            {
                RhinoApp.WriteLine("Grasshopper not installed.");
                return(Result.Cancel);
            }

            // Prompt the user for a Grasshopper solution to open
            string filename = string.Empty;

            if (mode == RunMode.Interactive)
            {
                OpenFileDialog dialog = new OpenFileDialog();
                dialog.Filter     = @"Grasshopper Files (*.gh;*.ghx)|*.gh; *.ghx||";
                dialog.DefaultExt = "gh";
                DialogResult rc = dialog.ShowDialog();
                if (rc != DialogResult.OK)
                {
                    return(Result.Cancel);
                }

                filename = dialog.FileName;
            }
            else
            {
                Result rc = Rhino.Input.RhinoGet.GetString("Grasshopper file to open", false, ref filename);
                if (rc != Result.Success)
                {
                    return(rc);
                }
            }

            // Verify Grasshopper file
            if (string.IsNullOrEmpty(filename) || !File.Exists(filename))
            {
                return(Result.Failure);
            }

            try
            {
                // Try getting the Grasshopper COM object
                object gh_object = RhinoApp.GetPlugInObject(m_gh_guid);

                // Create a parameters array
                object[] parameters = new object[1];
                parameters[0] = filename;

                // Invoke the OpenDocument method
                gh_object.GetType().InvokeMember("OpenDocument", BindingFlags.InvokeMethod, null, gh_object, parameters);

                // You can use the folloiwng to dump the names and types of
                // all of the members to the command line...

                //foreach (MemberInfo member in gh_object.GetType().GetMembers())
                //  RhinoApp.WriteLine("{0} -- {1}", member.MemberType, member);
            }
            catch (Exception ex)
            {
                RhinoApp.WriteLine(ex.Message);
            }

            return(Result.Success);
        }