Пример #1
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            var panel_id = Views.UserStringsPanelControl.PanelId;
            var visible  = Panels.IsPanelVisible(panel_id);

            if (mode == RunMode.Scripted)
            {
                var go = new Rhino.Input.Custom.GetOption();
                go.SetCommandPrompt(LOC.STR("Choose document text option"));
                var hide_index   = go.AddOption("Hide");
                var show_index   = go.AddOption("Show");
                var toggle_index = go.AddOption("Toggle");
                go.Get();
                if (go.CommandResult() != Result.Success)
                {
                    return(go.CommandResult());
                }

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

                var index = option.Index;
                if (index == hide_index)
                {
                    if (visible)
                    {
                        Panels.ClosePanel(panel_id);
                    }
                }
                else if (index == show_index)
                {
                    if (!visible)
                    {
                        Panels.OpenPanel(panel_id);
                    }
                }
                else if (index == toggle_index)
                {
                    if (visible)
                    {
                        Panels.ClosePanel(panel_id);
                    }
                    else
                    {
                        Panels.OpenPanel(panel_id);
                    }
                }
            }
            else
            {
                Panels.OpenPanel(panel_id);
            }



            return(Result.Success);
        }
Пример #2
0
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            System.Guid panelId  = SampleCsPanelUserControl.PanelId;
            bool        bVisible = Rhino.UI.Panels.IsPanelVisible(panelId);

            string prompt = (bVisible)
        ? "Sample panel is visible. New value"
        : "Sample Manager panel is hidden. New value";

            Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
            int hide_index   = go.AddOption("Hide");
            int show_index   = go.AddOption("Show");
            int toggle_index = go.AddOption("Toggle");

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

            Rhino.Input.Custom.CommandLineOption option = go.Option();
            if (null == option)
            {
                return(Rhino.Commands.Result.Failure);
            }

            int index = option.Index;

            if (index == hide_index)
            {
                if (bVisible)
                {
                    Rhino.UI.Panels.ClosePanel(panelId);
                }
            }
            else if (index == show_index)
            {
                if (!bVisible)
                {
                    Rhino.UI.Panels.OpenPanel(panelId);
                }
            }
            else if (index == toggle_index)
            {
                if (bVisible)
                {
                    Rhino.UI.Panels.ClosePanel(panelId);
                }
                else
                {
                    Rhino.UI.Panels.OpenPanel(panelId);
                }
            }

            return(Rhino.Commands.Result.Success);
        }
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            System.Guid panelId = SampleCsPanelUserControl.PanelId;
              bool bVisible = Rhino.UI.Panels.IsPanelVisible(panelId);

              string prompt = (bVisible)
            ? "Sample panel is visible. New value"
            : "Sample Manager panel is hidden. New value";

              Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
              int hide_index = go.AddOption("Hide");
              int show_index = go.AddOption("Show");
              int toggle_index = go.AddOption("Toggle");

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

              Rhino.Input.Custom.CommandLineOption option = go.Option();
              if (null == option)
            return Rhino.Commands.Result.Failure;

              int index = option.Index;

              if (index == hide_index)
              {
            if (bVisible)
              Rhino.UI.Panels.ClosePanel(panelId);
              }
              else if (index == show_index)
              {
            if (!bVisible)
              Rhino.UI.Panels.OpenPanel(panelId);
              }
              else if (index == toggle_index)
              {
            if (bVisible)
              Rhino.UI.Panels.ClosePanel(panelId);
            else
              Rhino.UI.Panels.OpenPanel(panelId);
              }

              return Rhino.Commands.Result.Success;
        }
        protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode)
        {
            var panel_id = Views.SampleCsEtoPanel.PanelId;
              var visible = Rhino.UI.Panels.IsPanelVisible(panel_id);

              var prompt = (visible)
            ? "Sample panel is visible. New value"
            : "Sample panel is hidden. New value";

              var go = new Rhino.Input.Custom.GetOption();
              go.SetCommandPrompt(prompt);
              var hide_index = go.AddOption("Hide");
              var show_index = go.AddOption("Show");
              var toggle_index = go.AddOption("Toggle");
              go.Get();
              if (go.CommandResult() != Rhino.Commands.Result.Success)
            return go.CommandResult();

              var option = go.Option();
              if (null == option)
            return Rhino.Commands.Result.Failure;

              var index = option.Index;
              if (index == hide_index)
              {
            if (visible)
              Rhino.UI.Panels.ClosePanel(panel_id);
              }
              else if (index == show_index)
              {
            if (!visible)
              Rhino.UI.Panels.OpenPanel(panel_id);
              }
              else if (index == toggle_index)
              {
            if (visible)
              Rhino.UI.Panels.ClosePanel(panel_id);
            else
              Rhino.UI.Panels.OpenPanel(panel_id);
              }

              return Rhino.Commands.Result.Success;
        }
        private bool SetPageUnit(RhinoDoc doc)
        {
            bool result = false;

            try
            {
                Rhino.Input.Custom.GetOption getOption = new Rhino.Input.Custom.GetOption();
                getOption.SetCommandPrompt("Set Page Units");

                foreach (string unit in optionValues)
                {
                    getOption.AddOption(unit);
                }

                getOption.Get();
                if (getOption.CommandResult() != Rhino.Commands.Result.Success)
                {
                    return(false);
                }

                string selectedUnit = getOption.Option().EnglishName;
                switch (selectedUnit)
                {
                case "Inch":
                    doc.AdjustPageUnitSystem(UnitSystem.Inches, true);
                    break;

                case "Foot":
                    doc.AdjustPageUnitSystem(UnitSystem.Feet, true);
                    break;

                case "Millimeter":
                    doc.AdjustPageUnitSystem(UnitSystem.Millimeters, true);
                    break;

                case "Centimeter":
                    doc.AdjustPageUnitSystem(UnitSystem.Centimeters, true);
                    break;

                case "Meter":
                    doc.AdjustPageUnitSystem(UnitSystem.Meters, true);
                    break;
                }

                doc.Views.Redraw();
                result = true;
            }
            catch (Exception ex)
            {
                string message = ex.Message;
            }
            return(result);
        }
