コード例 #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // get the path
            string path = string.Empty;

            RhinoGet.GetString("Absolute path of the exexutable", true, ref path);
            if (string.IsNullOrEmpty(path))
            {
                RhinoApp.WriteLine("Cancelled.");
                return(Result.Cancel);
            }
            // valdiate path
            if (!File.Exists(path))
            {
                RhinoApp.WriteLine("File path is not valid.");
                return(Result.Cancel);
            }
            // run the file
            try
            {
                Process.Start(path);
            }
            catch (Exception e)
            {
                RhinoApp.WriteLine(e.Message);
            }

            return(Result.Success);
        }
コード例 #2
0
        /// <summary>
        /// Called by Rhino when the user wants to run the command.
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            GetOption go = new GetOption();

            go.SetCommandPrompt("Select command option");
            int add_index    = go.AddOption("Add");
            int delete_index = go.AddOption("Delete");
            int list_index   = go.AddOption("List");

            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            CommandLineOption option = go.Option();

            if (null == option)
            {
                return(Result.Failure);
            }

            int index = option.Index;

            if (index == add_index)
            {
                string str = string.Empty;
                Result rc  = RhinoGet.GetString("String to add", false, ref str);
                if (rc == Result.Success)
                {
                    SampleCsStringTableHelpers.Add(str);
                }
            }
            else if (index == delete_index)
            {
                string str = string.Empty;
                Result rc  = RhinoGet.GetString("String to delete", false, ref str);
                if (rc == Result.Success)
                {
                    SampleCsStringTableHelpers.Remove(str);
                }
            }
            else if (index == list_index)
            {
                int count = SampleCsStringTableHelpers.Count();
                if (0 == count)
                {
                    RhinoApp.WriteLine("0 string items to list.");
                }
                else
                {
                    for (int i = 0; i < count; i++)
                    {
                        RhinoApp.WriteLine(SampleCsStringTableHelpers.GetAt(i));
                    }
                }
            }

            return(Result.Success);
        }
コード例 #3
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            RhinoView view = doc.Views.ActiveView;

            if (null == view)
            {
                return(Result.Failure);
            }

            string name = null;
            Result rc   = RhinoGet.GetString("Named view to restore", false, ref name);

            if (rc != Result.Success || string.IsNullOrEmpty(name))
            {
                return(Result.Cancel);
            }

            int index = doc.NamedViews.FindByName(name);

            if (index < 0 || index >= doc.NamedViews.Count)
            {
                RhinoApp.WriteLine("Named view not found");
                return(Result.Nothing);
            }

            //doc.NamedViews.Restore(index, view, false);
            doc.NamedViews.RestoreAnimated(index, view, false);
            view.Redraw();

            return(Result.Success);
        }
コード例 #4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var filename = string.Empty;

            if (mode == Rhino.Commands.RunMode.Interactive)
            {
                filename = RhinoGet.GetFileName(GetFileNameMode.OpenRhinoOnly, null, "Open", RhinoApp.MainWindowHandle());
            }
            else
            {
                RhinoGet.GetString("Name of Rhino file to open", false, ref filename);
            }

            filename = filename.Trim();
            if (string.IsNullOrEmpty(filename))
            {
                return(Result.Cancel);
            }

            if (!System.IO.File.Exists(filename))
            {
                RhinoApp.WriteLine("File not found.");
                return(Result.Failure);
            }

            // Make sure to surround filename string with double-quote characters
            // in case the path contains spaces.
            var script = string.Format("_-Open \"{0}\"", filename);

            RhinoApp.RunScript(script, false);

            return(Result.Success);
        }
コード例 #5
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            ObjRef obj_ref;
            var    rc = RhinoGet.GetOneObject("Select object to change name", true, ObjectType.AnyObject, out obj_ref);

            if (rc != Result.Success)
            {
                return(rc);
            }
            var rhino_object = obj_ref.Object();

            var new_object_name = "";

            rc = RhinoGet.GetString("New object name", true, ref new_object_name);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (string.IsNullOrWhiteSpace(new_object_name))
            {
                return(Result.Nothing);
            }

            if (rhino_object.Name != new_object_name)
            {
                rhino_object.Attributes.Name = new_object_name;
                rhino_object.CommitChanges();
            }

            return(Result.Success);
        }
