protected override void OnExecute(Command command, ExecutionContext context, System.Drawing.Rectangle buttonRect) { base.OnExecute(command, context, buttonRect); List <ITrimmedCurve> trimmedCurves = new List <ITrimmedCurve>(); foreach (ITrimmedCurve trimmedCurve in activeWindow.GetAllSelectedITrimmedCurves()) { trimmedCurves.Add(trimmedCurve); } TrimmedCurveChain curveChain = new TrimmedCurveChain(trimmedCurves); double length = curveChain.Length; int count = (int)Math.Floor(length / dashMinSize / 2) * 2; if (curveChain.StartPoint != curveChain.EndPoint) // odd number when not closed curve { count++; } List <DesignCurve> dashes = new List <DesignCurve>(); double lastParam = curveChain.Bounds.Start; Point lastPoint; Debug.Assert(curveChain.TryGetPointAlongCurve(lastParam, out lastPoint)); for (int i = 0; i < count; i++) { Point point; if (curveChain.TryGetPointAlongCurve(lastParam -= length / count, out point)) { if (i % 2 == 1) { DesignCurve dash = DesignCurve.Create(part, CurveSegment.Create(lastPoint, point)); dash.Layer = dashLayer; dashes.Add(dash); } #if false // tori ShapeHelper.CreateTorus( new Point[] { point, lastPoint }.Average(), (point - lastPoint).Direction, 0.188 * inches, 0.75 * inches, part ); #endif lastPoint = point; } } #if false // cylinders for (int i = 1; i < count; i++) { CurveEvaluation eval = dashes[i].Shape.Geometry.Evaluate(dashes[i].Shape.Bounds.Start); Direction dir1 = eval.Tangent; eval = dashes[i - 1].Shape.Geometry.Evaluate(dashes[i - 1].Shape.Bounds.End); Direction dir2 = eval.Tangent; if (dir1 == dir2) { DatumPlane.Create(part, "miter parallel", Plane.Create(Frame.Create(eval.Point, eval.Tangent.ArbitraryPerpendicular, Direction.Cross(eval.Tangent.ArbitraryPerpendicular, eval.Tangent)))); continue; } Direction averageDir = (dir1.UnitVector + dir2.UnitVector).Direction; Direction xDir = Direction.Cross(averageDir, dir1); // DatumPlane.Create(part, "miter", Plane.Create(Frame.Create(eval.Point, xDir, Direction.Cross(xDir, averageDir)))); double offset = 0.0001 / 2; ShapeHelper.CreateCylinder(eval.Point + averageDir * offset, eval.Point - averageDir * offset, 7 * inches, part); } #endif }