用.NET阻止AutoCAD对象被选中

2024-06-10 11:32
文章标签 对象 net 选中 autocad 阻止

本文主要是介绍用.NET阻止AutoCAD对象被选中,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文:Preventing AutoCAD objects from being selected using .NET

在上一篇文章中我们看到如何阻止实体在选择中被高亮显示。这一片文章我们将会看到如何阻止实体被选中。再次感谢 Balaji Ramamoorthyt 提供的代码

我们采用的基本方案和上一篇相似,我们维护一份我们想阻止被选择的对象的DXF名称列表。但是它可以很容易的被改进成用其他的条件来讲对象从选择集中删除

如果我们使用单个实体选择函数(GetEntity())而不是用GetSelection(),我们可能需要使用另外一种方式来过滤:我们可能需要用PrompEntityOptions.AddAllowedClass()来允许特定的类型。但是我们也可以使用这一技术用于实体选择。尤其是我们用其他的条件(例如不是基于实体类型)来阻止实体被选择

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System.Collections.Generic;
using System.Text;namespace PreventSelection
{public class Test : IExtensionApplication{void OnSelectionAdded(object sender, SelectionAddedEventArgs e){ObjectId[] addedIds = e.AddedObjects.GetObjectIds();for (int i=0; i < addedIds.Length; i++){ObjectId oid = addedIds[i];if (IsInList(oid.ObjectClass.DxfName)){e.Remove(i);}}}[CommandMethod("US")]public static void Unselect(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;// Print the list of currently unhighlighted classesed.WriteMessage(ListToPrint());// Get the type to add to the listPromptResult pr =ed.GetString("\nEnter the type of object to stop from " +"being selected: ");if (pr.Status != PromptStatus.OK)return;if (IsInList(pr.StringResult)){ed.WriteMessage("\nItem already in the list.");}else{AddToList(pr.StringResult);ed.WriteMessage("\nItem added to the list.");}}// Would call this command RS, but it's taken by RSCRIPT,// so using the somewhat unwieldy UUS, instead[CommandMethod("UUS")]public static void Ununselect(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;// Print the list of currently unhighlighted classesed.WriteMessage(ListToPrint());// Get the type to remove from the listPromptResult pr =ed.GetString("\nEnter the type of object to remove from the " +"list: ");if (pr.Status != PromptStatus.OK)return;if (!IsInList(pr.StringResult)){ed.WriteMessage("\nItem not currently in the list.");}else{RemoveFromList(pr.StringResult);ed.WriteMessage("\nItem removed from the list.");}}void IExtensionApplication.Initialize(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.SelectionAdded +=new SelectionAddedEventHandler(OnSelectionAdded);}void IExtensionApplication.Terminate(){Document doc = Application.DocumentManager.MdiActiveDocument;Editor ed = doc.Editor;ed.SelectionAdded -=new SelectionAddedEventHandler(OnSelectionAdded);}// The list of types to unhighlightstatic List<string> _unhighlighted = new List<string>();// Add a type to the listpublic static void AddToList(string name){string upper = name.ToUpper();if (!_unhighlighted.Contains(upper)){_unhighlighted.Add(upper);}}// Remove a type from the listpublic static void RemoveFromList(string name){string upper = name.ToUpper();if (_unhighlighted.Contains(upper)){_unhighlighted.Remove(upper);}}// Check whether the list contains a typepublic static bool IsInList(string name){return _unhighlighted.Contains(name.ToUpper());}// Get a string printing the contents of the listpublic static string ListToPrint(){string toPrint;if (_unhighlighted.Count == 0){toPrint ="\nThere are currently no objects in the list " +"to stop from being selected.";}else{StringBuilder sb =new StringBuilder("\nObjects of these types will not be selected:");foreach (string name in _unhighlighted){sb.Append(" " + name);}toPrint = sb.ToString();}return toPrint;}}
}


这篇关于用.NET阻止AutoCAD对象被选中的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1048044

相关文章

Spring中管理bean对象的方式(专业级说明)

《Spring中管理bean对象的方式(专业级说明)》在Spring框架中,Bean的管理是核心功能,主要通过IoC(控制反转)容器实现,下面给大家介绍Spring中管理bean对象的方式,感兴趣的朋... 目录1.Bean的声明与注册1.1 基于XML配置1.2 基于注解(主流方式)1.3 基于Java

C++/类与对象/默认成员函数@构造函数的用法

《C++/类与对象/默认成员函数@构造函数的用法》:本文主要介绍C++/类与对象/默认成员函数@构造函数的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录名词概念默认成员函数构造函数概念函数特征显示构造函数隐式构造函数总结名词概念默认构造函数:不用传参就可以

C++类和对象之默认成员函数的使用解读

《C++类和对象之默认成员函数的使用解读》:本文主要介绍C++类和对象之默认成员函数的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、默认成员函数有哪些二、各默认成员函数详解默认构造函数析构函数拷贝构造函数拷贝赋值运算符三、默认成员函数的注意事项总结一

golang 对象池sync.Pool的实现

《golang对象池sync.Pool的实现》:本文主要介绍golang对象池sync.Pool的实现,用于缓存和复用临时对象,以减少内存分配和垃圾回收的压力,下面就来介绍一下,感兴趣的可以了解... 目录sync.Pool的用法原理sync.Pool 的使用示例sync.Pool 的使用场景注意sync.

SpringBoot项目中Redis存储Session对象序列化处理

《SpringBoot项目中Redis存储Session对象序列化处理》在SpringBoot项目中使用Redis存储Session时,对象的序列化和反序列化是关键步骤,下面我们就来讲讲如何在Spri... 目录一、为什么需要序列化处理二、Spring Boot 集成 Redis 存储 Session2.1

Java实例化对象的​7种方式详解

《Java实例化对象的​7种方式详解》在Java中,实例化对象的方式有多种,具体取决于场景需求和设计模式,本文整理了7种常用的方法,文中的示例代码讲解详细,有需要的可以了解下... 目录1. ​new 关键字(直接构造)​2. ​反射(Reflection)​​3. ​克隆(Clone)​​4. ​反序列化

C++类和对象之初始化列表的使用方式

《C++类和对象之初始化列表的使用方式》:本文主要介绍C++类和对象之初始化列表的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录C++初始化列表详解:性能优化与正确实践什么是初始化列表?初始化列表的三大核心作用1. 性能优化:避免不必要的赋值操作2. 强

使用easy connect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题

《使用easyconnect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题》:本文主要介绍使用easyconnect之后,maven无法... 目录使用easGWowCy connect之后,maven无法使用,原来需要配置-DJava.net.pr

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

Java对象转换的实现方式汇总

《Java对象转换的实现方式汇总》:本文主要介绍Java对象转换的多种实现方式,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录Java对象转换的多种实现方式1. 手动映射(Manual Mapping)2. Builder模式3. 工具类辅助映