目录

  • Editor
  • 拖动类EntityJig
  • 选择集

Editor

在C#进行CAD二次开发时,Editor类是一个特别有用的类。它提供了大量常用的接口函数,比如:

// 拖动相关接口
public PromptPointResult Drag(SelectionSet selection, string message, DragCallback callback);
public PromptResult Drag(Jig jig);
public PromptPointResult Drag(PromptDragOptions options);// 获取点
public PromptPointResult GetPoint(PromptPointOptions options);
public PromptPointResult GetPoint(string message);// 获取选择集
public PromptSelectionResult GetSelection(PromptSelectionOptions options, SelectionFilter filter);
public PromptSelectionResult GetSelection(PromptSelectionOptions options);
public PromptSelectionResult GetSelection(SelectionFilter filter);
public PromptSelectionResult GetSelection();// 调用选择集相关接口
public PromptSelectionResult SelectAll();
public PromptSelectionResult SelectAll(SelectionFilter filter);
public PromptSelectionResult SelectCrossingPolygon(Point3dCollection polygon);
public PromptSelectionResult SelectCrossingPolygon(Point3dCollection polygon, SelectionFilter filter);
public PromptSelectionResult SelectCrossingWindow(Point3d pt1, Point3d pt2, SelectionFilter filter, bool forceSubEntitySelection);
public PromptSelectionResult SelectCrossingWindow(Point3d pt1, Point3d pt2);
public PromptSelectionResult SelectCrossingWindow(Point3d pt1, Point3d pt2, SelectionFilter filter);
public PromptSelectionResult SelectFence(Point3dCollection fence);
public PromptSelectionResult SelectFence(Point3dCollection fence, SelectionFilter filter);
public PromptSelectionResult SelectImplied();
public PromptSelectionResult SelectLast();
public PromptSelectionResult SelectPrevious();
public PromptSelectionResult SelectWindow(Point3d pt1, Point3d pt2);
public PromptSelectionResult SelectWindow(Point3d pt1, Point3d pt2, SelectionFilter filter);
public PromptSelectionResult SelectWindowPolygon(Point3dCollection polygon);
public PromptSelectionResult SelectWindowPolygon(Point3dCollection polygon, SelectionFilter filter);

Editor相当于CAD的编辑器,因此提供了大量的接口供我们使用,这里列举了其中一部分。关于Editor接口函数,需要不断的积累掌握。

拖动类EntityJig

实现代码,以模仿CAD绘制直线的命令为例

using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace JigDemo
{// 定义拖动类,继承EntityJigpublic class LineJig : EntityJig{private Point3d m_ptStart;private Point3d m_ptEnd;private string m_sMessage;private string[] m_sKeywords;/// <summary>/// 构造函数/// </summary>/// <param name="ptStart">直线起点</param>/// <param name="sMessage">命令行信息</param>/// <param name="sKeywords">关键字</param>public LineJig(Point3d ptStart, string sMessage, params string[] sKeywords):base(new Line()){m_ptStart = ptStart;m_sMessage = sMessage;m_sKeywords = sKeywords;((Line)Entity).StartPoint = ptStart;}/// <summary>/// 取样函数/// </summary>/// <param name="prompts">拖拽信息提示类,可获取结果</param>/// <returns></returns>protected override SamplerStatus Sampler(JigPrompts prompts){// 声明提示信息类JigPromptPointOptions jppo = new JigPromptPointOptions(m_sMessage);// 添加关键字for (int i = 0; i < m_sKeywords.Length; i++){jppo.Keywords.Add(m_sKeywords[i]);}char space = ' ';jppo.Keywords.Add(space.ToString());// 设置获取的信息类型jppo.UserInputControls = UserInputControls.Accept3dCoordinates; // 3d坐标点// 取消系统自动添加的关键字jppo.AppendKeywordsToMessage = false;PromptPointResult ppr = prompts.AcquirePoint(jppo);m_ptEnd = ppr.Value;return SamplerStatus.NoChange;}// 更新实体protected override bool Update(){((Line)Entity).EndPoint = m_ptEnd;return true;}// 获取实体public Entity GetEntity(){return Entity;}}
}// 调用相关代码
Editor editor = Application.DocumentManager.MdiActiveDocument.Editor;
LineJig linejig = new LineJig(ptPre, "\n 指定下一点或[闭合(C)/放弃(U)]", new string[] { "C", "U" });
PromptResult pr = editor.Drag(linejig);

选择集

可以直接调用Editor的相关接口,过滤器SelectionFilter
示例:

{Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;TypedValue value = new TypedValue((int)DxfCode.Start, "CIRCLE"); // 实体类型名称 圆TypedValue[] values = new TypedValue[]{value}// 过滤器SelectionFilter filter = new SelectionFilter(values); PromptSelectionResult psr = ed.GetSelection(filter);if (psr.Status == PromptStatus.OK){// 选择集SelectionSet ss = psr.Value;ObjectId[] selIds = ss.GetObjectIds();}
}

Editor提供了丰富的接口可供我们调用
比如public PromptSelectionResule SelectionImplied(); 函数,可以获取图面上已经选中的实体到结果选择集里面,此时要注意在写命令时,添加如下参数

