用.NET的面板来显示多个AutoCAD实体的属性

2024-06-10 11:32

本文主要是介绍用.NET的面板来显示多个AutoCAD实体的属性,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文:Using a palette from .NET to display properties of multiple AutoCAD objects

本文仅翻译部分内容

经过短暂的插曲,我们又回到了演示如何用.NET在AutoCAD中实现基本用户界面的系列文章。这是目前为止该系列的文章列表:

  • Using a modal .NET dialog to display AutoCAD object properties
  • Using a modeless .NET dialog to display AutoCAD object properties
  • Using a modeless .NET dialog to display properties of multiple AutoCAD objects

在这篇文章中我们将换掉已经在前几篇系列文章中使用的无模式对话框,用AutoCAD内置的palette类(Autodesk.AutoCAD.Windows.PaletteSet)为例来替换它。

为什么要用Paletteset类呢?因为Paletteset类非常炫酷:它提供了停靠(docking),自动隐藏,支持透明度并且修复了我们在无模式对话框中遇到的恼人的焦点相关的问题。

最重要的是,实现这一切基本上不需要花费任何代价——实现它的工作几乎最小的。我从ObjectARX SDK的DockingPalette的示例中复制了大部分的代码,然后删除了我们项目不需要的部分。

下面是更新后的命令的实现。修改真的非常小,因为palette的实现都隐藏在新的TypeViewerPalette类里了。

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using System;
using CustomDialogs;namespace CustomDialogs
{public class Commands : IExtensionApplication{static TypeViewerPalette tvp;public void Initialize(){tvp = new TypeViewerPalette();DocumentCollection dm =Application.DocumentManager;dm.DocumentCreated +=new DocumentCollectionEventHandler(OnDocumentCreated);foreach (Document doc in dm){doc.Editor.PointMonitor +=new PointMonitorEventHandler(OnMonitorPoint);}}public void Terminate(){try{DocumentCollection dm =Application.DocumentManager;if (dm != null){Editor ed = dm.MdiActiveDocument.Editor;ed.PointMonitor -=new PointMonitorEventHandler(OnMonitorPoint);}}catch (System.Exception){// The editor may no longer// be available on unload}}private void OnDocumentCreated(object sender,DocumentCollectionEventArgs e){e.Document.Editor.PointMonitor +=new PointMonitorEventHandler(OnMonitorPoint);}private void OnMonitorPoint(object sender,PointMonitorEventArgs e){FullSubentityPath[] paths =e.Context.GetPickedEntities();if (paths.Length <= 0){tvp.SetObjectId(ObjectId.Null);return;};ObjectIdCollection idc = new ObjectIdCollection();foreach (FullSubentityPath path in paths){// Just add the first ID in the list from each pathObjectId[] ids = path.GetObjectIds();idc.Add(ids[0]);}tvp.SetObjectIds(idc);}[CommandMethod("vt",CommandFlags.UsePickSet)]public void ViewType(){tvp.Show();}}
}


至于TypeViewerPalette类:我通过从原来的TypeViewerForm类中把SetObjectId[s]()/SetObjectText() 协议迁移过来开始——这是其中最复杂的一部分,涉及通过一个可以从SetObjectText()成员变量暴露我们的面板的内容(我们作为一个用户控件定义并加载)。除了前面说的以外,其它的就只是复制和粘贴了。

这是C #代码:

using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Windows;
using TypeViewer;namespace CustomDialogs
{public class TypeViewerPalette{// We cannot derive from PaletteSet// so we contain itstatic PaletteSet ps;// We need to make the textbox available// via a static memberstatic TypeViewerControl tvc;public TypeViewerPalette(){tvc = new TypeViewerControl();}public void Show(){if (ps == null){ps = new PaletteSet("Type Viewer");ps.Style =PaletteSetStyles.NameEditable |PaletteSetStyles.ShowPropertiesMenu |PaletteSetStyles.ShowAutoHideButton |PaletteSetStyles.ShowCloseButton;ps.MinimumSize =new System.Drawing.Size(300, 300);ps.Add("Type Viewer 1", tvc);}ps.Visible = true;}public void SetObjectText(string text){tvc.typeTextBox.Text = text;}public void SetObjectIds(ObjectIdCollection ids){if (ids.Count < 0){SetObjectText("");}else{Document doc =Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;DocumentLock loc =doc.LockDocument();using (loc){string info ="Number of objects: " +ids.Count.ToString() + "\r\n";Transaction tr =doc.TransactionManager.StartTransaction();using (tr){foreach (ObjectId id in ids){Entity ent =(Entity)tr.GetObject(id, OpenMode.ForRead);Solid3d sol = ent as Solid3d;if (sol != null){Acad3DSolid oSol =(Acad3DSolid)sol.AcadObject;// Put in a try-catch block, as it's possible// for solids to not support this property,// it seems (better safe than sorry)try{string solidType = oSol.SolidType;info +=ent.GetType().ToString() +" (" + solidType + ") : " +ent.ColorIndex.ToString() + "\r\n";}catch (System.Exception){info +=ent.GetType().ToString() +" : " +ent.ColorIndex.ToString() + "\r\n";}}else{info +=ent.GetType().ToString() +" : " +ent.ColorIndex.ToString() + "\r\n";}}tr.Commit();}SetObjectText(info);}}}public void SetObjectId(ObjectId id){if (id == ObjectId.Null){SetObjectText("");}else{Document doc =Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;DocumentLock loc =doc.LockDocument();using (loc){Transaction tr =doc.TransactionManager.StartTransaction();using (tr){DBObject obj =tr.GetObject(id, OpenMode.ForRead);SetObjectText(obj.GetType().ToString());tr.Commit();}}}}}
}
你可以从 这里下载源码

这篇关于用.NET的面板来显示多个AutoCAD实体的属性的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



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

相关文章

python删除xml中的w:ascii属性的步骤

《python删除xml中的w:ascii属性的步骤》使用xml.etree.ElementTree删除WordXML中w:ascii属性,需注册命名空间并定位rFonts元素,通过del操作删除属... 可以使用python的XML.etree.ElementTree模块通过以下步骤删除XML中的w:as

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

SpringSecurity显示用户账号已被锁定的原因及解决方案

《SpringSecurity显示用户账号已被锁定的原因及解决方案》SpringSecurity中用户账号被锁定问题源于UserDetails接口方法返回值错误,解决方案是修正isAccountNon... 目录SpringSecurity显示用户账号已被锁定的解决方案1.问题出现前的工作2.问题出现原因各

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

Python打印对象所有属性和值的方法小结

《Python打印对象所有属性和值的方法小结》在Python开发过程中,调试代码时经常需要查看对象的当前状态,也就是对象的所有属性和对应的值,然而,Python并没有像PHP的print_r那样直接提... 目录python中打印对象所有属性和值的方法实现步骤1. 使用vars()和pprint()2. 使

CSS3中的字体及相关属性详解

《CSS3中的字体及相关属性详解》:本文主要介绍了CSS3中的字体及相关属性,详细内容请阅读本文,希望能对你有所帮助... 字体网页字体的三个来源:用户机器上安装的字体,放心使用。保存在第三方网站上的字体,例如Typekit和Google,可以link标签链接到你的页面上。保存在你自己Web服务器上的字

使用jenv工具管理多个JDK版本的方法步骤

《使用jenv工具管理多个JDK版本的方法步骤》jenv是一个开源的Java环境管理工具,旨在帮助开发者在同一台机器上轻松管理和切换多个Java版本,:本文主要介绍使用jenv工具管理多个JD... 目录一、jenv到底是干啥的?二、jenv的核心功能(一)管理多个Java版本(二)支持插件扩展(三)环境隔

SpringBoot读取ZooKeeper(ZK)属性的方法实现

《SpringBoot读取ZooKeeper(ZK)属性的方法实现》本文主要介绍了SpringBoot读取ZooKeeper(ZK)属性的方法实现,强调使用@ConfigurationProperti... 目录1. 在配置文件中定义 ZK 属性application.propertiesapplicati

Java反射实现多属性去重与分组功能

《Java反射实现多属性去重与分组功能》在Java开发中,​​List是一种非常常用的数据结构,通常我们会遇到这样的问题:如何处理​​List​​​中的相同字段?无论是去重还是分组,合理的操作可以提高... 目录一、开发环境与基础组件准备1.环境配置:2. 代码结构说明:二、基础反射工具:BeanUtils

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.