protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var gp = new GetPoint(); gp.SetCommandPrompt("Start point"); gp.AddOptionEnumList("Justification", m_justification); gp.ConstrainToConstructionPlane(false); for (;;) { var res = gp.Get(); if (res == GetResult.Option) { var option = gp.Option(); if (null != option) { var list = Enum.GetValues(typeof(TextJustification)).Cast <TextJustification>().ToList(); m_justification = list[option.CurrentListOptionIndex]; } continue; } if (res != GetResult.Point) { return(Result.Cancel); } break; } var point = gp.Point(); var plane = gp.View().ActiveViewport.ConstructionPlane(); plane.Origin = point; var text = new TextEntity { Plane = plane, Justification = m_justification }; text.PlainText = text.Justification.ToString(); var attr = new ObjectAttributes { ColorSource = ObjectColorSource.ColorFromObject, ObjectColor = Color.FromArgb(0, 0, 255) }; var object_id = doc.Objects.AddText(text, attr); RhinoApp.WriteLine("{0}", object_id.ToString()); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Start point"); gp.AddOptionEnumList("Justification", m_justification); gp.ConstrainToConstructionPlane(false); for (;;) { GetResult res = gp.Get(); if (res == GetResult.Option) { CommandLineOption option = gp.Option(); if (null != option) { List <TextJustification> list = Enum.GetValues(typeof(TextJustification)).Cast <TextJustification>().ToList(); m_justification = list[option.CurrentListOptionIndex]; } continue; } else if (res != GetResult.Point) { return(Result.Cancel); } break; } Point3d point = gp.Point(); Plane plane = gp.View().ActiveViewport.ConstructionPlane(); plane.Origin = point; TextEntity text = new TextEntity(); text.Plane = plane; text.Justification = m_justification; text.Text = text.Justification.ToString(); doc.Objects.AddPoint(point); doc.Objects.AddText(text); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(Rhino.RhinoDoc doc, RunMode mode) { var dirname = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string[] pathComponent = new string[] { dirname.ToString(), @"common_paper_sizes.json" }; var jsonPath = Path.Combine(pathComponent); GetPoint gp = new GetPoint(); string text = System.IO.File.ReadAllText(jsonPath); gp.SetCommandPrompt("Set Origin of Paper Rectangle"); OptionToggle boolOption = new OptionToggle(false, "Off", "On"); gp.AddOptionToggle("Portrait", ref boolOption); var listNames = new List <string>(); var listValues = new List <Point2d>(); List <Paper> papers = JsonConvert.DeserializeObject <List <Paper> >(text); //foreach(var paper in papers) //{ var count = 0; foreach (var format in papers[0].formats) { var num = int.Parse(Regex.Match(format.name, @"\d+").Value); if (num < 6 && !format.name.Contains("C")) { listNames.Add(format.name); listValues.Add(new Point2d(format.size.mm[0], format.size.mm[1])); count++; } } //} var listNamesArr = listNames.ToArray(); int listIndex = 0; int opList = gp.AddOptionList("PaperType", listNamesArr, 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) { var plane = doc.Views.ActiveView.ActiveViewport.GetConstructionPlane().Plane; plane.Origin = gp.Point(); var item = listValues[listIndex]; var isPortrait = boolOption.CurrentValue; var rect = new Rectangle3d(plane, isPortrait ? item.X : item.Y, isPortrait ? item.Y : item.X); var attr = new Rhino.DocObjects.ObjectAttributes(); attr.Name = listNames[listIndex]; attr.LayerIndex = doc.Layers.CurrentLayerIndex; doc.Objects.AddRectangle(rect, attr); doc.Views.Redraw(); } 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 Result RunCommand(RhinoDoc doc, RunMode mode) { var fruit_list = new[] { "Apple", "Bannana", "Grape", "Mango", "Orange", "Pear" }; var nut_list = new[] { "Almonds", "Cashews", "Hazelnuts", "Pecans", "Pistachios", "Walnuts" }; var vegetable_list = new[] { "Asparagus", "Broccoli", "Carrot", "Corn", "Lettuce", "Onion" }; // Get persistent settings var fruit_value = Settings.GetInteger("Fruit", 0); var nut_value = Settings.GetInteger("Nut", 0); var vegetable_value = Settings.GetInteger("Vegetable", 0); var gp = new GetPoint(); gp.SetCommandPrompt("GetPoint with options"); var rc = Result.Cancel; while (true) { gp.ClearCommandOptions(); var fruit_index = gp.AddOptionList("Fruit", fruit_list, fruit_value); var nut_index = gp.AddOptionList("Nut", nut_list, nut_value); var vegetable_index = gp.AddOptionList("Vegetable", vegetable_list, vegetable_value); var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.Point()); doc.Views.Redraw(); rc = Result.Success; } else if (res == Rhino.Input.GetResult.Option) { var option = gp.Option(); if (null != option) { if (option.Index == fruit_index) { fruit_value = option.CurrentListOptionIndex; } else if (option.Index == nut_index) { nut_value = option.CurrentListOptionIndex; } else if (option.Index == vegetable_index) { vegetable_value = option.CurrentListOptionIndex; } } continue; } break; } if (rc == Result.Success) { // Set persistent settings Settings.SetInteger("Fruit", fruit_value); Settings.SetInteger("Nut", nut_value); Settings.SetInteger("Vegetable", vegetable_value); } return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to expand"); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); goList.Add(obj); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Expansion factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); Rhino.Display.RhinoView view = gp2.View(); plane2D = view.ActiveViewport.ConstructionPlane(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Expantion factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { Rhino.Geometry.Vector3d vec = (centers[i] - scaleCenter) * (factor - 1); Vector3d planeNormal = plane2D.Normal; if (planeNormal[0] != 0) { vec.X = 0; } else if (planeNormal[1] != 0) { vec.Y = 0; } else if (planeNormal[2] != 0) { vec.Z = 0; } var xform = Rhino.Geometry.Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vecEach = (centers[i] - scaleCenter); double vecEachLength = vecEach.Length * (factor - 1); Vector3d vec = (scaleRefPoint - scaleCenter); double angleVec = Vector3d.VectorAngle(vecEach, vec); int pol = 1; if (angleVec > 1.57) { pol = -1; } vec.Unitize(); vec = vec * vecEachLength * pol; var xform = Transform.Translation(vec); doc.Objects.Transform(go.Object(i), xform, true); } } goList = new List <Object>(); centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); doc.Views.Redraw(); return(Result.Success); }
/// <summary> /// RunCommand override /// </summary> protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // Get persistent settings (from Registry) var bool_value = Settings.GetBool("BoolValue", BOOL_DEFAULT); var int_value = Settings.GetInteger("IntValue", INT_DEFAULT); var dbl_value = Settings.GetDouble("DblValue", DBL_DEFAULT); var list_value = Settings.GetInteger("ListValue", LIST_DEFAULT); var gp = new GetPoint(); gp.SetCommandPrompt("GetPoint with options"); var rc = Result.Cancel; while (true) { gp.ClearCommandOptions(); var bool_option = new OptionToggle(bool_value, "Off", "On"); var int_option = new OptionInteger(int_value, 1, 99); var dbl_option = new OptionDouble(dbl_value, 0, 99.9); var list_items = new[] { "Item0", "Item1", "Item2", "Item3", "Item4" }; var bool_index = gp.AddOptionToggle("Boolean", ref bool_option); var int_index = gp.AddOptionInteger("Integer", ref int_option); var dbl_index = gp.AddOptionDouble("Double", ref dbl_option); var list_index = gp.AddOptionList("List", list_items, list_value); var reset_index = gp.AddOption("Reset"); var res = gp.Get(); if (res == Rhino.Input.GetResult.Point) { doc.Objects.AddPoint(gp.Point()); doc.Views.Redraw(); rc = Result.Success; } else if (res == Rhino.Input.GetResult.Option) { var option = gp.Option(); if (null != option) { if (option.Index == bool_index) { bool_value = bool_option.CurrentValue; } else if (option.Index == int_index) { int_value = int_option.CurrentValue; } else if (option.Index == dbl_index) { dbl_value = dbl_option.CurrentValue; } else if (option.Index == list_index) { list_value = option.CurrentListOptionIndex; } else if (option.Index == reset_index) { bool_value = BOOL_DEFAULT; int_value = INT_DEFAULT; dbl_value = DBL_DEFAULT; list_value = LIST_DEFAULT; } } continue; } break; } if (rc == Result.Success) { // Set persistent settings (to Registry) Settings.SetBool("BoolValue", bool_value); Settings.SetInteger("IntValue", int_value); Settings.SetDouble("DblValue", dbl_value); Settings.SetInteger("ListValue", list_value); } return(rc); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { var myTypes = ObjectType.AnyObject ^ ObjectType.BrepLoop; //pick objects to expand Rhino.Input.Custom.GetObject go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select objects to scale"); go.GeometryFilter = myTypes; //go.GroupSelect = true; go.SubObjectSelect = true; //go.EnableClearObjectsOnEntry(false); //go.EnableUnselectObjectsOnExit(false); //go.DeselectAllBeforePostSelect = false; go.GetMultiple(1, 0); //Compute center Point3d centersAdd = new Point3d(); for (int i = 0; i < go.ObjectCount; i++) { BoundingBox bbObj = go.Object(i).Geometry().GetBoundingBox(true); Point3d bbObjCenter = bbObj.Center; centers.Add(bbObjCenter); centersAdd += bbObjCenter; Rhino.DocObjects.ObjRef objref = go.Object(i); // get selected surface object Rhino.DocObjects.RhinoObject obj = objref.Object(); dynRef.Add(objref); } Point3d allCenter = centersAdd / centers.Count; //pick center GetPoint gp = new GetPoint(); gp.SetCommandPrompt("Basepoint. Press Enter for automatic."); gp.AcceptNothing(true); var resgp = gp.Get(); if (resgp == GetResult.Nothing) { scaleCenter = allCenter; } else { scaleCenter = gp.Point(); } Rhino.Display.RhinoView view = gp.View(); plane2D = view.ActiveViewport.ConstructionPlane(); //Expansion factor GetPoint gp2 = new GetPoint(); gp2.SetCommandPrompt("Scale factor or first reference point <" + factor + ">"); gp2.DrawLineFromPoint(scaleCenter, true); gp2.AcceptNumber(true, true); GetResult gr = gp2.Get(); if (gr == GetResult.Number) { factor = gp2.Number(); } if (gr == GetResult.Point) { scaleRefPoint = gp2.Point(); Line line1 = new Line(scaleCenter, scaleRefPoint); Guid tempLine = doc.Objects.AddLine(line1); Guid tempPoint = doc.Objects.AddPoint(scaleRefPoint); if (scaleCenter == gp2.Point()) { return(Rhino.Commands.Result.Cancel); } GetPoint gp3 = new GetPoint(); gp3.SetCommandPrompt("Secondt reference point"); gp3.AddOptionList("ScaleDimension", dimensions, 0); gp3.DrawLineFromPoint(scaleCenter, true); gp3.DynamicDraw += RefObjDraw; while (true) { GetResult res = gp3.Get(); if (res == GetResult.Option) { dimensionIndex = gp3.Option().CurrentListOptionIndex; continue; } else if (res == GetResult.Point) { Point3d scaleRefPoint2 = gp3.Point(); factor = (scaleCenter.DistanceTo(scaleRefPoint2)) / (scaleCenter.DistanceTo(scaleRefPoint)); doc.Objects.Delete(tempLine, true); doc.Objects.Delete(tempPoint, true); } break; } } RhinoApp.WriteLine("Scale factor: " + factor); //Compute translation //Translate 3d if (dimensionIndex == 0) { for (int i = 0; i < go.ObjectCount; i++) { var xform = Transform.Scale(centers[i], factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 2d else if (dimensionIndex == 1) { for (int i = 0; i < go.ObjectCount; i++) { plane2D.Origin = centers[i]; var xform = Rhino.Geometry.Transform.Scale(plane2D, factor, factor, 1); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } //Translate 1d else if (dimensionIndex == 2) { for (int i = 0; i < go.ObjectCount; i++) { Vector3d vec = (scaleRefPoint - scaleCenter); Plane scalePlane = new Plane(centers[i], vec); var xform = Transform.Scale(scalePlane, 1, 1, factor); var objref = go.Object(i); var brep = objref.Brep(); var index = objref.GeometryComponentIndex.Index; if (index > 0) { brep.TransformComponent(new[] { objref.GeometryComponentIndex }, xform, doc.ModelAbsoluteTolerance, 0, true); doc.Objects.Replace(objref.ObjectId, brep); } else { doc.Objects.Transform(go.Object(i), xform, true); } } } centers = new List <Point3d>(); dimensionIndex = 0; plane2D = new Plane(); dynRef = new List <Rhino.DocObjects.ObjRef>(); doc.Views.Redraw(); return(Result.Success); }