当前位置: 首页 > news >正文

002集—— CAD划线并模拟向命令窗口发送命令(CAD—C#二次开发入门)

模拟向命令窗口发送全图居中的命令:  Application.DocumentManager.MdiActiveDocument.SendStringToExecute("z\ne\n",true,false,false); 

弹窗命令:

 Application.ShowAlertDialog("Erase the newly added polyline.");

本例在cad画一条线并全图显示:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ClassLibrary4
{public class Class1{[CommandMethod("xx")]public static void AngleFromXAxis(){//// 获得当前文档和数据库   Get the current document and databaseDocument acDoc = Application.DocumentManager.MdiActiveDocument;Database acCurDb = acDoc.Database;// 启动一个事务  Start a transactionusing (Transaction acTrans = acCurDb.TransactionManager.StartTransaction()){// 以只读方式打开块表   Open the Block table for readBlockTable acBlkTbl;acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,OpenMode.ForRead) as BlockTable;// 以写方式打开模型空间块表记录   Open the Block table record Model space for writeBlockTableRecord acBlkTblRec;acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],OpenMode.ForWrite) as BlockTableRecord;// 创建一条轻量多段线     Create a lightweight polylinePolyline acPoly = new Polyline();acPoly.SetDatabaseDefaults();acPoly.AddVertexAt(0, new Point2d(2, 4), 0, 0, 0);acPoly.AddVertexAt(1, new Point2d(4, 2), 0, 0, 0);acPoly.AddVertexAt(2, new Point2d(6, 4), 0, 0, 0);// 添加新对象到块表记录和事务中   Add the new object to the block table record and the transactionacBlkTblRec.AppendEntity(acPoly);acTrans.AddNewlyCreatedDBObject(acPoly, true);// 更新显示并显示一条提醒消息    Update the display and display an alert messageacDoc.Editor.Regen();//acDoc.Editor.WriteMessage("z\n");//acDoc.Editor.Regen();//acDoc.Editor.WriteMessage("e\n");Application.DocumentManager.MdiActiveDocument.SendStringToExecute("z\ne\n",true,false,false); acDoc.Editor.Regen();Application.DocumentManager.MdiActiveDocument.SendStringToExecute("regen", true, false, false);Application.ShowAlertDialog("pl线已画好");// 从图形中删除多段线    Erase the polyline from the drawing//acPoly.Erase(true);// Application.ShowAlertDialog("pl线已删除");// 保存新对象到数据库中   Save the new object to the databaseacTrans.Commit();}////}}
}

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 绿荫德清,数聚聚宝汇智—聚宝用户夏日交流会圆满落幕
  • linux 操作系统下cu命令介绍和使用案例
  • PHP悦读随行一键借阅图书小程序
  • 计算机网络:概述 - 性能指标
  • 深度学习经典模型之T5
  • matlab处理函数3
  • C++库std::clamp
  • Docker容器创建时,无法访问镜像源:Could not connect to archive.ubuntu.com:80
  • 【项目】高并发内存池
  • Rust 数据类型
  • 坐牢第三十七天(Qt)
  • 【C++算法】分治——归并
  • 每日必抢小程序下单总结
  • C++——深部解析哈希
  • 助力汽车零部件产业发展,2025 第十二届广州国际汽车零部件加工技术及汽车模具展览会与您相约“羊城”广州
  • 【162天】黑马程序员27天视频学习笔记【Day02-上】
  • C++类中的特殊成员函数
  • Docker下部署自己的LNMP工作环境
  • ES学习笔记(12)--Symbol
  • Iterator 和 for...of 循环
  • java 多线程基础, 我觉得还是有必要看看的
  • JS 面试题总结
  • leetcode388. Longest Absolute File Path
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • SQLServer之创建数据库快照
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • 产品三维模型在线预览
  • 成为一名优秀的Developer的书单
  • 将回调地狱按在地上摩擦的Promise
  • 聚类分析——Kmeans
  • 双管齐下,VMware的容器新战略
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 微信小程序:实现悬浮返回和分享按钮
  • 阿里云移动端播放器高级功能介绍
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • ​​​​​​​开发面试“八股文”:助力还是阻力?
  • ​Java并发新构件之Exchanger
  • ​软考-高级-信息系统项目管理师教程 第四版【第14章-项目沟通管理-思维导图】​
  • #Linux(帮助手册)
  • (12)Linux 常见的三种进程状态
  • (4)(4.6) Triducer
  • (Redis使用系列) Springboot 实现Redis 同数据源动态切换db 八
  • (第8天)保姆级 PL/SQL Developer 安装与配置
  • (附源码)ssm高校升本考试管理系统 毕业设计 201631
  • (附源码)ssm经济信息门户网站 毕业设计 141634
  • (四)stm32之通信协议
  • (学习总结16)C++模版2
  • *Django中的Ajax 纯js的书写样式1
  • *p=a是把a的值赋给p,p=a是把a的地址赋给p。
  • .mysql secret在哪_MySQL如何使用索引
  • .net MVC中使用angularJs刷新页面数据列表
  • .net6+aspose.words导出word并转pdf
  • @DateTimeFormat 和 @JsonFormat 注解详解
  • @entity 不限字节长度的类型_一文读懂Redis常见对象类型的底层数据结构
  • @property括号内属性讲解