コード例 #6
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var view = doc.Views.ActiveView;

            if (null == view)
            {
                return(Result.Failure);
            }

            var conduit = new SampleCsDrawGrayscaleConduit(view.ActiveViewportID)
            {
                Enabled = true
            };

            doc.Views.Redraw();

            string out_str = null;

            RhinoGet.GetString("Press <Enter> to continue", true, ref out_str);

            conduit.Enabled = false;
            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Plane  plane  = Plane.WorldXY;
            double radius = 10.0;
            double height = 2.0;

            Circle   circle   = new Circle(plane, radius);
            Cylinder cylinder = new Cylinder(circle, height);

            Brep brep = Brep.CreateFromCylinder(cylinder, true, true);

            SampleCsShadedBrepConduit conduit = new SampleCsShadedBrepConduit();

            conduit.BrepGeometry = brep;
            conduit.Enabled      = true;
            doc.Views.Redraw();

            string out_str = null;

            RhinoGet.GetString("Press <Enter> to continue", true, ref out_str);

            conduit.Enabled = false;

            doc.Objects.AddBrep(brep);
            doc.Views.Redraw();

            return(Result.Success);
        }
コード例 #8
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Point3d[] corners;
            var       rc = RhinoGet.GetRectangle(out corners);

            if (rc != Result.Success)
            {
                return(rc);
            }

            var plane = new Plane(corners[0], corners[1], corners[2]);

            var plane_surface = new PlaneSurface(
                plane,
                new Interval(0, corners[0].DistanceTo(corners[1])),
                new Interval(0, corners[1].DistanceTo(corners[2]))
                );

            rc = Result.Cancel;
            if (plane_surface.IsValid)
            {
                var layer_name = doc.Layers.GetUnusedLayerName();
                rc = RhinoGet.GetString("Name of layer to create", true, ref layer_name);
                if (rc == Result.Success && !string.IsNullOrEmpty(layer_name))
                {
                    var layer_index = doc.Layers.FindByFullPath(layer_name, -1);
                    if (-1 == layer_index)
                    {
                        layer_index = doc.Layers.Add(layer_name, System.Drawing.Color.Black);
                    }

                    if (layer_index >= 0)
                    {
                        var attribs = doc.CreateDefaultAttributes();
                        attribs.LayerIndex = layer_index;
                        attribs.Name       = layer_name;
                        doc.Objects.AddSurface(plane_surface, attribs);
                        doc.Views.Redraw();
                        rc = Result.Success;
                    }
                }
            }

            return(rc);
        }
コード例 #9
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string filename = null;
            var    rc       = RhinoGet.GetString("Name of AutoCAD DWG file to open", false, ref filename);

            if (rc != Result.Success)
            {
                return(rc);
            }

            filename = filename.Trim();
            if (string.IsNullOrEmpty(filename))
            {
                return(Result.Nothing);
            }

            if (!File.Exists(filename))
            {
                RhinoApp.WriteLine("File not found");
                return(Result.Failure);
            }

            var extension = Path.GetExtension(filename);

            if (string.IsNullOrEmpty(extension))
            {
                return(Result.Nothing);
            }

            if (!string.Equals(extension, ".dwg", StringComparison.InvariantCultureIgnoreCase))
            {
                RhinoApp.WriteLine("Not an AutoCAD DWG file.");
                return(Result.Failure);
            }

            // Make sure to surround filename string with double-quote characters
            // in case the path contains spaces.
            var script = string.Format("_-Open \"{0}\" _Enter", filename);

            RhinoApp.RunScript(script, false);

            return(Result.Success);
        }
コード例 #10
0
ファイル: Load3dm.cs プロジェクト: KaivnD/noah-plugin
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string path    = "";
            Result getArgs = RhinoGet.GetString("加载文件", true, ref path);

            if (File.Exists(path))
            {
                bool alreadyOpen = false;
                RhinoDoc.Open(path, out alreadyOpen);
                if (alreadyOpen)
                {
                    RhinoApp.WriteLine(string.Format("已加载 {0}", path));
                }
            }
            else
            {
                RhinoApp.WriteLine(string.Format("{0} 文件不存在", path));
            }
            return(Result.Success);
        }
