public static Rhino.Commands.Result SpriteDrawing(RhinoDoc doc) { var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite"); var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size); var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World"); var go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Sprite drawing mode"); go.AddOptionToggle("Mode", ref sprite_mode); go.AddOptionDouble("Size", ref size_option); go.AddOptionToggle("DrawSpace", ref space_option); int option_go = go.AddOption("Spin"); int option_file = go.AddOption("FileSprite"); Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; doc.Views.Redraw(); while (go.Get() == Rhino.Input.GetResult.Option) { m_draw_single_sprite = sprite_mode.CurrentValue; m_sprite_size = (float)size_option.CurrentValue; m_draw_world_location = space_option.CurrentValue; if (go.OptionIndex() == option_go) { var gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("press enter/escape to end"); gs.SetWaitDuration(1); var vp = doc.Views.ActiveView.MainViewport; while (gs.Get() == Rhino.Input.GetResult.Timeout) { vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin); doc.Views.Redraw(); } } else if (go.OptionIndex() == option_file) { var dlg = new Rhino.UI.OpenFileDialog(); if (dlg.ShowDialog()) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName); m_sprite = new Rhino.Display.DisplayBitmap(bmp); } doc.Views.Redraw(); } else { doc.Views.Redraw(); } } Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox; return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { var sprite_mode = new Rhino.Input.Custom.OptionToggle(m_draw_single_sprite, "SpriteList", "SingleSprite"); var size_option = new Rhino.Input.Custom.OptionDouble(m_sprite_size); var space_option = new Rhino.Input.Custom.OptionToggle(m_draw_world_location, "Screen", "World"); var go = new Rhino.Input.Custom.GetOption(); go.SetCommandPrompt("Sprite drawing mode"); go.AddOptionToggle("Mode", ref sprite_mode); go.AddOptionDouble("Size", ref size_option); go.AddOptionToggle("DrawSpace", ref space_option); int option_go = go.AddOption("Spin"); int option_file = go.AddOption("FileSprite"); Rhino.Display.DisplayPipeline.PostDrawObjects += DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox += DisplayPipeline_CalculateBoundingBox; doc.Views.Redraw(); while (go.Get() == Rhino.Input.GetResult.Option) { m_draw_single_sprite = sprite_mode.CurrentValue; m_sprite_size = (float)size_option.CurrentValue; m_draw_world_location = space_option.CurrentValue; if (go.OptionIndex() == option_go) { var gs = new Rhino.Input.Custom.GetOption(); gs.SetCommandPrompt("press enter/escape to end"); gs.SetWaitDuration(1); var vp = doc.Views.ActiveView.MainViewport; while (gs.Get() == Rhino.Input.GetResult.Timeout) { vp.Rotate(0.1, Vector3d.ZAxis, Point3d.Origin); doc.Views.Redraw(); } } else if (go.OptionIndex() == option_file) { System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog(); if (dlg.ShowDialog(RhinoApp.MainWindow()) == System.Windows.Forms.DialogResult.OK) { System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(dlg.FileName); m_sprite = new Rhino.Display.DisplayBitmap(bmp); } doc.Views.Redraw(); } else doc.Views.Redraw(); } Rhino.Display.DisplayPipeline.PostDrawObjects -= DisplayPipeline_PostDrawObjects; Rhino.Display.DisplayPipeline.CalculateBoundingBox -= DisplayPipeline_CalculateBoundingBox; return Rhino.Commands.Result.Success; }
public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("GetPoint with options"); // 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[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" }; gp.AddOptionInteger("Integer", ref intOption); gp.AddOptionDouble("Double", ref dblOption); gp.AddOptionToggle("Boolean", ref boolOption); int listIndex = 3; int opList = gp.AddOptionList("List", listValues, listIndex); 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 = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) { return(gp.CommandResult()); } if (get_rc == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.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(" List = {0}", listValues[listIndex]); } else if (get_rc == Rhino.Input.GetResult.Option) { if (gp.OptionIndex() == opList) { listIndex = gp.Option().CurrentListOptionIndex; } continue; } break; } return(Rhino.Commands.Result.Success); }
public static Rhino.Commands.Result CommandLineOptions(Rhino.RhinoDoc doc) { // For this example we will use a GetPoint class, but all of the custom // "Get" classes support command line options. Rhino.Input.Custom.GetPoint gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("GetPoint with options"); // 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[] listValues = new string[] { "Item0", "Item1", "Item2", "Item3", "Item4" }; gp.AddOptionInteger("Integer", ref intOption); gp.AddOptionDouble("Double", ref dblOption); gp.AddOptionToggle("Boolean", ref boolOption); int listIndex = 3; int opList = gp.AddOptionList("List", listValues, listIndex); 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 = gp.Get(); if (gp.CommandResult() != Rhino.Commands.Result.Success) return gp.CommandResult(); if (get_rc == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.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(" List = {0}", listValues[listIndex]); } else if (get_rc == Rhino.Input.GetResult.Option) { if (gp.OptionIndex() == opList) listIndex = gp.Option().CurrentListOptionIndex; continue; } break; } return Rhino.Commands.Result.Success; }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { // Select objects to scale var list = new Rhino.Collections.TransformObjectList(); var rc = SelectObjects("Select objects to scale", list); if (rc != Rhino.Commands.Result.Success) { return(rc); } Point3d anchor; Point3d _ref; Plane plane; // Origin point var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Origin point"); var copy = new Rhino.Input.Custom.OptionToggle(m_copy, "No", "Yes"); gp.AddOptionToggle("Copy", ref copy); for (; ;) { var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { var view = gp.View(); if (view == null) { return(Rhino.Commands.Result.Failure); } plane = view.ActiveViewport.ConstructionPlane(); anchor = gp.Point(); break; } if (res == Rhino.Input.GetResult.Option) { continue; } return(Rhino.Commands.Result.Cancel); } bool bAcceptDefault = true; // Scale factor or first reference point gp.SetCommandPrompt("Scale factor or first reference point"); gp.SetBasePoint(anchor, true); gp.DrawLineFromPoint(anchor, true); gp.ConstrainToConstructionPlane(true); for (; ;) { if (bAcceptDefault) { gp.AcceptNumber(true, false); gp.SetDefaultNumber(m_scale); } else { gp.AcceptNothing(true); gp.ClearDefault(); } var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { _ref = gp.Point(); break; } if (res == Rhino.Input.GetResult.Number) { double scale = Math.Abs(gp.Number()); const double EPS_DIVIDE = 0.000001; if (scale < EPS_DIVIDE) { continue; } m_scale = scale; plane.Origin = anchor; var xform = Transform.Scale(plane, m_scale, m_scale, m_scale); TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); m_copy = copy.CurrentValue; if (m_copy) { bAcceptDefault = false; continue; } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } if (res == Rhino.Input.GetResult.Nothing) { if (bAcceptDefault == false) { return(Rhino.Commands.Result.Success); } plane.Origin = anchor; var xform = Transform.Scale(plane, m_scale, m_scale, m_scale); TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); m_copy = copy.CurrentValue; if (m_copy) { bAcceptDefault = false; continue; } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); } if (res == Rhino.Input.GetResult.Option) { continue; } return(Rhino.Commands.Result.Cancel); } // Second reference point var gx = new GetScaleXform(); gx.SetCommandPrompt("Second reference point"); gx.AddOptionToggle("copy", ref copy); gx.AddTransformObjects(list); gx.SetBasePoint(anchor, true); gx.DrawLineFromPoint(anchor, true); gx.ConstrainToConstructionPlane(true); gx.Plane = plane; gx.RefPoint = _ref; gx.AcceptNothing(true); gx.AcceptNumber(true, false); rc = Rhino.Commands.Result.Cancel; for (; ;) { var res = gx.GetXform(); if (res == Rhino.Input.GetResult.Point) { var view = gx.View(); if (view == null) { rc = Rhino.Commands.Result.Failure; break; } var xform = gx.CalculateTransform(view.ActiveViewport, gx.Point()); if (xform.IsValid && xform != Transform.Identity) { TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); rc = Rhino.Commands.Result.Success; m_scale = gx.Scale; } m_copy = copy.CurrentValue; if (m_copy) { continue; } break; } if (res == Rhino.Input.GetResult.Number) { var view = gx.View(); if (view == null) { rc = Rhino.Commands.Result.Failure; break; } var xform = gx.CalculateTransform(view.ActiveViewport, gx.Number()); if (xform.IsValid && xform != Transform.Identity) { TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); rc = Rhino.Commands.Result.Success; m_scale = gx.Scale; } m_copy = copy.CurrentValue; if (m_copy) { continue; } break; } if (res == Rhino.Input.GetResult.Option) { continue; } break; } doc.Views.Redraw(); return(rc); }
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); }
/// <summary> /// Executes the platonic command /// </summary> protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { // Get the platonic geometry Rhino.Geometry.Brep[] faces = Platonic.Faces(); if (null == faces) { return(Rhino.Commands.Result.Failure); } // Prompt for center point string prompt = string.Format("Center of {0}", Platonic.DisplayName.ToLower()); Rhino.Geometry.Point3d origin; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetPoint(prompt, false, out origin); if (rc != Rhino.Commands.Result.Success) { return(rc); } double length = m_length; bool create_solid = m_create_solid; bool group_faces = m_group_faces; // Prompt for edge length PlatonicGetPoint get = new PlatonicGetPoint(faces, origin); get.SetCommandPrompt(Platonic.Prompt); get.SetDefaultNumber(length); get.SetBasePoint(origin, true); get.DrawLineFromPoint(origin, true); get.AcceptNumber(true, false); Rhino.Geometry.Transform xform = new Rhino.Geometry.Transform(1.0); rc = Rhino.Commands.Result.Cancel; for (; ;) { get.ClearCommandOptions(); Rhino.Input.Custom.OptionToggle output_toggle = null; Rhino.Input.Custom.OptionToggle group_toggle = null; output_toggle = new Rhino.Input.Custom.OptionToggle(create_solid, "Faces", "Solid"); get.AddOptionToggle("Output", ref output_toggle); if (!create_solid) { group_toggle = new Rhino.Input.Custom.OptionToggle(group_faces, "No", "Yes"); get.AddOptionToggle("Group", ref group_toggle); } Rhino.Input.GetResult res = get.Get(); if (res == Rhino.Input.GetResult.Point) { if (get.CalculateTransform(get.View().ActiveViewport, get.Point(), ref xform)) { m_length = get.Length; rc = Rhino.Commands.Result.Success; break; } } else if (res == Rhino.Input.GetResult.Number) { length = System.Math.Abs(get.Number()); if (get.CalculateTransform(get.View().ActiveViewport, length, ref xform)) { m_length = get.Length; rc = Rhino.Commands.Result.Success; break; } } else if (res == Rhino.Input.GetResult.Option) { if (null != output_toggle && create_solid != output_toggle.CurrentValue) { create_solid = output_toggle.CurrentValue; } if (null != group_toggle && group_faces != group_toggle.CurrentValue) { group_faces = group_toggle.CurrentValue; } continue; } else { break; } } // If we got here, then we have the center point and edge length, // any any command options. Time to add the geomtry to the document. if (rc == Rhino.Commands.Result.Success && xform.IsValid) { m_create_solid = create_solid; m_group_faces = group_faces; Rhino.DocObjects.ObjectAttributes attribs = doc.CreateDefaultAttributes(); attribs.Name = Platonic.Name; attribs.WireDensity = 0; // solid looks "nicer" with wires turned off... if (m_create_solid) { Rhino.Geometry.Brep[] breps = Rhino.Geometry.Brep.JoinBreps(faces, 2.1 * doc.ModelAbsoluteTolerance); foreach (Brep t in breps) { if (null == t) { continue; } t.Transform(xform); doc.Objects.AddBrep(t, attribs, null, false, false); } } else { if (m_group_faces) { attribs.AddToGroup(doc.Groups.Add()); } foreach (Brep t in faces) { if (null == t) { continue; } t.Transform(xform); doc.Objects.AddBrep(t, attribs, null, false, false); } } doc.Views.Redraw(); } return(Rhino.Commands.Result.Success); }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { Rhino.DocObjects.ObjRef objref; var rc = Rhino.Input.RhinoGet.GetOneObject("Select object", true, Rhino.DocObjects.ObjectType.AnyObject, out objref); if (rc != Rhino.Commands.Result.Success) { return(rc); } rc = Rhino.Input.RhinoGet.GetPoint("Start point", false, out m_point_start); if (rc != Rhino.Commands.Result.Success) { return(rc); } var obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } // create an instance of a GetPoint class and add a delegate // for the DynamicDraw event var gp = new Rhino.Input.Custom.GetPoint(); gp.DrawLineFromPoint(m_point_start, true); var optdouble = new Rhino.Input.Custom.OptionDouble(m_distance); bool constrain = false; var optconstrain = new Rhino.Input.Custom.OptionToggle(constrain, "Off", "On"); gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); gp.DynamicDraw += ArrayByDistanceDraw; gp.Tag = obj; while (gp.Get() == Rhino.Input.GetResult.Option) { m_distance = optdouble.CurrentValue; if (constrain != optconstrain.CurrentValue) { constrain = optconstrain.CurrentValue; if (constrain) { var gp2 = new Rhino.Input.Custom.GetPoint(); gp2.DrawLineFromPoint(m_point_start, true); gp2.SetCommandPrompt("Second point on constraint line"); if (gp2.Get() == Rhino.Input.GetResult.Point) { gp.Constrain(m_point_start, gp2.Point()); } else { gp.ClearCommandOptions(); optconstrain.CurrentValue = false; constrain = false; gp.AddOptionDouble("Distance", ref optdouble); gp.AddOptionToggle("Constrain", ref optconstrain); } } else { gp.ClearConstraints(); } } } if (gp.CommandResult() == Rhino.Commands.Result.Success) { m_distance = optdouble.CurrentValue; var pt = gp.Point(); var vec = pt - m_point_start; double length = vec.Length; vec.Unitize(); int count = (int)(length / m_distance); for (int i = 1; i < count; i++) { var translate = vec * (i * m_distance); var xf = Rhino.Geometry.Transform.Translation(translate); doc.Objects.Transform(obj, xf, false); } doc.Views.Redraw(); } return(gp.CommandResult()); }
/// <summary> /// Called when the command is in scripted mode /// </summary> /// <param name="model"></param> /// <returns></returns> static Result RunScript(TextViewModel model) { var height = new Rhino.Input.Custom.OptionDouble(model.textHeight); var bold = new Rhino.Input.Custom.OptionToggle(model.bold, Localization.LocalizeCommandOptionValue("No", 396), Localization.LocalizeCommandOptionValue("Yes", 397)); var italic = new Rhino.Input.Custom.OptionToggle(model.italic, Localization.LocalizeCommandOptionValue("No", 398), Localization.LocalizeCommandOptionValue("Yes", 399)); var mask = new Rhino.Input.Custom.OptionToggle(model.maskEnabled, Localization.LocalizeCommandOptionValue("No", 400), Localization.LocalizeCommandOptionValue("Yes", 401)); var masksource = new Rhino.Input.Custom.OptionToggle(model.maskUsesViewportColor, Localization.LocalizeCommandOptionValue("No", 402), Localization.LocalizeCommandOptionValue("Yes", 403)); var maskcolor = new Rhino.Input.Custom.OptionColor(model.maskColor); var maskborder = new Rhino.Input.Custom.OptionDouble(model.maskOffset, true, 0); string facename = model.Font.FaceName; string newtext = ""; var go = new Rhino.Input.Custom.GetString(); var get_rc = Rhino.Input.GetResult.Cancel; var rc = Rhino.Commands.Result.Cancel; while (get_rc != Rhino.Input.GetResult.Nothing && get_rc != Rhino.Input.GetResult.String) { go.ClearCommandOptions(); go.AcceptNothing(true); go.SetCommandPrompt(LOC.STR("Text string")); int faceopt = go.AddOption(LOC.CON("Font")); go.AddOptionDouble(LOC.CON("Height"), ref height, LOC.STR("Text height")); go.AddOptionToggle(LOC.CON("Italic"), ref italic); go.AddOptionToggle(LOC.CON("Mask"), ref mask); go.AddOptionToggle(LOC.CON("UseBackgroundColor"), ref masksource); go.AddOptionColor(LOC.CON("MaskColor"), ref maskcolor); go.AddOptionDouble(LOC.CON("MaskMargin"), ref maskborder); get_rc = go.Get(); switch (get_rc) { case Rhino.Input.GetResult.Cancel: return Rhino.Commands.Result.Cancel; case Rhino.Input.GetResult.String: newtext = go.StringResult(); break; case Rhino.Input.GetResult.Option: if( go.OptionIndex() == faceopt ) { string oldname = facename; rc = Rhino.Input.RhinoGet.GetString(LOC.STR("Font name"), true, ref facename); if( rc!=Rhino.Commands.Result.Success) return rc; if (string.IsNullOrWhiteSpace(facename)) facename = oldname; } break; } } if (string.IsNullOrWhiteSpace(newtext)) return Rhino.Commands.Result.Cancel; // update default settings model.text = newtext; int fontindex = model.Doc.Fonts.FindOrCreate(facename, bold.CurrentValue, italic.CurrentValue); model.fontIndex = fontindex; model.textHeight = height.CurrentValue; model.maskEnabled = mask.CurrentValue; model.maskUsesViewportColor = masksource.CurrentValue; model.maskColor = maskcolor.CurrentValue; model.maskOffset = maskborder.CurrentValue; return Result.Success; }
protected override Rhino.Commands.Result RunCommand(RhinoDoc doc, Rhino.Commands.RunMode mode) { // Select objects to scale var list = new Rhino.Collections.TransformObjectList(); var rc = SelectObjects("Select objects to scale", list); if (rc != Rhino.Commands.Result.Success) return rc; var anchor = new Point3d(); var _ref = new Point3d(); Plane plane = new Plane(); // Origin point var gp = new Rhino.Input.Custom.GetPoint(); gp.SetCommandPrompt("Origin point"); var copy = new Rhino.Input.Custom.OptionToggle(m_copy,"No", "Yes"); gp.AddOptionToggle("Copy", ref copy); for (; ; ) { var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { var view = gp.View(); if (view == null) return Rhino.Commands.Result.Failure; plane = view.ActiveViewport.ConstructionPlane(); anchor = gp.Point(); break; } if (res == Rhino.Input.GetResult.Option) continue; return Rhino.Commands.Result.Cancel; } bool bAcceptDefault = true; // Scale factor or first reference point gp.SetCommandPrompt("Scale factor or first reference point"); gp.SetBasePoint(anchor, true); gp.DrawLineFromPoint(anchor, true); gp.ConstrainToConstructionPlane(true); for (; ; ) { if (bAcceptDefault) { gp.AcceptNumber(true, false); gp.SetDefaultNumber(m_scale); } else { gp.AcceptNothing(true); gp.ClearDefault(); } var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { _ref = gp.Point(); break; } if (res == Rhino.Input.GetResult.Number) { double scale = Math.Abs(gp.Number()); const double EPS_DIVIDE = 0.000001; if (scale < EPS_DIVIDE) continue; m_scale = scale; plane.Origin = anchor; var xform = Transform.Scale(plane, m_scale, m_scale, m_scale); TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); m_copy = copy.CurrentValue; if (m_copy) { bAcceptDefault = false; continue; } doc.Views.Redraw(); return Rhino.Commands.Result.Success; } if (res == Rhino.Input.GetResult.Nothing) { if (bAcceptDefault == false) return Rhino.Commands.Result.Success; plane.Origin = anchor; var xform = Transform.Scale(plane, m_scale, m_scale, m_scale); TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); m_copy = copy.CurrentValue; if (m_copy) { bAcceptDefault = false; continue; } doc.Views.Redraw(); return Rhino.Commands.Result.Success; } if (res == Rhino.Input.GetResult.Option) continue; return Rhino.Commands.Result.Cancel; } // Second reference point var gx = new GetScaleXform(); gx.SetCommandPrompt("Second reference point"); gx.AddOptionToggle("copy", ref copy); gx.AddTransformObjects(list); gx.SetBasePoint(anchor, true); gx.DrawLineFromPoint(anchor, true); gx.ConstrainToConstructionPlane(true); gx.Plane = plane; gx.RefPoint = _ref; gx.AcceptNothing(true); gx.AcceptNumber(true, false); rc = Rhino.Commands.Result.Cancel; for (; ; ) { var res = gx.GetXform(); if (res == Rhino.Input.GetResult.Point) { var view = gx.View(); if (view == null) { rc = Rhino.Commands.Result.Failure; break; } var xform = gx.CalculateTransform(view.ActiveViewport, gx.Point()); if (xform.IsValid && xform != Transform.Identity) { TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); rc = Rhino.Commands.Result.Success; m_scale = gx.Scale; } m_copy = copy.CurrentValue; if (m_copy) continue; break; } if (res == Rhino.Input.GetResult.Number) { var view = gx.View(); if (view == null) { rc = Rhino.Commands.Result.Failure; break; } var xform = gx.CalculateTransform(view.ActiveViewport, gx.Number()); if (xform.IsValid && xform != Transform.Identity) { TransformObjects(list, xform, copy.CurrentValue, copy.CurrentValue); rc = Rhino.Commands.Result.Success; m_scale = gx.Scale; } m_copy = copy.CurrentValue; if (m_copy) continue; break; } if (res == Rhino.Input.GetResult.Option) continue; if (res == Rhino.Input.GetResult.Nothing) break; break; } doc.Views.Redraw(); return rc; }