protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. Brep my_brep = My_object_functions.Initialize("D:/Desktop/MyObject_1pin.3dm"); My_object_functions.SetName(my_brep, "my_object_1_pin"); My_object_functions.SetColor(my_brep, Color.Red); My_object_functions.SetPosition(my_brep, new Point3d(0, 10.0, 0)); My_object_functions.SetZ(my_brep, new Vector3d(0, -1.0, 0)); My_object_functions.SetY(my_brep, new Vector3d(1.0, 0, 0)); My_object_functions.SetX(my_brep, new Vector3d(0.0, 0, 1.0)); My_object_functions.SetPinQuantity(my_brep, 1); My_object_functions.SetPinCoordination(my_brep, 0, new Point3d(0, 0, 0)); for (int i = 0; i < 1; i++) { My_object_functions.SetPinGuid(my_brep, i, Guid.NewGuid()); } ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.ObjectColor = My_object_functions.GetColor(my_brep); MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; p.my_objects_list.Add(my_brep); doc.Objects.AddBrep(my_brep, my_attributes); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gcurve = new GetObject(); gcurve.SetCommandPrompt("Get nurbscurve"); gcurve.GeometryFilter = Rhino.DocObjects.ObjectType.Curve; gcurve.SubObjectSelect = false; gcurve.Get(); if (gcurve.CommandResult() != Result.Success) { return(gcurve.CommandResult()); } ObjRef curve_objref = gcurve.Object(0); RhinoObject curve_obj = curve_objref.Object(); Curve selected_curve = curve_objref.Curve(); NurbsCurve nurbs_curve = selected_curve.ToNurbsCurve(); Guid path_id = selected_curve.UserDictionary.GetGuid("PathID"); IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } List <NurbsCurve> new_path_list = new List <NurbsCurve>(); new_path_list = my_graph.DijkstraPath_DeletePath(path_id); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; //doc.Objects.Delete(my_objref1, true); for (int i = 0; i < new_path_list.Count; i++) { Guid PathID = new_path_list[i].UserDictionary.GetGuid("PathID"); my_attributes.ObjectId = PathID; doc.Objects.Add(new_path_list[i], my_attributes); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. Brep my_brep = My_object_functions.Initialize("D:/Desktop/MyObject_4pins.3dm"); My_object_functions.SetName(my_brep, "my_object_4_pins"); My_object_functions.SetColor(my_brep, Color.Blue); My_object_functions.SetPosition(my_brep, new Point3d(0, 0, -5.0)); My_object_functions.SetPinQuantity(my_brep, 4); My_object_functions.SetPinCoordination(my_brep, 0, new Point3d(7.5, 5.0, 0.0)); My_object_functions.SetPinCoordination(my_brep, 1, new Point3d(-7.5, 5.0, 0.0)); My_object_functions.SetPinCoordination(my_brep, 2, new Point3d(7.5, -5.0, 0.0)); My_object_functions.SetPinCoordination(my_brep, 3, new Point3d(-7.5, -5.0, 0.0)); for (int i = 0; i < 4; i++) { My_object_functions.SetPinGuid(my_brep, i, Guid.NewGuid()); } ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.ObjectColor = My_object_functions.GetColor(my_brep); /* * Point3d position = My_object_functions.GetPosition(my_brep); * Vector3d d_x = My_object_functions.GetX(my_brep); * Vector3d d_y = My_object_functions.GetY(my_brep); * Vector3d d_z = My_object_functions.GetZ(my_brep); * Line l_x = new Line(position, 10 * d_x); * Line l_y = new Line(position, 10 * d_y); * Line l_z = new Line(position, 10 * d_z); * * * ObjectAttributes path_attributes = new ObjectAttributes(); * path_attributes.ObjectColor = Color.Yellow; * path_attributes.ColorSource = ObjectColorSource.ColorFromObject; * path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; * path_attributes.PlotWeight = 2.0; * * * doc.Objects.AddLine(l_x, path_attributes); * doc.Objects.AddLine(l_y, path_attributes); * doc.Objects.AddLine(l_z, path_attributes); */ MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; p.my_objects_list.Add(my_brep); doc.Objects.AddBrep(my_brep, my_attributes); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. RhinoApp.WriteLine("The {0} command is under construction.", EnglishName); Rhino.Input.Custom.GetObject gmesh = new Rhino.Input.Custom.GetObject(); gmesh.SetCommandPrompt("Get the Mesh"); gmesh.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh; gmesh.SubObjectSelect = true; gmesh.Get(); if (gmesh.CommandResult() != Rhino.Commands.Result.Success) { return(gmesh.CommandResult()); } Rhino.DocObjects.ObjRef objref = gmesh.Object(0); Rhino.DocObjects.RhinoObject obj = objref.Object(); if (obj == null) { return(Rhino.Commands.Result.Failure); } Rhino.Geometry.Mesh mesh = objref.Mesh(); if (mesh == null) { return(Rhino.Commands.Result.Failure); } obj.Select(false); MeshTextureCoordinateList texture_list = mesh.TextureCoordinates; for (int i = 0; i < texture_list.Count - 1; i++) { Point2f f1 = texture_list[i]; Point2f f2 = texture_list[i + 1]; Point3d t1 = new Point3d(f1.X, f1.Y, 0); Point3d t2 = new Point3d(f2.X, f2.Y, 0); Line l = new Line(t1, t2); doc.Objects.AddLine(l); RhinoApp.WriteLine("Line added"); } doc.Views.Redraw(); MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; p.painted_object_ = mesh; p.if_painted_object_set_ = true; mesh.UserDictionary.Set("name", "myMesh"); mesh.UserDictionary.Set("isMovable", false); p.graph = new DijkstraGraph(10); RhinoApp.WriteLine("Mesh Got"); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } ObjRef my_objref = gbrep.Object(0); RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); int brep_number = 0; for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; if (My_object_functions.GetComponentID(brep) == My_object_functions.GetComponentID(an_object)) { brep_number = i; break; } } Point3d position = My_object_functions.GetPosition(brep); Vector3d normal_direction = My_object_functions.GetZ(brep); Plane plane = new Plane(position, normal_direction); /* * GetPoint gp = new GetPoint(); * gp.Constrain(plane, false); * gp.Get(); * if (gp.CommandResult() != Result.Success) * return gp.CommandResult(); * var start_point = gp.Point(); * if (start_point == Point3d.Unset) * return Result.Failure; */ Vector3d horizontal_direction = My_object_functions.GetY(brep); Point3d start_point = position + 10 * horizontal_direction; GetRotationAngle gr = new GetRotationAngle(brep, my_mesh, start_point); gr.SetCommandPrompt("Get the rotation angle"); gr.Constrain(plane, false); gr.Get(); if (gr.CommandResult() != Result.Success) { return(gr.CommandResult()); } Point3d end_point = gr.Point(); Brep new_brep = GetRotationAngle.RotateBrep(brep, my_mesh, end_point, start_point); ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = My_object_functions.GetColor(new_brep); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; int new_pin_number = My_object_functions.GetPinQuantity(new_brep); List <NurbsCurve> new_path_list = new List <NurbsCurve>(); for (int i = 0; i < new_pin_number; i++) { Guid pin_id = My_object_functions.GetPinGuid(new_brep, i); Point3d pin_position = My_object_functions.GetPinPosition(new_brep, i); MeshPoint pin_on_mesh = my_mesh.ClosestMeshPoint(pin_position, 0); new_path_list = p.graph.DijkstraPath_Change(pin_id, pin_on_mesh); } IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } for (int i = 0; i < new_path_list.Count; i++) { Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID"); path_attributes.ObjectId = path_id; doc.Objects.AddCurve(new_path_list[i], path_attributes); } doc.Objects.Delete(my_objref, true); doc.Objects.AddBrep(new_brep, my_attributes); p.my_objects_list[brep_number] = new_brep; doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; Stopwatch watch = new Stopwatch(); GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } Rhino.DocObjects.ObjRef my_objref = gbrep.Object(0); Rhino.DocObjects.RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); GetObjectPosition gp = new GetObjectPosition(brep, my_mesh); gp.SetCommandPrompt("Get the object position on mesh: "); gp.Constrain(my_mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Brep moved_brep = brep.DuplicateBrep(); Point3d Origin = brep.UserDictionary.GetPoint3d("CurrentPosition"); Vector3d OriginVector = brep.UserDictionary.GetVector3d("CurrentDirection"); Point3d new_position = gp.Point(); Vector3d normal_on_mesh = my_mesh.NormalAt(my_mesh.ClosestMeshPoint(new_position, 0)); if (OriginVector.IsParallelTo(normal_on_mesh) == 0) { double RotationAngle = Vector3d.VectorAngle(OriginVector, normal_on_mesh); Vector3d RoationAxis = Vector3d.CrossProduct(OriginVector, normal_on_mesh); moved_brep.Rotate(RotationAngle, RoationAxis, Origin); } moved_brep.Translate(new_position - Origin); moved_brep.UserDictionary.Set("CurrentPosition", new_position); moved_brep.UserDictionary.Set("CurrentDirection", normal_on_mesh); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.FromName(moved_brep.UserDictionary.GetString("Color")); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; watch.Start(); //delete all old paths IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } watch.Stop(); RhinoApp.WriteLine("time 1: {0}", watch.Elapsed); ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; Guid pin_1_id = moved_brep.UserDictionary.GetGuid("PinID"); MeshPoint current_meshpoint = my_mesh.ClosestMeshPoint(new_position, 0.0); watch.Restart(); List <NurbsCurve> new_path_list = p.graph.DijkstraPath_Change(pin_1_id, current_meshpoint); watch.Stop(); RhinoApp.WriteLine("time 2: {0}", watch.Elapsed); watch.Restart(); for (int i = 0; i < new_path_list.Count; i++) { doc.Objects.Add(new_path_list[i], path_attributes); } doc.Objects.Delete(my_objref, true); brep.Dispose(); doc.Objects.AddBrep(moved_brep, my_attributes); doc.Views.Redraw(); watch.Stop(); RhinoApp.WriteLine("time 3: {0}", watch.Elapsed); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep1 = new GetObject(); gbrep1.SetCommandPrompt("get the brep"); gbrep1.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep1.SubObjectSelect = false; gbrep1.Get(); if (gbrep1.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep1.CommandResult()); } Rhino.DocObjects.ObjRef my_objref1 = gbrep1.Object(0); Rhino.DocObjects.RhinoObject my_obj1 = my_objref1.Object(); if (my_obj1 == null) { return(Rhino.Commands.Result.Failure); } Brep brep1 = my_objref1.Brep(); if (brep1 == null) { return(Result.Failure); } my_obj1.Select(false); for (int i = 0; i < p.my_objects_list.Count; i++) { Guid brep1_id = My_object_functions.GetComponentID(brep1); Guid my_object_id = My_object_functions.GetComponentID(p.my_objects_list[i]); if (brep1_id == my_object_id) { p.my_objects_list.RemoveAt(i); } } IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } List <NurbsCurve> new_path_list = new List <NurbsCurve>(); int pin_number = My_object_functions.GetPinQuantity(brep1); for (int i = 0; i < pin_number; i++) { Guid pin_id = My_object_functions.GetPinGuid(brep1, i); new_path_list = p.graph.DijkstraPath_DeletePin(pin_id); } ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.Delete(my_objref1, true); for (int i = 0; i < new_path_list.Count; i++) { Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID"); my_attributes.ObjectId = path_id; doc.Objects.Add(new_path_list[i], my_attributes); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep1 = new GetObject(); gbrep1.SetCommandPrompt("get the brep"); gbrep1.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep1.SubObjectSelect = false; gbrep1.Get(); if (gbrep1.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep1.CommandResult()); } Rhino.DocObjects.ObjRef my_objref1 = gbrep1.Object(0); Rhino.DocObjects.RhinoObject my_obj1 = my_objref1.Object(); if (my_obj1 == null) { return(Rhino.Commands.Result.Failure); } Brep brep1 = my_objref1.Brep(); if (brep1 == null) { return(Result.Failure); } my_obj1.Select(false); GetObject gbrep2 = new GetObject(); gbrep2.SetCommandPrompt("get the brep"); gbrep2.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep2.SubObjectSelect = false; gbrep2.Get(); if (gbrep2.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep2.CommandResult()); } Rhino.DocObjects.ObjRef my_objref2 = gbrep2.Object(0); Rhino.DocObjects.RhinoObject my_obj2 = my_objref2.Object(); if (my_obj2 == null) { return(Rhino.Commands.Result.Failure); } Brep brep2 = my_objref2.Brep(); if (brep2 == null) { return(Result.Failure); } my_obj2.Select(false); Point3d pin_1_position = brep1.UserDictionary.GetPoint3d("CurrentPosition"); Point3d pin_2_position = brep2.UserDictionary.GetPoint3d("CurrentPosition"); Guid pin_1_id = brep1.UserDictionary.GetGuid("PinID"); Guid pin_2_id = brep2.UserDictionary.GetGuid("PinID"); MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(pin_1_position, 0); MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(pin_2_position, 0); Stopwatch watch = new Stopwatch(); watch.Start(); NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, pin_1_id, pin_2_meshpoint, pin_2_id); watch.Stop(); if (d_path == null) { return(Result.Success); } RhinoApp.WriteLine("link time: {0}", watch.Elapsed); ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.AddCurve(d_path, my_attributes); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } ObjRef my_objref = gbrep.Object(0); RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); int brep_number = 0; for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; if (My_object_functions.GetComponentID(brep) == My_object_functions.GetComponentID(an_object)) { brep_number = i; break; } } GetComponentPosition gp = new GetComponentPosition(brep, my_mesh); gp.SetCommandPrompt("Get the object position on mesh: "); gp.Constrain(my_mesh, false); gp.Get(); if (gp.CommandResult() != Result.Success) { return(gp.CommandResult()); } Point3d n_p = gp.Point(); List <Sphere> pin_ball_list; Brep new_brep = GetComponentPosition.MoveBrep(brep, my_mesh, n_p, out pin_ball_list); /* * Point3d position = My_object_functions.GetPosition(new_brep); * Vector3d d_x = My_object_functions.GetX(new_brep); * Vector3d d_y = My_object_functions.GetY(new_brep); * Vector3d d_z = My_object_functions.GetZ(new_brep); * Line l_x = new Line(position, 10 * d_x); * Line l_y = new Line(position, 10 * d_y); * Line l_z = new Line(position, 10 * d_z); */ ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = My_object_functions.GetColor(new_brep); my_attributes.ColorSource = ObjectColorSource.ColorFromObject; int new_pin_number = My_object_functions.GetPinQuantity(new_brep); List <NurbsCurve> new_path_list = new List <NurbsCurve>(); for (int i = 0; i < new_pin_number; i++) { Guid pin_id = My_object_functions.GetPinGuid(new_brep, i); Point3d pin_position = My_object_functions.GetPinPosition(new_brep, i); MeshPoint pin_on_mesh = my_mesh.ClosestMeshPoint(pin_position, 0); new_path_list = p.graph.DijkstraPath_Change(pin_id, pin_on_mesh); } IEnumerable <RhinoObject> path_objref = doc.Objects.GetObjectList(ObjectType.Curve); foreach (RhinoObject path in path_objref) { doc.Objects.Delete(path, true); } for (int i = 0; i < new_path_list.Count; i++) { Guid path_id = new_path_list[i].UserDictionary.GetGuid("PathID"); path_attributes.ObjectId = path_id; doc.Objects.AddCurve(new_path_list[i], path_attributes); } doc.Objects.Delete(my_objref, true); /* * IEnumerable<RhinoObject> rhino_objects = doc.Objects.GetObjectList(ObjectType.Brep); * foreach (RhinoObject r_o in rhino_objects) { doc.Objects.Delete(r_o, true); } * * IEnumerable<RhinoObject> lines = doc.Objects.GetObjectList(ObjectType.Curve); * foreach (RhinoObject r_o in lines) { doc.Objects.Delete(r_o, true); } */ doc.Objects.AddBrep(new_brep, my_attributes); p.my_objects_list[brep_number] = new_brep; /* * foreach (Sphere s in pin_ball_list) * { doc.Objects.AddSphere(s); } * doc.Objects.AddLine(l_x, path_attributes); * doc.Objects.AddLine(l_y, path_attributes); * doc.Objects.AddLine(l_z, path_attributes); */ doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.if_painted_object_set_ == false) { RhinoApp.WriteLine("No mesh"); return(Result.Failure); } Mesh my_mesh = p.painted_object_; DijkstraGraph my_graph = p.graph; GetObject gbrep = new GetObject(); gbrep.SetCommandPrompt("get the brep"); gbrep.GeometryFilter = Rhino.DocObjects.ObjectType.Brep; gbrep.SubObjectSelect = false; gbrep.Get(); if (gbrep.CommandResult() != Rhino.Commands.Result.Success) { return(gbrep.CommandResult()); } Rhino.DocObjects.ObjRef my_objref = gbrep.Object(0); Rhino.DocObjects.RhinoObject my_obj = my_objref.Object(); if (my_obj == null) { return(Rhino.Commands.Result.Failure); } Brep brep = my_objref.Brep(); if (brep == null) { return(Result.Failure); } my_obj.Select(false); int pin_number_1 = My_object_functions.GetPinQuantity(brep); List <Guid> pin_ball_guid_list_1 = new List <Guid>(); for (int i = 0; i < pin_number_1; i++) { ObjectAttributes green_ball_attributes = new ObjectAttributes(); green_ball_attributes.ObjectColor = Color.Green; green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; Point3d pin_position = My_object_functions.GetPinPosition(brep, i); Guid pin_id = My_object_functions.GetPinGuid(brep, i); green_ball_attributes.ObjectId = pin_id; green_ball_attributes.UserDictionary.Set("isPin", true); Sphere pin_ball = new Sphere(pin_position, 2); //Brep pin_ball_brep = pin_ball.ToBrep(); doc.Objects.AddSphere(pin_ball, green_ball_attributes); pin_ball_guid_list_1.Add(pin_id); } doc.Views.Redraw(); GetObject g_pinball = new GetObject(); g_pinball.SetCommandPrompt("choose the pin"); g_pinball.GeometryFilter = ObjectType.Surface; //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter); //g_pinball.DisablePreSelect(); g_pinball.SubObjectSelect = false; g_pinball.Get(); if (g_pinball.CommandResult() != Result.Success) { return(g_pinball.CommandResult()); } if (g_pinball.Object(0).Brep() == null) { return(Result.Failure); } RhinoObject selected_pin_ball = g_pinball.Object(0).Object(); Guid selected_pin_ball_id = selected_pin_ball.Id; for (int i = 0; i < pin_ball_guid_list_1.Count; i++) { doc.Objects.Delete(pin_ball_guid_list_1[i], true); } ObjectAttributes greenyellow_ball_attributes = new ObjectAttributes(); greenyellow_ball_attributes.ObjectColor = Color.GreenYellow; greenyellow_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; greenyellow_ball_attributes.ObjectId = selected_pin_ball_id; greenyellow_ball_attributes.UserDictionary.Set("isPin", true); int pin_number = My_object_functions.FindPinNumber(brep, selected_pin_ball_id); Point3d selected_pin_position = My_object_functions.GetPinPosition(brep, pin_number); Sphere pin_ball_new = new Sphere(selected_pin_position, 2); doc.Objects.AddSphere(pin_ball_new, greenyellow_ball_attributes); doc.Views.Redraw(); //MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; if (p.my_objects_list.Count <= 1) { RhinoApp.WriteLine("not enough objects"); return(Result.Failure); } List <Guid> pin_ball_guid_list_2 = new List <Guid>(); for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; if (My_object_functions.GetComponentID(brep) != My_object_functions.GetComponentID(an_object)) { int pin_quantity = My_object_functions.GetPinQuantity(an_object); for (int j = 0; j < pin_quantity; j++) { ObjectAttributes green_ball_attributes = new ObjectAttributes(); green_ball_attributes.ObjectColor = Color.Green; green_ball_attributes.ColorSource = ObjectColorSource.ColorFromObject; Point3d pin_position = My_object_functions.GetPinPosition(an_object, j); Guid pin_id = My_object_functions.GetPinGuid(an_object, j); green_ball_attributes.ObjectId = pin_id; green_ball_attributes.UserDictionary.Set("isPin", true); Sphere pin_ball = new Sphere(pin_position, 2); doc.Objects.AddSphere(pin_ball, green_ball_attributes); pin_ball_guid_list_2.Add(pin_id); } } } doc.Views.Redraw(); GetObject g_pinball_2 = new GetObject(); g_pinball_2.SetCommandPrompt("choose the pin"); g_pinball_2.GeometryFilter = ObjectType.Surface; //g_pinball.SetCustomGeometryFilter(PinBallGeometryFilter); //g_pinball.DisablePreSelect(); g_pinball_2.SubObjectSelect = false; g_pinball_2.Get(); if (g_pinball_2.CommandResult() != Result.Success) { return(g_pinball_2.CommandResult()); } if (g_pinball_2.Object(0).Brep() == null) { return(Result.Failure); } RhinoObject selected_pin_ball_2 = g_pinball_2.Object(0).Object(); Guid selected_pin_ball_id_2 = selected_pin_ball_2.Id; Brep brep_2 = null; for (int i = 0; i < p.my_objects_list.Count; i++) { Brep an_object = p.my_objects_list[i]; int pin_quantity = My_object_functions.GetPinQuantity(an_object); bool mark = false; for (int j = 0; j < pin_quantity; j++) { if (My_object_functions.GetPinGuid(an_object, j) == selected_pin_ball_id_2) { mark = true; break; } } if (mark) { brep_2 = an_object; break; } } if (brep_2 == null) { return(Result.Failure); } int selected_pin_number_2 = My_object_functions.FindPinNumber(brep_2, selected_pin_ball_id_2); for (int i = 0; i < pin_ball_guid_list_2.Count; i++) { doc.Objects.Delete(pin_ball_guid_list_2[i], true); } Point3d selected_pin_position_2 = My_object_functions.GetPinPosition(brep_2, selected_pin_number_2); Sphere pin_ball_new_2 = new Sphere(selected_pin_position_2, 2); greenyellow_ball_attributes.ObjectId = selected_pin_ball_id_2; doc.Objects.AddSphere(pin_ball_new_2, greenyellow_ball_attributes); doc.Views.Redraw(); MeshPoint pin_1_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position, 0); MeshPoint pin_2_meshpoint = my_mesh.ClosestMeshPoint(selected_pin_position_2, 0); NurbsCurve d_path = my_graph.DijkstraPath_Add(pin_1_meshpoint, selected_pin_ball_id, pin_2_meshpoint, selected_pin_ball_id_2); if (d_path != null) { ObjectAttributes path_attributes = new ObjectAttributes(); path_attributes.ObjectColor = Color.Yellow; path_attributes.ColorSource = ObjectColorSource.ColorFromObject; path_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; path_attributes.PlotWeight = 2.0; path_attributes.ObjectId = d_path.UserDictionary.GetGuid("PathID"); doc.Objects.AddCurve(d_path, path_attributes); } doc.Objects.Delete(selected_pin_ball_id, true); doc.Objects.Delete(selected_pin_ball_id_2, true); doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { // TODO: complete command. //DijkstraGraph graph = new DijkstraGraph(50); MyRhino5rs11project8PlugIn p = MyRhino5rs11project8PlugIn.Instance; Mesh my_mesh = p.painted_object_; int vertex_list_count = p.graph.GetVertexListCount(); RhinoApp.WriteLine("the total number of vertices is {0}", vertex_list_count); GetPoint gp_start = new GetPoint(); gp_start.SetCommandPrompt("Get the begin point on mesh: "); gp_start.Constrain(my_mesh, false); gp_start.Get(); if (gp_start.CommandResult() != Result.Success) { return(gp_start.CommandResult()); } Point3d p_start = gp_start.Point(); GetPoint gp_end = new GetPoint(); gp_end.SetCommandPrompt("Get the end point on mesh: "); gp_end.Constrain(my_mesh, false); gp_end.Get(); if (gp_end.CommandResult() != Result.Success) { return(gp_end.CommandResult()); } Point3d p_end = gp_end.Point(); int begin_num = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_start, 0).FaceIndex); int end_num = p.graph.NearVertexOnMesh(my_mesh.ClosestMeshPoint(p_end, 0).FaceIndex); /* * GetInteger g_begin = new GetInteger(); * g_begin.SetCommandPrompt("Type in the number of beginning vertex"); * g_begin.AcceptNumber(true, true); * g_begin.Get(); * int begin_num = g_begin.Number(); * GetInteger g_end = new GetInteger(); * g_end.SetCommandPrompt("Type in the number of the ending vertex"); * g_end.AcceptNumber(true, true); * g_end.Get(); * int end_num = g_end.Number(); */ NurbsCurve d_path = p.graph.GetDijkstraPath(begin_num, end_num, true).path; ObjectAttributes my_attributes = new ObjectAttributes(); my_attributes.ObjectColor = Color.Yellow; my_attributes.ColorSource = ObjectColorSource.ColorFromObject; my_attributes.PlotWeightSource = ObjectPlotWeightSource.PlotWeightFromObject; my_attributes.PlotWeight = 2.0; doc.Objects.AddCurve(d_path, my_attributes); doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_start, 0).Point); doc.Objects.AddPoint(my_mesh.ClosestMeshPoint(p_end, 0).Point); doc.Views.Redraw(); return(Result.Success); }