コード例 #11
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get the name of the instance definition to rename
            string instance_definition_name = "";
            var    rc = RhinoGet.GetString("Name of block to delete", true, ref instance_definition_name);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (string.IsNullOrWhiteSpace(instance_definition_name))
            {
                return(Result.Nothing);
            }

            // Verify instance definition exists
            var instance_definition = doc.InstanceDefinitions.Find(instance_definition_name, true);

            if (instance_definition == null)
            {
                RhinoApp.WriteLine("Block \"{0}\" not found.", instance_definition_name);
                return(Result.Nothing);
            }

            // Verify instance definition can be deleted
            if (instance_definition.IsReference)
            {
                RhinoApp.WriteLine("Unable to delete block \"{0}\".", instance_definition_name);
                return(Result.Nothing);
            }

            // delete block and all references
            if (!doc.InstanceDefinitions.Delete(instance_definition.Index, true, true))
            {
                RhinoApp.WriteLine("Could not delete {0} block", instance_definition.Name);
                return(Result.Failure);
            }

            return(Result.Success);
        }
コード例 #12
0
ファイル: EchoCommand.cs プロジェクト: dalefugier/Rockfish
        /// <summary>
        /// Called by Rhino when the user wants to run the command.
        /// </summary>
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var rc = RockfishClientPlugIn.VerifyServerHostName();

            if (rc != Result.Success)
            {
                return(rc);
            }

            var message = "Hello Rhino!";

            rc = RhinoGet.GetString("String to echo", false, ref message);
            if (rc != Result.Success)
            {
                return(rc);
            }

            try
            {
                RockfishClientPlugIn.ServerHostName();
                using (var channel = new RockfishClientChannel())
                {
                    channel.Create();
                    message = channel.Echo(message);
                }
            }
            catch (Exception ex)
            {
                RhinoApp.WriteLine(ex.Message);
                return(Result.Failure);
            }

            RhinoApp.WriteLine(message);

            return(Result.Success);
        }
コード例 #13
0
    public static Result LockLayer(RhinoDoc doc)
    {
        string layer_name = "";
        var    rc         = RhinoGet.GetString("Name of layer to lock", true, ref layer_name);

        if (rc != Result.Success)
        {
            return(rc);
        }
        if (String.IsNullOrWhiteSpace(layer_name))
        {
            return(Result.Nothing);
        }

        // because of sublayers it's possible that mone than one layer has the same name
        // so simply calling doc.Layers.Find(layerName) isn't good enough.  If "layerName" returns
        // more than one layer then present them to the user and let him decide.
        var matching_layers = (from layer in doc.Layers
                               where layer.Name == layer_name
                               select layer).ToList <Rhino.DocObjects.Layer>();

        Rhino.DocObjects.Layer layer_to_lock = null;
        if (matching_layers.Count == 0)
        {
            RhinoApp.WriteLine("Layer \"{0}\" does not exist.", layer_name);
            return(Result.Nothing);
        }
        else if (matching_layers.Count == 1)
        {
            layer_to_lock = matching_layers[0];
        }
        else if (matching_layers.Count > 1)
        {
            for (int i = 0; i < matching_layers.Count; i++)
            {
                RhinoApp.WriteLine("({0}) {1}", i + 1, matching_layers[i].FullPath.Replace("::", "->"));
            }
            int selected_layer = -1;
            rc = RhinoGet.GetInteger("which layer?", true, ref selected_layer);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (selected_layer > 0 && selected_layer <= matching_layers.Count)
            {
                layer_to_lock = matching_layers[selected_layer - 1];
            }
            else
            {
                return(Result.Nothing);
            }
        }

        if (layer_to_lock == null)
        {
            return(Result.Nothing);
        }

        if (!layer_to_lock.IsLocked)
        {
            layer_to_lock.IsLocked = true;
            layer_to_lock.CommitChanges();
            return(Result.Success);
        }
        else
        {
            RhinoApp.WriteLine("layer {0} is already locked.", layer_to_lock.FullPath);
            return(Result.Nothing);
        }
    }