Пример #6
0
        private void GetNestingSettings()
        {
            //Parameters
            Rhino.Input.Custom.GetOption gp = new Rhino.Input.Custom.GetOption();
            gp.SetCommandPrompt("OpenNest: Set nesting settings");

            Rhino.Input.Custom.OptionInteger Iterations     = new Rhino.Input.Custom.OptionInteger(1, 1, 100);
            Rhino.Input.Custom.OptionDouble  Spacing        = new Rhino.Input.Custom.OptionDouble(0.01, 0.001, 10);
            Rhino.Input.Custom.OptionInteger Placement      = new Rhino.Input.Custom.OptionInteger(1, 0, 4);
            Rhino.Input.Custom.OptionDouble  Tolerance      = new Rhino.Input.Custom.OptionDouble(0.1, 0.01, 10);
            Rhino.Input.Custom.OptionInteger Rotations      = new Rhino.Input.Custom.OptionInteger(4, 0, 360);
            Rhino.Input.Custom.OptionInteger Seed           = new Rhino.Input.Custom.OptionInteger(0, 1, 100);
            Rhino.Input.Custom.OptionDouble  ClosestObjects = new Rhino.Input.Custom.OptionDouble(0.01, 0, 100);

            gp.AddOptionInteger("Iterations", ref Iterations);
            gp.AddOptionDouble("Spacing", ref Spacing);
            gp.AddOptionInteger("Placement", ref Placement);
            gp.AddOptionDouble("Tolerance", ref Tolerance);
            gp.AddOptionInteger("Rotations", ref Rotations);
            gp.AddOptionInteger("Seed", ref Seed);
            gp.AddOptionDouble("ClosestObjects", ref ClosestObjects);

            while (true)
            {
                Rhino.Input.GetResult get_rc = gp.Get();
                if (gp.CommandResult() != Rhino.Commands.Result.Success)
                {
                    break;
                }
            }

            this.iterations    = Iterations.CurrentValue;
            this.spacing       = Spacing.CurrentValue;
            this.placementType = Placement.CurrentValue;
            this.tolerance     = Tolerance.CurrentValue;
            this.rotations     = Rotations.CurrentValue;
            this.seed          = Seed.CurrentValue;
            this.spacing      *= (1 / tolerance);
            this.cp            = ClosestObjects.CurrentValue;
        }
