public static Result SetActiveView(RhinoDoc doc)
    {
        // view and view names
        var active_view_name = doc.Views.ActiveView.ActiveViewport.Name;

        var non_active_views =
          doc.Views
          .Where(v => v.ActiveViewport.Name != active_view_name)
          .ToDictionary(v => v.ActiveViewport.Name, v => v);

        // get name of view to set active
        var gs = new GetString();
        gs.SetCommandPrompt("Name of view to set active");
        gs.AcceptNothing(true);
        gs.SetDefaultString(active_view_name);
        foreach (var view_name in non_active_views.Keys)
          gs.AddOption(view_name);
        var result = gs.Get();
        if (gs.CommandResult() != Result.Success)
          return gs.CommandResult();

        var selected_view_name =
          result == GetResult.Option ? gs.Option().EnglishName : gs.StringResult();

        if (selected_view_name != active_view_name)
          if (non_active_views.ContainsKey(selected_view_name))
        doc.Views.ActiveView = non_active_views[selected_view_name];
          else
        RhinoApp.WriteLine("\"{0}\" is not a view name", selected_view_name);

        return Rhino.Commands.Result.Success;
    }
Exemplo n.º 2
0
    public static Result SetActiveView(RhinoDoc doc)
    {
        // view and view names
        var active_view_name = doc.Views.ActiveView.ActiveViewport.Name;

        var non_active_views =
            doc.Views
            .Where(v => v.ActiveViewport.Name != active_view_name)
            .ToDictionary(v => v.ActiveViewport.Name, v => v);

        // get name of view to set active
        var gs = new GetString();

        gs.SetCommandPrompt("Name of view to set active");
        gs.AcceptNothing(true);
        gs.SetDefaultString(active_view_name);
        foreach (var view_name in non_active_views.Keys)
        {
            gs.AddOption(view_name);
        }
        var result = gs.Get();

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

        var selected_view_name =
            result == GetResult.Option ? gs.Option().EnglishName : gs.StringResult();

        if (selected_view_name != active_view_name)
        {
            if (non_active_views.ContainsKey(selected_view_name))
            {
                doc.Views.ActiveView = non_active_views[selected_view_name];
            }
            else
            {
                RhinoApp.WriteLine("\"{0}\" is not a view name", selected_view_name);
            }
        }

        return(Rhino.Commands.Result.Success);
    }
        /// <summary>
        /// Prompts the user for the name of a file to save
        /// </summary>
        private Result GetSaveFileName(string prompt, ref string fileName)
        {
            Result rc = Result.Cancel;

            if (string.IsNullOrEmpty(prompt))
            {
                prompt = "File name";
            }

            GetString gs = new GetString();

            gs.SetCommandPrompt(prompt);
            gs.AddOption(new Rhino.UI.LocalizeStringPair("Browse", "Browse"));

            if (!string.IsNullOrEmpty(fileName))
            {
                gs.SetDefaultString(fileName);
            }

            GetResult res = gs.Get();

            if (res == GetResult.String)
            {
                fileName = gs.StringResult();
                rc       = Result.Success;
            }
            else if (res == GetResult.Option)
            {
                SaveFileDialog fileDialog = new SaveFileDialog();
                fileDialog.Filter = "Text Documents|*.txt";
                fileDialog.Title  = "Save As";
                if (fileDialog.ShowDialog() == DialogResult.OK)
                {
                    fileName = fileDialog.FileName;
                    rc       = Result.Success;
                }
            }

            return(rc);
        }
Exemplo n.º 4
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            Rhino.Input.Custom.GetOption go = new GetOption();
            go.SetCommandPrompt("Set Faro scan settings");

            Rhino.Input.Custom.GetString gs = new GetString();
            gs.SetCommandPrompt("Set Faro IP address.");
            gs.SetDefaultString("127.0.0.1");

            gs.AddOption("Scanner IP");

            gs.Get();

            string val = gs.StringResult();

            Rhino.RhinoApp.WriteLine("IP: " + val);

            // set up the options
            Rhino.Input.Custom.OptionInteger intOption  = new Rhino.Input.Custom.OptionInteger(1, 1, 99);
            Rhino.Input.Custom.OptionDouble  dblOption  = new Rhino.Input.Custom.OptionDouble(2.2, 0, 99.9);
            Rhino.Input.Custom.OptionToggle  boolOption = new Rhino.Input.Custom.OptionToggle(true, "Off", "On");
            string[] resolutionValues  = new string[] { "Full", "Half", "Quarter", "Eighth", "Sixsteenth" };
            string[] measurementValues = new string[] { "Low", "Medium", "High" };
            string[] noiseValues       = new string[] { "Low", "Medium", "High" };


            go.AddOptionInteger("Integer", ref intOption);
            go.AddOptionDouble("Double", ref dblOption);
            go.AddOptionToggle("Boolean", ref boolOption);

            int resolutionIndex  = 2;
            int measurementIndex = 1;
            int noiseIndex       = 1;

            int resolutionList  = go.AddOptionList("Resolution", resolutionValues, resolutionIndex);
            int measurementList = go.AddOptionList("MeasurementRate", measurementValues, measurementIndex);
            int noiseList       = go.AddOptionList("NoiseCompression", noiseValues, noiseIndex);

            while (true)
            {
                // perform the get operation. This will prompt the user to input a point, but also
                // allow for command line options defined above
                Rhino.Input.GetResult get_rc = go.Get();
                Rhino.RhinoApp.WriteLine(get_rc.ToString());

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

                if (get_rc == Rhino.Input.GetResult.Nothing)
                {
                    //doc.Objects.AddPoint(go.Point());
                    doc.Views.Redraw();
                    Rhino.RhinoApp.WriteLine("Command line option values are");
                    Rhino.RhinoApp.WriteLine(" Integer = {0}", intOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Double = {0}", dblOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Boolean = {0}", boolOption.CurrentValue);
                    Rhino.RhinoApp.WriteLine(" Measurement rate = {0}", measurementValues[measurementIndex]);
                    Rhino.RhinoApp.WriteLine(" Resolution = {0}", resolutionValues[resolutionIndex]);
                }
                else if (get_rc == Rhino.Input.GetResult.Option)
                {
                    if (go.OptionIndex() == resolutionList)
                    {
                        resolutionIndex = go.Option().CurrentListOptionIndex;
                    }
                    else if (go.OptionIndex() == measurementList)
                    {
                        measurementIndex = go.Option().CurrentListOptionIndex;
                    }

                    continue;
                }
                break;
            }

            return(Rhino.Commands.Result.Success);
        }