コード例 #14
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var go = new GetObject();

            go.SetCommandPrompt("Selet surface or polysurface to serialize to a file.");
            go.GeometryFilter  = ObjectType.Surface | ObjectType.PolysrfFilter;
            go.SubObjectSelect = false;
            go.Get();
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            var brep = go.Object(0).Brep();

            if (null == brep)
            {
                return(Result.Failure);
            }

            string path = null;

            if (mode == RunMode.Interactive)
            {
                var dialog = new SaveFileDialog
                {
                    Title      = EnglishName,
                    Filter     = @"Bin Files (*.bin)|*.bin||",
                    DefaultExt = "bin"
                };

                if (!dialog.ShowSaveDialog())
                {
                    return(Result.Cancel);
                }

                path = dialog.FileName;
            }
            else
            {
                var result = RhinoGet.GetString("Save file name", false, ref path);
                if (result != Result.Success)
                {
                    return(result);
                }
            }

            path = path.Trim();
            if (string.IsNullOrEmpty(path))
            {
                return(Result.Nothing);
            }

            if (!Path.HasExtension(path))
            {
                path = Path.ChangeExtension(path, ".bin");
            }

            var rc = SampleCsGeometryHelper.WriteToFile(path, brep);

            return(rc ? Result.Success : Result.Failure);
        }
コード例 #15
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            doc.Objects.UnselectAll();

            ObjRef obj_ref1;
            var    rc1 = RhinoGet.GetOneObject("first curve", true, ObjectType.Curve, out obj_ref1);

            if (rc1 != Result.Success)
            {
                return(rc1);
            }
            Curve curve_a = null;

            if (obj_ref1 != null)
            {
                curve_a = obj_ref1.Curve();
            }
            if (curve_a == null)
            {
                return(Result.Failure);
            }

            // Since you already selected a curve if you don't unselect it
            // the next GetOneObject won't stop as it considers that curve
            // input, i.e., curveA and curveB will point to the same curve.
            // Another option would be to use an instance of Rhino.Input.Custom.GetObject
            // instead of Rhino.Input.RhinoGet as GetObject has a DisablePreSelect() method.
            doc.Objects.UnselectAll();

            ObjRef obj_ref2;
            var    rc2 = RhinoGet.GetOneObject("second curve", true, ObjectType.Curve, out obj_ref2);

            if (rc2 != Result.Success)
            {
                return(rc2);
            }
            Curve curve_b = null;

            if (obj_ref2 != null)
            {
                curve_b = obj_ref2.Curve();
            }
            if (curve_b == null)
            {
                return(Result.Failure);
            }

            var tolerance = doc.ModelAbsoluteTolerance;

            double max_distance;
            double max_distance_parameter_a;
            double max_distance_parameter_b;
            double min_distance;
            double min_distance_parameter_a;
            double min_distance_parameter_b;

            DeviationConduit conduit;

            if (!Curve.GetDistancesBetweenCurves(curve_a, curve_b, tolerance, out max_distance,
                                                 out max_distance_parameter_a, out max_distance_parameter_b,
                                                 out min_distance, out min_distance_parameter_a, out min_distance_parameter_b))
            {
                RhinoApp.WriteLine("Unable to find overlap intervals.");
                return(Result.Success);
            }
            else
            {
                if (min_distance <= RhinoMath.ZeroTolerance)
                {
                    min_distance = 0.0;
                }
                var max_dist_pt_a = curve_a.PointAt(max_distance_parameter_a);
                var max_dist_pt_b = curve_b.PointAt(max_distance_parameter_b);
                var min_dist_pt_a = curve_a.PointAt(min_distance_parameter_a);
                var min_dist_pt_b = curve_b.PointAt(min_distance_parameter_b);

                conduit = new DeviationConduit(curve_a, curve_b, min_dist_pt_a, min_dist_pt_b, max_dist_pt_a, max_dist_pt_b)
                {
                    Enabled = true
                };
                doc.Views.Redraw();

                RhinoApp.WriteLine("Minimum deviation = {0}   pointA({1}), pointB({2})", min_distance, min_dist_pt_a, min_dist_pt_b);
                RhinoApp.WriteLine("Maximum deviation = {0}   pointA({1}), pointB({2})", max_distance, max_dist_pt_a, max_dist_pt_b);
            }

            var str = "";

            RhinoGet.GetString("Press Enter when done", true, ref str);
            conduit.Enabled = false;

            return(Result.Success);
        }
