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. 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 void OnDynamicDraw(GetPointDrawEventArgs e) { base.OnDynamicDraw(e); Point3d current_point = e.CurrentPoint; Brep new_new_brep = RotateBrep(new_brep, base_mesh, current_point, start_point); Color color = My_object_functions.GetColor(new_new_brep); double radius = current_point.DistanceTo(center_point); Circle circle = new Circle(plane, center_point, radius); Line line1 = new Line(current_point, center_point); Line line2 = new Line(center_point, start_point - center_point, radius); e.Display.DrawBrepWires(new_new_brep, color); Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(color); e.Display.DrawBrepShaded(new_new_brep, material); e.Display.DrawCircle(circle, System.Drawing.Color.Black); e.Display.DrawLine(line1, System.Drawing.Color.Black); //e.Display.DrawLine(line2, System.Drawing.Color.Black); }
protected override void OnDynamicDraw(GetPointDrawEventArgs e) { base.OnDynamicDraw(e); Point3d current_point = e.CurrentPoint; List <Sphere> pin_ball_list; Brep new_new_brep = MoveBrep(new_brep, base_mesh, current_point, out pin_ball_list); Color color = My_object_functions.GetColor(new_new_brep); for (int i = 0; i < pin_ball_list.Count; i++) { e.Display.DrawSphere(pin_ball_list[i], System.Drawing.Color.Red); } e.Display.DrawBrepWires(new_new_brep, color); Rhino.Display.DisplayMaterial material = new Rhino.Display.DisplayMaterial(color); e.Display.DrawBrepShaded(new_new_brep, material); }
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) { 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); }