C# 二次开发cad获取鼠标点击坐标
时间: 2023-07-12 19:09:09 浏览: 341
以下是C#二次开发CAD获取鼠标点击坐标的示例:
```csharp
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
namespace GetMousePoint
{
public class Commands
{
[CommandMethod("GetMousePoint")]
public void GetMousePoint()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
// 获取鼠标点击点
PromptPointOptions ppo = new PromptPointOptions("\n选择点: ");
PromptPointResult ppr = ed.GetPoint(ppo);
if (ppr.Status != PromptStatus.OK) return;
Point3d pt = ppr.Value;
ed.WriteMessage("\nX坐标:{0}, Y坐标:{1}, Z坐标:{2}", pt.X, pt.Y, pt.Z);
}
}
}
```
上述代码中,通过 `ed.GetPoint` 方法获取鼠标点击点,然后通过 `PromptPointResult` 的 `Value` 属性获取点的坐标。最后,将获取到的坐标打印到命令行窗口中。
阅读全文