コード例 #16
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string path = null;

            if (mode == RunMode.Interactive)
            {
                var dialog = new OpenFileDialog
                {
                    Title  = EnglishName,
                    Filter = @"Text Documents|*.txt"
                };

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancel);
                }

                path = dialog.FileName;
            }
            else
            {
                var rc = RhinoGet.GetString("Name of file to embed", false, ref path);
                if (rc != Result.Success)
                {
                    return(rc);
                }
            }

            path = path.Trim();
            if (string.IsNullOrEmpty(path))
            {
                return(Result.Nothing);
            }

            if (!File.Exists(path))
            {
                RhinoApp.WriteLine("File not found.");
                return(Result.Nothing);
            }

            string text;

            try
            {
                text = File.ReadAllText(path);
            }
            catch (Exception ex)
            {
                RhinoApp.WriteLine(ex.Message);
                return(Result.Failure);
            }

            if (string.IsNullOrEmpty(text))
            {
                RhinoApp.WriteLine("File is empty.");
                return(Result.Nothing);
            }

            var fname = Path.GetFileName(path);

            doc.Strings.SetString(fname, text);

            RhinoApp.Write("Embedded {0} ({1} characters)", fname, text.Length);

            return(Result.Success);
        }
コード例 #17
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Get the name of the insance definition to rename
            var instance_definition_name = "";
            var rc = RhinoGet.GetString("Name of block to rename", true, ref instance_definition_name);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (string.IsNullOrWhiteSpace(instance_definition_name))
            {
                return(Result.Nothing);
            }

            // Verify instance definition exists
            var instance_definition = doc.InstanceDefinitions.Find(instance_definition_name, true);

            if (instance_definition == null)
            {
                RhinoApp.WriteLine("Block \"{0}\" not found.", instance_definition_name);
                return(Result.Nothing);
            }

            // Verify instance definition is rename-able
            if (instance_definition.IsDeleted || instance_definition.IsReference)
            {
                RhinoApp.WriteLine("Unable to rename block \"{0}\".", instance_definition_name);
                return(Result.Nothing);
            }

            // Get the new instance definition name
            string instance_definition_new_name = "";

            rc = RhinoGet.GetString("Name of block to rename", true, ref instance_definition_new_name);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (string.IsNullOrWhiteSpace(instance_definition_new_name))
            {
                return(Result.Nothing);
            }

            // Verify the new instance definition name is not already in use
            var existing_instance_definition = doc.InstanceDefinitions.Find(instance_definition_new_name, true);

            if (existing_instance_definition != null && !existing_instance_definition.IsDeleted)
            {
                RhinoApp.WriteLine("Block \"{0}\" already exists.", existing_instance_definition);
                return(Result.Nothing);
            }

            // change the block name
            if (!doc.InstanceDefinitions.Modify(instance_definition.Index, instance_definition_new_name, instance_definition.Description, true))
            {
                RhinoApp.WriteLine("Could not rename {0} to {1}", instance_definition.Name, instance_definition_new_name);
                return(Result.Failure);
            }

            return(Result.Success);
        }
コード例 #18
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string fname = null;
            var    rc    = RhinoGet.GetString("Name of file to extract", false, ref fname);

            if (rc != Result.Success)
            {
                return(rc);
            }

            fname = fname.Trim();
            if (string.IsNullOrEmpty(fname))
            {
                return(Result.Nothing);
            }

            var text = doc.Strings.GetValue(fname);

            if (string.IsNullOrEmpty(text))
            {
                RhinoApp.WriteLine("File not found.");
                return(Result.Nothing);
            }

            string path = null;

            if (mode == RunMode.Interactive)
            {
                var dialog = new SaveFileDialog
                {
                    Title    = EnglishName,
                    Filter   = @"Text Documents|*.txt",
                    FileName = fname
                };

                if (dialog.ShowDialog() != DialogResult.OK)
                {
                    return(Result.Cancel);
                }

                path = dialog.FileName;
            }
            else
            {
                rc = RhinoGet.GetString("Save file name", false, ref path);
                if (rc != Result.Success)
                {
                    return(rc);
                }
            }

            path = path.Trim();
            if (string.IsNullOrEmpty(path))
            {
                return(Result.Nothing);
            }

            try
            {
                File.WriteAllText(path, text);
                // Optional, purge embedded text
                doc.Strings.Delete(fname);
            }
            catch (Exception ex)
            {
                RhinoApp.WriteLine(ex.Message);
                return(Result.Failure);
            }

            return(Result.Success);
        }
