CAD二次开发(C#)第二个例子
2017-06-29 20:47
288 查看
设置参考第一个例子。引入必要的命名空间
第二个例子:交互提示选择一个直线的起始点和终点,然后绘制一条以选择的两个点为始终的直线
代码如下,尽量添加了注释。
编译之后,利用NETLOAD命令,载入生成的DLL,之后输入CreateLine命令,会分别提示选择起始点和终点,选择之后,会在模型空间中绘制一条直线。
选择直线起始点
选择直线终点
最终效果
第二个例子:交互提示选择一个直线的起始点和终点,然后绘制一条以选择的两个点为始终的直线
代码如下,尽量添加了注释。
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Geometry; namespace FirstCAD { public class Class1 { [CommandMethod("CreateLine")]//设计的新命令 public void CreateLine()//CreateLine命令所调用的函数 { //打开数据库 Database db = HostApplicationServices.WorkingDatabase; //获取当前的编辑器输入类 Editor ed = Application .DocumentManager .MdiActiveDocument .Editor ; //点交换输入类;提示选择起始点 PromptPointOptions ppo = new PromptPointOptions("\n请选择直线的起始点"); //点交互输入类:提示选择终点 PromptPointResult ressp = ed.GetPoint(ppo) ; //获取点交互输入类的结果 PromptPointOptions ppe = new PromptPointOptions("\n请选择直线的终点"); PromptPointResult resep = ed.GetPoint(ppe); //点交互类的结果转换为Point3d坐标点 Point3d startPoint = ressp .Value ; Point3d endPoint = resep .Value ; //构建一个直线的实例 Line oldLine = new Line(startPoint ,endPoint ); //启动一个任务,保证操作的原子性 using (Transaction trans = db.TransactionManager.StartTransaction()) { //打开块表, BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead); //打开块表记录,获取模型空间的记录 BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); //在块表记录中添加创建的直线实体 btr.AppendEntity(oldLine); //告知数据库新对象加入 trans.AddNewlyCreatedDBObject(oldLine, true); //任务提交 trans.Commit(); } } } }
编译之后,利用NETLOAD命令,载入生成的DLL,之后输入CreateLine命令,会分别提示选择起始点和终点,选择之后,会在模型空间中绘制一条直线。
选择直线起始点
选择直线终点
最终效果
相关文章推荐
- CAD二次开发(C#)第一个例子
- c# socket 同步开发小例子
- 用c#进行directX开发的一个简单例子
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - 主细表事务处理的标准例子
- 小例子,C#开发之kinect体感交互设备英文语音识别
- C#开发WebService为例子
- C#.NET 大型通用信息化系统集成快速开发平台 4.1 版本 - .NET商业化成品成熟各种数据权限的需求对应例子代码
- C#.NET开发网站例子
- 对C#开发经验技巧宝典-如何对计算结果四舍五入例子的异议
- C# CAD二次开发(三) 绘制多段线
- C#CAD二次开发图案填充对象边界提取
- 有简易通用权限管理后台的快速C# ASP.NET开发的例子应用程序卖给了曾长期开发JAVA银行程序的大哥
- C# CAD二次开发入门(VS2005+CAD2008)
- 软件开发与数学基础 一个C#中的例子——lambda表达式
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 导入导出Microsoft Excel 2010的例子
- 《Windows Mobile 平台应用与开发》C#【人出版】例子下载!
- 有简易通用权限管理后台的快速C# ASP.NET开发的例子应用程序卖给了曾长期开发JAVA银行程序的大哥
- 有简易通用权限管理后台的快速C# ASP.NET开发的例子应用程序卖给了曾长期开发JAVA银行程序的大哥
- C# CAD二次开发 扩展数据的几个重要方法
- 解决C#,CAD二次开发实例化AcadApplicationClass失败