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) { 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()); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Get a polyframe // Get a new point // Create the pipes and lines in the new location // the lines will be from an edge container of the PolyFrame // The pipes will be added extra. This will allow for the pipes to be used as a PolyFrame var primal = new PFoam(); var dual = new PFoam(); try { var guids = LoadData.LoadPrimalDual(out primal, out dual, out ContainerType container); if (primal.Cells.Count < 1) { Rhino.RhinoApp.WriteLine("Error loading PolyFrame from provided data!"); return(Result.Failure); } var form = primal.Edges.Where(e => e.Id > 0).Any(x => x.Faces.Count < 2); if (dual.Cells.Count < 1) { RhinoApp.WriteLine("Could not load dual from the selected PolyFrame."); return(Result.Failure); } double minLen; double maxLen; var pipePolyFrame = new PFoam(); if (form) { pipePolyFrame = primal; } else { pipePolyFrame = dual; } var edgeLengths = pipePolyFrame.Edges.Select(x => x.GetLength()); minLen = edgeLengths.Min(); maxLen = edgeLengths.Max(); //var medLen = edgeLengths.Average(); var gp = new Rhino.Input.Custom.GetPoint(); var minRadius = new Rhino.Input.Custom.OptionDouble(minLen / 10, true, double.Epsilon); var maxRadius = new Rhino.Input.Custom.OptionDouble(minLen / 2, true, double.Epsilon); gp.SetCommandPrompt("Place the Pipes. Hit <Enter> to replace Input"); gp.SetDefaultPoint(primal.Centroid); gp.AcceptPoint(true); gp.AddOptionDouble("MinRadius", ref minRadius); gp.AddOptionDouble("MaxRadius", ref maxRadius); while (true) { gp.Get(); if (gp.Result() == Rhino.Input.GetResult.Point) { break; } else if (gp.Result() == Rhino.Input.GetResult.Cancel) { return(Result.Failure); } } var moveVect = gp.Point() - pipePolyFrame.Centroid; pipePolyFrame.Offset(moveVect); if (gp.GotDefault()) { if (!form) { moveVect = primal.Centroid - dual.Centroid; } doc.Objects.Delete(guids, true); doc.Views.Redraw(); } var pipeLayer = new Rhino.DocObjects.Layer() { Name = "_Pipes" }; if (doc.Layers.All(x => x.Name != pipeLayer.Name)) { doc.Layers.Add(pipeLayer); } pipeLayer = doc.Layers.First(x => x.Name == "_Pipes"); var pipeCol = pipePolyFrame.PipeGeoDual(minRadius.CurrentValue, maxRadius.CurrentValue, pipePolyFrame.Edges.Select(x => x.Id).ToList()); var pipeGuids = new List <Guid>(); foreach (var pc in pipeCol) { var att = new Rhino.DocObjects.ObjectAttributes { LayerIndex = pipeLayer.Index, ObjectColor = pc.Item2, ColorSource = Rhino.DocObjects.ObjectColorSource.ColorFromObject }; pipeGuids.Add(doc.Objects.AddBrep(pc.Item1, att)); } doc.Groups.Add(pipePolyFrame.Id.ToString() + "_Pipes", pipeGuids); pipePolyFrame.SaveAsEdges(); doc.Views.Redraw(); } catch (PolyFrameworkException pfE) { RhinoApp.WriteLine(pfE.Message); primal.Hide(); dual.Hide(); return(Result.Failure); } return(Result.Success); }