コード例 #19
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);
        }
コード例 #20
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Select objects to define block
            var go = new GetObject();

            go.SetCommandPrompt("Select objects to define block");
            go.ReferenceObjectSelect = false;
            go.SubObjectSelect       = false;
            go.GroupSelect           = true;

            // Phantoms, grips, lights, etc., cannot be in blocks.
            var forbidden_geometry_filter = ObjectType.Light | ObjectType.Grip | ObjectType.Phantom;
            var geometry_filter           = forbidden_geometry_filter ^ ObjectType.AnyObject;

            go.GeometryFilter = geometry_filter;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            // Block base point
            Point3d base_point;
            var     rc = RhinoGet.GetPoint("Block base point", false, out base_point);

            if (rc != Result.Success)
            {
                return(rc);
            }

            // Block definition name
            string idef_name = "";

            rc = RhinoGet.GetString("Block definition name", false, ref idef_name);
            if (rc != Result.Success)
            {
                return(rc);
            }

            // Validate block name
            idef_name = idef_name.Trim();
            if (string.IsNullOrEmpty(idef_name))
            {
                return(Result.Nothing);
            }

            // See if block name already exists
            InstanceDefinition existing_idef = doc.InstanceDefinitions.Find(idef_name);

            if (existing_idef != null)
            {
                RhinoApp.WriteLine("Block definition {0} already exists", idef_name);
                return(Result.Nothing);
            }

            // Gather all of the selected objects
            var geometry   = new List <GeometryBase>();
            var attributes = new List <ObjectAttributes>();

            for (int i = 0; i < go.ObjectCount; i++)
            {
                var rh_object = go.Object(i).Object();
                if (rh_object != null)
                {
                    geometry.Add(rh_object.Geometry);
                    attributes.Add(rh_object.Attributes);
                }
            }

            // Gather all of the selected objects
            var idef_index = doc.InstanceDefinitions.Add(idef_name, string.Empty, base_point, geometry, attributes);

            if (idef_index < 0)
            {
                RhinoApp.WriteLine("Unable to create block definition", idef_name);
                return(Result.Failure);
            }

            return(Result.Success);
        }
コード例 #21
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            string layer_name = "";
            var    rc         = RhinoGet.GetString("Name of layer to rename", true, ref layer_name);

            if (rc != Result.Success)
            {
                return(rc);
            }
            if (String.IsNullOrWhiteSpace(layer_name))
            {
                return(Result.Nothing);
            }

            // because of sublayers it's possible that more than one layer has the same name
            // so simply calling doc.Layers.Find(layerName) isn't good enough.  If "layerName" returns
            // more than one layer then present them to the user and let him decide.
            var matching_layers = (from layer in doc.Layers
                                   where layer.Name == layer_name
                                   select layer).ToList <Layer>();

            Layer layer_to_rename = null;

            if (matching_layers.Count == 0)
            {
                RhinoApp.WriteLine("Layer \"{0}\" does not exist.", layer_name);
                return(Result.Nothing);
            }
            else if (matching_layers.Count == 1)
            {
                layer_to_rename = matching_layers[0];
            }
            else if (matching_layers.Count > 1)
            {
                for (int i = 0; i < matching_layers.Count; i++)
                {
                    RhinoApp.WriteLine("({0}) {1}", i + 1, matching_layers[i].FullPath.Replace("::", "->"));
                }
                int selected_layer = -1;
                rc = RhinoGet.GetInteger("which layer?", true, ref selected_layer);
                if (rc != Result.Success)
                {
                    return(rc);
                }
                if (selected_layer > 0 && selected_layer <= matching_layers.Count)
                {
                    layer_to_rename = matching_layers[selected_layer - 1];
                }
                else
                {
                    return(Result.Nothing);
                }
            }

            if (layer_to_rename == null)
            {
                return(Result.Nothing);
            }

            layer_name = "";
            rc         = RhinoGet.GetString("New layer name", true, ref layer_name);
            if (rc != Result.Success)
            {
                return(rc);
            }
            if (String.IsNullOrWhiteSpace(layer_name))
            {
                return(Result.Nothing);
            }

            layer_to_rename.Name = layer_name;
            if (!layer_to_rename.CommitChanges())
            {
                return(Result.Failure);
            }
            return(Result.Success);
        }