马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
本程序运用于对象捕捉,运行时,拾取一个圆或圆弧、椭圆,能得到圆心(当然,不用这个方法也能得到)。圆心捕捉也可更改为中点捕捉、象限点捕捉等……
- using System;
- using Autodesk.AutoCAD.ApplicationServices;
- using Autodesk.AutoCAD.Runtime;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- namespace CS对象捕捉
- {
- /// <summary>
- /// TestClass的说明。
- /// </summary>
- public class TestClass
- {
- [CommandMethod("Test")]
- public void Test()
- {
- Database db = HostApplicationServices.WorkingDatabase;
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- PromptEntityOptions opt = new PromptEntityOptions("\n请选择圆、圆弧或椭圆");
- opt.SetRejectMessage("\n您选择的对象不存在圆心,请重新选择!");
- opt.AddAllowedClass(typeof(Circle), true);
- opt.AddAllowedClass(typeof(Arc), true);
- opt.AddAllowedClass(typeof(Ellipse), true);
- PromptEntityResult res = ed.GetEntity(opt);
- if (res.Status == PromptStatus.OK)
- {
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- Entity ent = (Entity)trans.GetObject(res.ObjectId, OpenMode.ForRead);
- Point3d pickPt = res.PickedPoint;
- Point3dCollection snapPts = new Point3dCollection();
- IntegerCollection geomIds = new IntegerCollection();
- geomIds.Add(0);
- ent.GetObjectSnapPoints(ObjectSnapModes.ModeCenter, 0, pickPt,
- pickPt, Matrix3d.Identity, snapPts, geomIds);
- ed.WriteMessage("\n您点取的点是:" + pickPt.ToString());
- for (int i = 0; i < snapPts.Count; i++)
- {
- ed.WriteMessage("\n您捕捉到的点是:" + snapPts.ToString());
- }
- trans.Commit();
- }
- }
- }
- }
- }
|