
[CommandMethod("FirstLine")]
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
ed.WriteMessage("\n开始执行FirstLine\n");
Database db = HostApplicationServices.WorkingDatabase;
Point3d startPoint = new Point3d(0, 1000, 0);
Point3d endPoint = new Point3d(0, 500, 0);
Line line = new Line(startPoint, endPoint);
Circle circle1 = new Circle(Point3d.Origin, Vector3d.ZAxis, 480);
Point3dCollection pc1 = new Point3dCollection();
circle1.IntersectWith(new Line(new Point3d(400,140,0), new Point3d(540, 60, 0)),
Intersect.OnBothOperands, pc1, IntPtr.Zero, IntPtr.Zero);
Point3dCollection pc2 = new Point3dCollection();
circle1.IntersectWith(new Line(new Point3d(400, -140, 0), new Point3d(540, -60, 0)),
Intersect.OnBothOperands, pc2, IntPtr.Zero, IntPtr.Zero);
Point2dCollection point2Ds = new Point2dCollection();
point2Ds.Add(new Point2d(pc1[0].X,pc1[0].Y));
point2Ds.Add(new Point2d(540, 60));
point2Ds.Add(new Point2d(540, -60));
point2Ds.Add(new Point2d(pc2[0].X, pc2[0].Y));
Polyline polyline = new Polyline();
foreach (var point2D in point2Ds)
polyline.AddVertexAt(tmp++,point2D,0,1,1);
Circle circle = new Circle(Point3d.Origin,Vector3d.ZAxis,400);
using (Transaction trans = db.TransactionManager.StartTransaction())
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
btr.AppendEntity(polyline);
trans.AddNewlyCreatedDBObject(polyline, true);
List ents= polyline.ObjectId.ArrayPolarEntity(12, 360, new Point3d(0, 0, 0));
using (Transaction trans = db.TransactionManager.StartTransaction())
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
CircularArc3d geArc = new CircularArc3d(circle1.Center, Vector3d.ZAxis, circle1.Radius);
for (int i = 0; i < ents.Count; i++)
Polyline pl = (Polyline)ents[i];
Polyline pl1 = (Polyline)ents[(i+1)%ents.Count];
pStart = pl.GetPoint2dAt(0);
pEnd = pl1.GetPoint2dAt(pl.NumberOfVertices - 1);
pt1 = new Point3d(pStart.X, pStart.Y, 0);
pt2 = new Point3d(pEnd.X,pEnd.Y,0);
arc.Center = geArc.Center;
arc.Radius = geArc.Radius;
arc.StartAngle = pt1.AngleFromXAxis(geArc.Center);
arc.EndAngle = pt2.AngleFromXAxis(geArc.Center);
trans.AddNewlyCreatedDBObject(arc, true);
btr.AppendEntity(circle);
trans.AddNewlyCreatedDBObject(circle, true);
System.Diagnostics.Debug.WriteLine("FirstLine 已经执行");

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using System.Collections.Generic;
using System.Threading.Tasks;
public static double AngleFromXAxis(this Point3d pt1, Point3d pt2)
Vector2d vector=new Vector2d(pt1.X-pt2.X, pt1.Y-pt2.Y);
public static double DegreeToAngle(this Double degree)
return degree * Math.PI / 180;
public static double AngleToDegree(this Double angle)
return angle * 180 / Math.PI;
public static List ArrayPolarEntity(this ObjectId entId, int num, double degree, Point3d center)
List entList = new List();
using (Transaction trans = entId.Database.TransactionManager.StartTransaction())
BlockTable bt = (BlockTable)trans.GetObject(entId.Database.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
Entity ent = (Entity)entId.GetObject(OpenMode.ForWrite);
degree = degree > 360 ? 360 : degree;
degree = degree < -360 ? 360 : degree;
if (degree == 360 || degree == -360)
for (int i = 0; i < num; i++)
Matrix3d mt = Matrix3d.Rotation((i * degree / divAngnum).DegreeToAngle(), Vector3d.ZAxis, center);
Entity entA = ent.GetTransformedCopy(mt);
trans.AddNewlyCreatedDBObject(entA, true);
