- using System;
- using System.Text;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.Runtime;
- namespace CurlyJigSample
- {
- public class Command
- {
- class CurlyJig : EntityJig
- {
- Polyline m_pline;
- Point3d m_dragPt;
- Point2d p0;
- Vector2d xDir = new Vector2d(1.0, 0.0);
- public CurlyJig(Polyline pline, Point3d dragPt, Point2d pt)
- : base(pline)
- {
- m_pline = pline;
- m_dragPt = dragPt;
- p0 = pt;
- }
- protected override bool Update()
- {
- Point2d p4 = new Point2d(m_dragPt.X, m_dragPt.Y);
- double d = (p0.GetDistanceTo(p4) / 2.0) / (Math.Cos(Math.PI / 12.0));
- Vector2d vec = p0.GetVectorTo(p4);
- double a0 = p4.Y < p0.Y ?
- (Math.PI * 2.0) - xDir.GetAngleTo(vec) :
- xDir.GetAngleTo(vec);
- m_pline.SetPointAt(1, Polar(p0, a0 - (Math.PI / 12.0), d / 2.0));
- m_pline.SetPointAt(2, Polar(p0, a0 - (Math.PI / 12.0), d));
- m_pline.SetPointAt(3, Polar(p4, a0 + Math.PI + (Math.PI / 12.0), d / 2.0));
- m_pline.SetPointAt(4, p4);
- return true;
- }
- protected override SamplerStatus Sampler(JigPrompts prompts)
- {
- JigPromptPointOptions jppo = new JigPromptPointOptions("\nSpecify the second point: ");
- jppo.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.GovernedByOrthoMode);
- PromptPointResult ppr = prompts.AcquirePoint(jppo);
- if (ppr.Status == PromptStatus.OK)
- {
- if (ppr.Value.IsEqualTo(m_dragPt))
- return SamplerStatus.NoChange;
- else
- {
- m_dragPt = ppr.Value;
- return SamplerStatus.OK;
- }
- }
- return SamplerStatus.Cancel;
- }
- }
- private static Point2d Polar(Point2d org, double angle, double distance)
- {
- return new Point2d(org.X + (distance * Math.Cos(angle)), org.Y + (distance * Math.Sin(angle)));
- }
- [CommandMethod("CURLY")]
- public void CURLY()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptPointResult ppr = ed.GetPoint("\nSpecify the first point: ");
- if (ppr.Status == PromptStatus.OK)
- {
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- Point3d picked = ppr.Value.TransformBy(ed.CurrentUserCoordinateSystem);
- Point2d pt = new Point2d(picked.X, picked.Y);
- Polyline pline = new Polyline(5);
- pline.AddVertexAt(0, pt, 0.6, 0.0, 0.0);
- pline.AddVertexAt(1, pt, -0.6, 0.0, 0.0);
- pline.AddVertexAt(2, pt, -0.6, 0.0, 0.0);
- pline.AddVertexAt(3, pt, 0.6, 0.0, 0.0);
- pline.AddVertexAt(4, pt, 0.0, 0.0, 0.0);
- CurlyJig jig = new CurlyJig(pline, picked, pt);
- PromptResult pr = ed.Drag(jig);
- if (pr.Status == PromptStatus.OK)
- {
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- btr.AppendEntity(pline);
- tr.AddNewlyCreatedDBObject(pline, true);
- }
- tr.Commit();
- }
- }
- }
- }
- }
卷曲夹具。拉链