C# 二次开发cad获取鼠标点击坐标代码
时间: 2023-10-13 16:04:17 浏览: 312
你可以使用 AutoCAD 自带的 .NET API 来实现 C# 二次开发,获取鼠标点击坐标的代码如下:
```csharp
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
public Point3d GetMouseClickPoint()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
PromptPointResult result = ed.GetPoint("Click a point:");
if (result.Status == PromptStatus.OK)
{
return result.Value;
}
return Point3d.Origin;
}
```
以上代码会弹出 AutoCAD 的提示框,让用户点击一个点,然后返回该点的坐标。你可以将其封装到自己的类或方法中,以便在你的程序中方便地调用。
相关问题
c# 二次开发cad获取鼠标点击坐标
以下是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` 属性获取点的坐标。最后,将获取到的坐标打印到命令行窗口中。
C# 二次开发cad获取鼠标点击坐标
以下是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` 属性获取点的坐标。最后,将获取到的坐标打印到命令行窗口中。
阅读全文