用.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

相关文章

JavaScript对象转数组的三种方法实现

《JavaScript对象转数组的三种方法实现》本文介绍了在JavaScript中将对象转换为数组的三种实用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友... 目录方法1:使用Object.keys()和Array.map()方法2:使用Object.entr

C#利用Free Spire.XLS for .NET复制Excel工作表

《C#利用FreeSpire.XLSfor.NET复制Excel工作表》在日常的.NET开发中,我们经常需要操作Excel文件,本文将详细介绍C#如何使用FreeSpire.XLSfor.NET... 目录1. 环境准备2. 核心功能3. android示例代码3.1 在同一工作簿内复制工作表3.2 在不同

使用MapStruct实现Java对象映射的示例代码

《使用MapStruct实现Java对象映射的示例代码》本文主要介绍了使用MapStruct实现Java对象映射的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、什么是 MapStruct?二、实战演练:三步集成 MapStruct第一步:添加 Mave

Java中实现对象的拷贝案例讲解

《Java中实现对象的拷贝案例讲解》Java对象拷贝分为浅拷贝(复制值及引用地址)和深拷贝(递归复制所有引用对象),常用方法包括Object.clone()、序列化及JSON转换,需处理循环引用问题,... 目录对象的拷贝简介浅拷贝和深拷贝浅拷贝深拷贝深拷贝和循环引用总结对象的拷贝简介对象的拷贝,把一个

在.NET项目中嵌入Python代码的实践指南

《在.NET项目中嵌入Python代码的实践指南》在现代开发中,.NET与Python的协作需求日益增长,从机器学习模型集成到科学计算,从脚本自动化到数据分析,然而,传统的解决方案(如HTTPAPI或... 目录一、CSnakes vs python.NET:为何选择 CSnakes?二、环境准备:从 Py

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

使用Java读取本地文件并转换为MultipartFile对象的方法

《使用Java读取本地文件并转换为MultipartFile对象的方法》在许多JavaWeb应用中,我们经常会遇到将本地文件上传至服务器或其他系统的需求,在这种场景下,MultipartFile对象非... 目录1. 基本需求2. 自定义 MultipartFile 类3. 实现代码4. 代码解析5. 自定

Go语言使用net/http构建一个RESTful API的示例代码

《Go语言使用net/http构建一个RESTfulAPI的示例代码》Go的标准库net/http提供了构建Web服务所需的强大功能,虽然众多第三方框架(如Gin、Echo)已经封装了很多功能,但... 目录引言一、什么是 RESTful API?二、实战目标:用户信息管理 API三、代码实现1. 用户数据

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结

javaSE类和对象进阶用法举例详解

《javaSE类和对象进阶用法举例详解》JavaSE的面向对象编程是软件开发中的基石,它通过类和对象的概念,实现了代码的模块化、可复用性和灵活性,:本文主要介绍javaSE类和对象进阶用法的相关资... 目录前言一、封装1.访问限定符2.包2.1包的概念2.2导入包2.3自定义包2.4常见的包二、stati