- [CommandMethod("t2")]
- public static void Test2()
- {
- var db = HostApplicationServices.WorkingDatabase;
- var doc = Application.DocumentManager.GetDocument(db);
- var ed = doc.Editor;
- var resDbl = ed.GetDouble("\n输入六边形的高度:");
- if (resDbl.Status != PromptStatus.OK)
- return;
- //边长
- double a = resDbl.Value / Math.Pow(3, 0.5);
- using (var tr = db.TransactionManager.StartTransaction())
- {
- var pl = new Polyline();
- //以0,0为起点
- Point2d pt = Point2d.Origin;
- //按边长生成一个向量
- Vector2d vec = Vector2d.XAxis * a;
- for (int i = 0; i < 6; i++)
- {
- pl.AddVertexAt(i, pt, 0, 0, 0);
- //移动到下一个点
- pt += vec;
- //循环每步将向量旋转60度
- vec = vec.RotateBy(Math.PI / 3);
- }
- pl.Closed = true;
- var btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- btr.AppendEntity(pl);
- tr.AddNewlyCreatedDBObject(pl, true);
- tr.Commit();
- }
- }
|