CAD 托管类发送命令
时间: 2023-09-19 11:09:20 浏览: 45
CAD 托管类发送命令通常需要使用以下代码:
```csharp
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
namespace MyCommands
{
public class MyCommandClass
{
[CommandMethod("MyCommand")]
public void MyCommand()
{
// 获取当前文档和数据库
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
// 开始事务
using (Transaction trans = db.TransactionManager.StartTransaction())
{
// 获取当前空间块表记录
BlockTableRecord btr = trans.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForWrite) as BlockTableRecord;
// 创建一个新的直线实体
Line line = new Line(new Point3d(0, 0, 0), new Point3d(10, 10, 0));
// 添加实体到空间块表记录中
btr.AppendEntity(line);
trans.AddNewlyCreatedDBObject(line, true);
// 提交事务
trans.Commit();
}
}
}
}
```
以上代码演示了如何在 CAD 中创建一个新的直线实体并将其添加到当前空间块表记录中。
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)