重写了一次,还没完,后面的自己试着写下
-
- [CommandMethod("CTest")]
- public void test()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Editor ed = doc.Editor;
- Database db = doc.Database;
- using (doc.LockDocument())
- {
- PromptPointOptions optPt1 = new PromptPointOptions("\n请选取第一个点:");
- PromptPointResult resPt1 = ed.GetPoint(optPt1);
- if (resPt1.Status != PromptStatus.OK)
- return;
- Point3d pt1 = resPt1.Value;
- PromptPointOptions optPt2 = new PromptPointOptions("\n请选取第二个点:");
- optPt2.BasePoint = pt1;
- optPt2.UseBasePoint = true;
- PromptPointResult resPt2 = ed.GetPoint(optPt2);
- if (resPt2.Status != PromptStatus.OK)
- return;
- Point3d pt2 = resPt2.Value;
- using (Transaction tr = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead, false);
- BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite, false);
- //pt1->pt2方向的单位矢量
- Vector3d vec1 = (pt2 - pt1).GetNormal();
- //垂直方向的向量,长度为5
- Vector3d vec2 = 5 * vec1.RotateBy(Math.PI / 2, Vector3d.ZAxis);
- List<Line> lines = new List<Line>();
- lines.Add(new Line(pt1 - 2 * vec1, pt2 + 2 * vec1));
- lines.Add(new Line(pt1 + vec2, pt2 + vec2));
- lines.Add(new Line(pt1 - vec2, pt2 - vec2));
- foreach (Line line in lines)
- {
- btr.AppendEntity(line);
- tr.AddNewlyCreatedDBObject(line, true);
- }
- tr.Commit();
- }
- }
- }
|