下面是一个使用C#语言编写的.NET平台上的
CAD应用程序的代码示例,实现了自动
捕捉端点功能:
using Autodesk.AutoCAD.Runtime;using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;namespace MyCADApp{public class MyCommands{[CommandMethod("MyLine")]public void MyLine(){Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;using (Transaction tr = db.TransactionManager.StartTransaction()){BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead);BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);PromptPointOptions ppo1 = new PromptPointOptions("Start point: ");ppo1.UseBasePoint = true;ppo1.BasePoint = Point3d.Origin;ppo1.UseDashedLine = true;ppo1.AllowNone = true;ppo1.Keywords.Add("E");ppo1.Keywords.Add("X");ppo1.Keywords.Default = "E";PromptPointResult ppr1 = ed.GetPoint(ppo1);if (ppr1.Status != PromptStatus.OK) return;if (ppr1.Status == PromptStatus.Keyword){if (ppr1.StringResult == "X") return;else if (ppr1.StringResult == "E"){ppo1.UseBasePoint = false;ppo1.UseDashedLine = false;ppo1.Message = "Endpoint: ";ppo1.Keywords.Clear();}}PromptPointOptions ppo2 = new PromptPointOptions("End point: ");ppo2.UseBasePoint = true;ppo2.BasePoint = ppr1.Value;ppo2.UseDashedLine = true;ppo2.AllowNone = true;ppo2.Keywords.Add("E");ppo2.Keywords.Add("X");ppo2.Keywords.Default = "E";PromptPointResult ppr2 = ed.GetPoint(ppo2);if (ppr2.Status != PromptStatus.OK) return;if (ppr2.Status == PromptStatus.Keyword){if (ppr2.StringResult == "X") return;else if (ppr2.StringResult == "E"){ppo2.UseBasePoint = false;ppo2.UseDashedLine = false;ppo2.Message = "Endpoint: ";ppo2.Keywords.Clear();}}Line line = new Line(ppr1.Value, ppr2.Value);btr.AppendEntity(line);tr.AddNewlyCreatedDBObject(line, true);tr.Commit();}}}}
在这个代码示例中,使用了
AutoCAD的API中的PromptPointOptions类的UseBasePoint属性和UseDashedLine属性来实现自动
捕捉端点功能。在获取起点坐标时,
设置UseBasePoint属性为true,并将BasePoint属性
设置为原点,同时
设置UseDashedLine属性为true,这样在鼠标移动过程中,会自动
捕捉到距离原点最近的端点。在获取终点坐标时,
设置UseBasePoint属性为true,并将BasePoint属性
设置为起点坐标,同时
设置UseDashedLine属性为true,这样在鼠标移动过程中,会自动
捕捉到距离起点坐标最近的端点。通过使用PromptPointOptions类的Keywords属性,可以添加关键字,实现在命令过程中的交互。
到此这篇ad20怎么设置捕捉(ad20怎么捕捉线的中心)的文章就介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!版权声明:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若内容造成侵权、违法违规、事实不符,请将相关资料发送至xkadmin@xkablog.com进行投诉反馈,一经查实,立即处理!
转载请注明出处,原文链接:https://www.xkablog.com/qkl-jr/14258.html