Пример #7
0
        protected override Result RunCommand(RhinoDoc doc, RunMode mode)
        {
            // Pick some objects to smooth
            Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject();
            go.SetCommandPrompt("Select objects to smooth");
            go.SubObjectSelect       = false;
            go.ReferenceObjectSelect = false;
            go.GeometryFilter        = Rhino.DocObjects.ObjectType.Curve | Rhino.DocObjects.ObjectType.Surface | Rhino.DocObjects.ObjectType.Mesh;
            go.GetMultiple(1, 0);
            if (go.CommandResult() != Result.Success)
            {
                return(go.CommandResult());
            }

            // Prompt for some command line options. In this case,
            // we will clone the -Smooth command.
            Rhino.Input.Custom.GetOption gs = new Rhino.Input.Custom.GetOption();
            gs.SetCommandPrompt("Choose smooth option");
            gs.AcceptNothing(true);
            for (; ;)
            {
                gs.ClearCommandOptions();

                Rhino.Input.Custom.OptionDouble smooth_factor_option  = new Rhino.Input.Custom.OptionDouble(m_smooth_factor);
                Rhino.Input.Custom.OptionToggle use_cplane_option     = new Rhino.Input.Custom.OptionToggle(m_use_cplane, "World", "CPlane");
                Rhino.Input.Custom.OptionToggle smooth_x_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_x, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_y_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_y, "No", "Yes");
                Rhino.Input.Custom.OptionToggle smooth_z_option       = new Rhino.Input.Custom.OptionToggle(m_smooth_z, "No", "Yes");
                Rhino.Input.Custom.OptionToggle fix_boundaries_option = new Rhino.Input.Custom.OptionToggle(m_fix_boundaries, "No", "Yes");

                int smooth_factor_index  = gs.AddOptionDouble("SmoothFactor", ref smooth_factor_option);
                int use_cplane_index     = gs.AddOptionToggle("CoordinateSystem", ref use_cplane_option);
                int smooth_x_index       = gs.AddOptionToggle("X", ref smooth_x_option);
                int smooth_y_index       = gs.AddOptionToggle("Y", ref smooth_y_option);
                int smooth_z_index       = gs.AddOptionToggle("Z", ref smooth_z_option);
                int fix_boundaries_index = gs.AddOptionToggle("FixBoundaries", ref fix_boundaries_option);

                Rhino.Input.GetResult getrc = gs.Get();
                if (gs.CommandResult() != Result.Success)
                {
                    return(gs.CommandResult());
                }

                if (getrc == Rhino.Input.GetResult.Option)
                {
                    int index = gs.OptionIndex();
                    if (index == smooth_factor_index)
                    {
                        m_smooth_factor = smooth_factor_option.CurrentValue;
                    }
                    else if (index == use_cplane_index)
                    {
                        m_use_cplane = use_cplane_option.CurrentValue;
                    }
                    else if (index == smooth_x_index)
                    {
                        m_smooth_x = smooth_x_option.CurrentValue;
                    }
                    else if (index == smooth_y_index)
                    {
                        m_smooth_y = smooth_y_option.CurrentValue;
                    }
                    else if (index == smooth_z_index)
                    {
                        m_smooth_z = smooth_z_option.CurrentValue;
                    }
                    else if (index == fix_boundaries_index)
                    {
                        m_fix_boundaries = fix_boundaries_option.CurrentValue;
                    }

                    continue;
                }

                break;
            }

            // Build a command line macro that we can script
            StringBuilder sb = new StringBuilder();

            sb.Append("_-Smooth ");
            sb.Append(string.Format("_SmoothFactor={0} ", m_smooth_factor));
            sb.Append(string.Format("_CoordinateSystem={0} ", m_use_cplane ? "_CPlane" : "_World"));
            sb.Append(string.Format("_X={0} ", m_smooth_x ? "_Yes" : "_No"));
            sb.Append(string.Format("_Y={0} ", m_smooth_y ? "_Yes" : "_No"));
            sb.Append(string.Format("_Z={0} ", m_smooth_z ? "_Yes" : "_No"));
            sb.Append(string.Format("_FixBoundaries={0} ", m_fix_boundaries ? "_Yes" : "_No"));
            sb.Append("_Enter");

            string script = sb.ToString();