[CommandMethod("PickFirst" , CommandFlags.UserPickSet)]
  1. CommandMethod() 函数具有多种重载;
  2. CommandFlags 来表示命令函数具备的一些属性

C#进行CAD二次开发学习笔记--02相关推荐

  1. 基于C#的中望CAD二次开发学习笔记(1)环境测试

    目录 前言 一.ZRXSDK的安装使用 二.创建项目 三.编写环境测试代码 四.在ZWCAD中测试 参考资料 总结 前言 作为一个设计院搬砖人,和各种CAD打交道是必不可少的.当然,其中最为正统的是A ...

  2. 引用:基于C#的中望CAD二次开发学习笔记

    目录 前言 一.ZRXSDK的安装使用 二.创建项目 三.编写环境测试代码 四.在ZWCAD中测试 参考资料 总结 前言 作为一个设计院搬砖人,和各种CAD打交道是必不可少的.当然,其中最为正统的是A ...

  3. C#进行CAD二次开发学习笔记-01

    一些基础知识 需要引用CAD的库文件 常用接口和类 与C++ ---- ObjectArx库的一些区别 需要引用CAD的库文件 accoremad.dll acdbmgd.dll acmgd.dll ...

  4. CAD二次开发学习笔记二(创建一个对话框)

    打开资源视图->右击->添加资源->Dialog 双击对话框,弹出MFC类向导,输入类名FirstClass, 确定,创建对话框类.FirstClass.h与FirstClass.c ...

  5. CAD二次开发学习笔记四(得到选中的实体,修改实体,如等分线段)

    AcGeVector3d是点阵的集合,通过等分点的差集得到. 新的点可以通过点与点阵相差得到. 大气象 public: // - ArxProject2.partLine command (do no ...

  6. CAD二次开发学习笔记五(在ObjectARX中使用MFC)

    要实现的功能是: 执行ArxModal命令,弹出如图所示对话框 选择点,则得到点坐标,选择角度则得到角度值. 步骤一: 新建基于MFC的ObjectArx项目, 参考:http://www.cnblo ...

  7. cad二次开发 java_基于.NET的CAD二次开发学习笔记一:CAD开发入门

    1.AutoCAD .NET API由不同的DLL文件组成,它们提供用于访问图形文件或AutoCAD应用程序的包含丰富的类.结构.方法和事件.每一个DLL文件都定义不同的使用基于功能的库组织组件的命名 ...

  8. Revit二次开发学习笔记

    Revit二次开发学习笔记1 20220314: 概念:Application与Document 接口函数:IExternalCommand.ActiveView与Selection 20220316 ...

  9. AUTOCAD 二次开发学习笔记

    图层处理: ​​​​​​(16条消息) C#之CAD二次开发实例 (13) 图层操作_yzk1062913581的博客-CSDN博客 (16条消息) .NET AutoCAD二次开发之路(二.直线篇) ...

最新文章

  1. java如何调用thrift_java – 我想在一个传输上使用多个服务(Thrift)
  2. linux 重新加载驱动程序,在linux中模拟设备驱动程序崩溃。让python重新加载i
  3. iOS之性能优化·提高App的编译速度
  4. iOS imageio nsurlsession 渐进式图片下载
  5. jquery页面滚动显示浮动菜单栏锚点定位效果
  6. TextView的一些高级应用(自定义字体、显示多种颜色、添加阴影)
  7. 如果Service有多个实现类,Spring怎么知道该注入哪个实现类
  8. 开发者如何在一周从入门级到专家级别的修炼
  9. java怎么设置颜色_java怎么设置颜色
  10. 软件产品测试报告模板
  11. JavaCV入门教程目录(JavaCV从入门到实战,JavaCV指南手册,免费JavaCV教程)
  12. mysql数据库的流水号生成,数据库流水号生成解决方案
  13. Android 绘制录音波浪 + 拓展: 让“字体”迎波而浪
  14. 请问这个问题怎么解决呀?打开什么也用不了
  15. 如何解决苹果笔记本连接显示器显示不全的问题
  16. 【读一本书】《昇腾AI处理器架构与编程》--神经网络基本知识学习(1)
  17. 湖北省钟祥一中2021高考成绩查询,京山一中的2020高考喜报三天前就发布了,钟祥一中为什么还没有公布?...
  18. 使用Cocos Creator制作试玩广告(PlayableAd)
  19. WIN10下 docker报错Error response from daemon: invalid mode
  20. [ITIL]-ITIL4架构

热门文章

  1. Android中ClearEditText自带清除功能的EditText
  2. Day171.基本内容 -Dubbo
  3. 【腾讯Bugly干货分享】React Native项目实战总结
  4. charm-crypto-0.5安装
  5. python项目之学员CRM管理系统开发阶段一-李杰-专题视频课程
  6. 带你走进华为组播IGMP 简单易懂
  7. abstract关键字的使用
  8. RF工程师必须掌握的内容:从浅入深解说S参数
  9. mysql .net orm_.NET(C#)主流的ORM框架
  10. 如何不通过iTunes将Mac上的音乐同步到iPad