/// <summary> /// Rhino calls this function to run the command. /// </summary> protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Curve; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) return rc; Rhino.Geometry.Curve curve = objref.Curve(); if (null == curve || curve.IsShort(Rhino.RhinoMath.ZeroTolerance)) return Rhino.Commands.Result.Failure; int segmentCount = 2; rc = Rhino.Input.RhinoGet.GetInteger("Number of segments", false, ref segmentCount, 2, 100); if (rc != Rhino.Commands.Result.Success) return rc; Rhino.Geometry.Point3d[] points; curve.DivideByCount(segmentCount, true, out points); if (null == points) return Rhino.Commands.Result.Failure; // Create a history record Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, _historyVersion); WriteHistory(history, objref, segmentCount, points.Length); for (int i = 0; i < points.Length; i++) doc.Objects.AddPoint(points[i], null, history, false); doc.Views.Redraw(); return Rhino.Commands.Result.Success; }
/// <summary> /// Rhino calls this function to run the command. /// </summary> protected override Rhino.Commands.Result RunCommand(Rhino.RhinoDoc doc, Rhino.Commands.RunMode mode) { const Rhino.DocObjects.ObjectType filter = Rhino.DocObjects.ObjectType.Curve; Rhino.DocObjects.ObjRef objref; Rhino.Commands.Result rc = Rhino.Input.RhinoGet.GetOneObject("Select curve to divide", false, filter, out objref); if (rc != Rhino.Commands.Result.Success || objref == null) { return(rc); } Rhino.Geometry.Curve curve = objref.Curve(); if (null == curve || curve.IsShort(Rhino.RhinoMath.ZeroTolerance)) { return(Rhino.Commands.Result.Failure); } int segmentCount = 2; rc = Rhino.Input.RhinoGet.GetInteger("Number of segments", false, ref segmentCount, 2, 100); if (rc != Rhino.Commands.Result.Success) { return(rc); } Rhino.Geometry.Point3d[] points; curve.DivideByCount(segmentCount, true, out points); if (null == points) { return(Rhino.Commands.Result.Failure); } // Create a history record Rhino.DocObjects.HistoryRecord history = new Rhino.DocObjects.HistoryRecord(this, _historyVersion); WriteHistory(history, objref, segmentCount, points.Length); for (int i = 0; i < points.Length; i++) { doc.Objects.AddPoint(points[i], null, history, false); } doc.Views.Redraw(); return(Rhino.Commands.Result.Success); }
private bool WriteHistory(Rhino.DocObjects.HistoryRecord history, Rhino.DocObjects.ObjRef objref, int segmentCount, int pointCount) { if (!history.SetObjRef(0, objref)) { return(false); } if (!history.SetInt(1, segmentCount)) { return(false); } if (!history.SetInt(2, pointCount)) { return(false); } return(true); }