#if (!RELEASE)
            Rhino.RhinoApp.WriteLine(script);
#endif

            // Script the smooth command
            Rhino.RhinoApp.RunScript(script, false);

            return(Result.Success);
        }
    // The following example code demonstrates how to modify advanced display settings using
    // the Rhino SDK. In this example, a display mode's mesh wireframe thickness (in pixels)
    // will be modified.
    public static Rhino.Commands.Result AdvancedDisplay(Rhino.RhinoDoc doc)
    {
        // Use the display attributes manager to build a list of display modes.
        // Note, these are copies of the originals...
        DisplayModeDescription[] display_modes = DisplayModeDescription.GetDisplayModes();
        if (display_modes == null || display_modes.Length < 1)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Construct an options picker so the user can pick which
        // display mode they want modified
        Rhino.Input.Custom.GetOption go = new Rhino.Input.Custom.GetOption();
        go.SetCommandPrompt("Display mode to modify mesh thickness");
        List <int> opt_list = new List <int>();

        for (int i = 0; i < display_modes.Length; i++)
        {
            string english_name = display_modes[i].EnglishName;
            english_name = english_name.Replace("_", "");
            english_name = english_name.Replace(" ", "");
            english_name = english_name.Replace("-", "");
            english_name = english_name.Replace(",", "");
            english_name = english_name.Replace(".", "");
            int index = go.AddOption(english_name);
            opt_list.Add(index);
        }

        // Get the command option
        go.Get();
        if (go.CommandResult() != Rhino.Commands.Result.Success)
        {
            return(go.CommandResult());
        }

        int selected_index = go.Option().Index;
        DisplayModeDescription selected_description = null;

        for (int i = 0; i < opt_list.Count; i++)
        {
            if (opt_list[i] == selected_index)
            {
                selected_description = display_modes[i];
                break;
            }
        }

        // Validate...
        if (selected_description == null)
        {
            return(Rhino.Commands.Result.Failure);
        }

        // Modify the desired display mode. In this case, we
        // will just set the mesh wireframe thickness to zero.
        selected_description.DisplayAttributes.MeshSpecificAttributes.MeshWireThickness = 0;
        // Use the display attributes manager to update the display mode.
        DisplayModeDescription.UpdateDisplayMode(selected_description);

        // Force the document to regenerate.
        doc.Views.Redraw();
        return(Rhino.Commands.Result.Success);
    }
Пример #9
0
 /// <summary>Easy to use bool getter.</summary>
 /// <param name="prompt">Command prompt.</param>
 /// <param name="acceptNothing">If true, the user can press enter.</param>
 /// <param name="offPrompt">The 'false/off' message.</param>
 /// <param name="onPrompt">The 'true/on' message.</param>
 /// <param name="boolValue">Default bool value set to this and returned here.</param>
 /// <returns>The getter result based on user choice.
 /// <para>Commands.Result.Success - got value.</para>
 /// <para>Commands.Result.Nothing - user pressed enter.</para>
 /// <para>Commands.Result.Cancel - user cancelled value getting.</para>
 /// </returns>
 public static Commands.Result GetBool(string prompt, bool acceptNothing, string offPrompt, string onPrompt, ref bool boolValue)
 {
   Commands.Result result = Commands.Result.Failure;
   using (Rhino.Input.Custom.GetOption get = new Rhino.Input.Custom.GetOption())
   {
     get.SetCommandPrompt(prompt);
     get.AcceptNothing(acceptNothing);
     if (acceptNothing)
       get.SetDefaultString(boolValue ? onPrompt : offPrompt);
     int onValue = get.AddOption(onPrompt);
     int offValue = get.AddOption(offPrompt);
     get.Get();
     result = get.CommandResult();
     if (result == Commands.Result.Success && get.Result() == GetResult.Option)
     {
       Rhino.Input.Custom.CommandLineOption option = get.Option();
       if (null != option)
       {
         if (option.Index == onValue)
           boolValue = true;
         else if (option.Index == offValue)
           boolValue = false;
       }
     }
   }
   return result;
 }