- 积分
- 82
- 明经币
- 个
- 注册时间
- 2011-2-14
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
- #
- using System;
- #
- using Autodesk.AutoCAD.Runtime;
- #
- using Autodesk.AutoCAD.Geometry;
- #
- using Autodesk.AutoCAD.ApplicationServices;
- #
- using Autodesk.AutoCAD.DatabaseServices;
- #
- using Autodesk.AutoCAD.EditorInput;
- #
- namespace CADTest
- #
- {
- #
- public class Class1
- #
- {
- #
- [CommandMethod("c2p")]
- #
- public void CircleToPloyline()
- #
- {
- #
- Document doc = Application.DocumentManager.MdiActiveDocument;
- #
- Database db = doc.Database;
- #
- Editor ed = doc.Editor;
- #
- Transaction trans = db.TransactionManager.StartTransaction();
- #
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- #
- BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
- #
- PromptSelectionResult psr = ed.GetSelection();
- #
- //获取选择集,这里就不过滤了
- #
- SelectionSet ss = null;
- #
- if (psr.Status == PromptStatus.OK)
- #
- {
- #
- ss = psr.Value;
- #
- foreach (SelectedObject so in ss)
- #
- {
- #
- Circle c = trans.GetObject(so.ObjectId, OpenMode.ForWrite) as Circle;
- #
- double r = c.Radius;
- #
- Point3d cc = c.Center;
- #
- Point2d p1 = new Point2d(cc.X + r, cc.Y);
- #
- Point2d p2 = new Point2d(cc.X - r, cc.Y);
- #
- Polyline poly = new Polyline();
- #
- poly.AddVertexAt(0, p1, 1, 0, 0);
- #
- poly.AddVertexAt(1, p2, 1, 0, 0);
- #
- poly.AddVertexAt(2, p1, 1, 0, 0);
- #
- btr.AppendEntity(poly);
- #
- trans.AddNewlyCreatedDBObject(poly, true);
- #
- c.Erase(true);
- #
- }
- #
- }
- #
- trans.Commit();
- #
- trans.Dispose();
- #
- }
- #
- #
- [CommandMethod("GET")]
- #
- public void GetEntityType()
- #
- {
- #
- Document doc = Application.DocumentManager.MdiActiveDocument;
- #
- Database db = doc.Database;
- #
- Editor ed = doc.Editor;
- #
- PromptEntityOptions peo = new PromptEntityOptions("请选择一个实体");
- #
- PromptEntityResult per = null;
- #
- try
- #
- {
- #
- per = ed.GetEntity(peo);
- #
- if (per.Status == PromptStatus.OK)
- #
- {
- #
- ObjectId id = per.ObjectId;
- #
- Transaction trans = db.TransactionManager.StartTransaction();
- #
- Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead, true);
- #
- #
- ed.WriteMessage("\n实体ObjectId 为:" + ent.ObjectId + "\n实体类型为:" + ent.GetType().FullName);
- #
- trans.Commit();
- #
- trans.Dispose();
- #
- }
- #
- }
- #
- catch (Autodesk.AutoCAD.Runtime.Exception exc)
- #
- {
- #
- ed.WriteMessage("发生异常,原因为:" + exc.Message);
- #
- }
- #
- }
- #
- }
- #
- }
|
|