// 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; }
/// <summary> /// Called by Rhino when the user wants to run this command. /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { System.Guid panelId = SampleCsWpfPanelHost.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(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { System.Guid panelId = PanelTestUserControl.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; }
public static Result ConduitArrowHeads(RhinoDoc doc) { if (m_draw_conduit != null) { RhinoApp.WriteLine("Turn off existing arrowhead conduit"); m_draw_conduit.Enabled = false; m_draw_conduit = null; } else { // get arrow head size var go = new GetOption(); go.SetCommandPrompt("ArrowHead length in screen size (pixels) or world size (percentage of arrow length)?"); go.AddOption("screen"); go.AddOption("world"); go.Get(); if (go.CommandResult() != Result.Success) return go.CommandResult(); int screen_size = 0; double world_size = 0.0; if (go.Option().EnglishName == "screen") { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetCommandPrompt("Length of arrow head in pixels"); gi.Get(); if (gi.CommandResult() != Result.Success) return gi.CommandResult(); screen_size = gi.Number(); } else { var gi = new GetInteger(); gi.SetLowerLimit(0, true); gi.SetUpperLimit(100, false); gi.SetCommandPrompt("Length of arrow head in percentage of total arrow length"); gi.Get(); if (gi.CommandResult() != Result.Success) return gi.CommandResult(); world_size = gi.Number() / 100.0; } // get arrow start and end points var gp = new GetPoint(); gp.SetCommandPrompt("Start of line"); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var start_point = gp.Point(); gp.SetCommandPrompt("End of line"); gp.SetBasePoint(start_point, false); gp.DrawLineFromPoint(start_point, true); gp.Get(); if (gp.CommandResult() != Result.Success) return gp.CommandResult(); var end_point = gp.Point(); var v = end_point - start_point; if (v.IsTiny(Rhino.RhinoMath.ZeroTolerance)) return Result.Nothing; var line = new Line(start_point, end_point); m_draw_conduit = new DrawArrowHeadsConduit(line, screen_size, world_size); // toggle conduit on/off m_draw_conduit.Enabled = true; RhinoApp.WriteLine("Draw arrowheads conduit enabled."); } doc.Views.Redraw(); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // --- Set tolerance _unit = doc.ModelAbsoluteTolerance; // --- Get Mesh var getMesh = new GetObject { GeometryFilter = ObjectType.Mesh }; getMesh.SetCommandPrompt("Select mesh"); while (true) { var getMeshResult = getMesh.Get(); if (getMesh.CommandResult() != Result.Success) return getMesh.CommandResult(); if (getMeshResult == GetResult.Object) break; } _mesh = (Mesh)getMesh.Object(0).Geometry(); doc.Objects.UnselectAll(); // --- Start preview DisplayPipeline.DrawOverlay += DisplayPipelineOnDrawOverlay; // --- Get options var getOptions = new GetOption(); getOptions.SetCommandPrompt("Settings:"); getOptions.AddOptionInteger("CountX", ref _countX); getOptions.AddOptionInteger("CountY", ref _countY); getOptions.AddOptionDouble("Thickness", ref _thickness); getOptions.AddOption("Plane"); getOptions.AddOptionDouble("Deeper", ref _deeper); getOptions.AddOptionToggle("DeleteInput", ref _deleteSource); getOptions.AddOptionToggle("Project", ref _project); getOptions.AddOptionDouble("ProjectSpace", ref _projectSpace); getOptions.AcceptNothing(true); do { doc.Views.Redraw(); getOptions.Get(); switch (getOptions.Result()) { case GetResult.Option: switch (getOptions.Option().EnglishName) { case "Plane": _plane = PlaneGetter.GetPlane() ?? _plane; break; } break; } } while (getOptions.CommandResult() == Result.Success && getOptions.Result() != GetResult.Nothing); // --- Stop preview DisplayPipeline.DrawOverlay -= DisplayPipelineOnDrawOverlay; // --- Check for cancel with ESC if (getOptions.Result() == GetResult.Cancel) return Result.Cancel; // --- Execute var result = Waffle.Create(_mesh, _plane, _thickness.CurrentValue, _deeper.CurrentValue, _countX.CurrentValue, _countY.CurrentValue, _unit, _project.CurrentValue, _projectSpace.CurrentValue); // --- Add objects foreach (var curves in result.CurvesX) doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o))); foreach (var curves in result.CurvesY) doc.Groups.Add(curves.Select(o => doc.Objects.AddCurve(o))); // --- Delete input if (_deleteSource.CurrentValue) doc.Objects.Delete(getMesh.Object(0).ObjectId, true); // --- Update views doc.Views.Redraw(); 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); }