用.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函数返回多个值的多种方法小结

《Python函数返回多个值的多种方法小结》在Python中,函数通常用于封装一段代码,使其可以重复调用,有时,我们希望一个函数能够返回多个值,Python提供了几种不同的方法来实现这一点,需要的朋友... 目录一、使用元组(Tuple):二、使用列表(list)三、使用字典(Dictionary)四、 使

MySQL 事务的概念及ACID属性和使用详解

《MySQL事务的概念及ACID属性和使用详解》MySQL通过多线程实现存储工作,因此在并发访问场景中,事务确保了数据操作的一致性和可靠性,下面通过本文给大家介绍MySQL事务的概念及ACID属性和... 目录一、什么是事务二、事务的属性及使用2.1 事务的 ACID 属性2.2 为什么存在事务2.3 事务

idea中project的显示问题及解决

《idea中project的显示问题及解决》:本文主要介绍idea中project的显示问题及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录idea中project的显示问题清除配置重China编程新生成配置总结idea中project的显示问题新建空的pr

Spring Cache注解@Cacheable的九个属性详解

《SpringCache注解@Cacheable的九个属性详解》在@Cacheable注解的使用中,共有9个属性供我们来使用,这9个属性分别是:value、cacheNames、key、key... 目录1.value/cacheNames 属性2.key属性3.keyGeneratjavascriptor

Spring Boot 事务详解(事务传播行为、事务属性)

《SpringBoot事务详解(事务传播行为、事务属性)》SpringBoot提供了强大的事务管理功能,通过@Transactional注解可以方便地配置事务的传播行为和属性,本文将详细介绍Spr... 目录Spring Boot 事务详解引言声明式事务管理示例编程式事务管理示例事务传播行为1. REQUI

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

电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案

《电脑显示mfc100u.dll丢失怎么办?系统报错mfc90u.dll丢失5种修复方案》最近有不少兄弟反映,电脑突然弹出“mfc100u.dll已加载,但找不到入口点”的错误提示,导致一些程序无法正... 在计算机使用过程中,我们经常会遇到一些错误提示,其中最常见的就是“找不到指定的模块”或“缺少某个DL

Java中Switch Case多个条件处理方法举例

《Java中SwitchCase多个条件处理方法举例》Java中switch语句用于根据变量值执行不同代码块,适用于多个条件的处理,:本文主要介绍Java中SwitchCase多个条件处理的相... 目录前言基本语法处理多个条件示例1:合并相同代码的多个case示例2:通过字符串合并多个case进阶用法使用

Spring Security基于数据库的ABAC属性权限模型实战开发教程

《SpringSecurity基于数据库的ABAC属性权限模型实战开发教程》:本文主要介绍SpringSecurity基于数据库的ABAC属性权限模型实战开发教程,本文给大家介绍的非常详细,对大... 目录1. 前言2. 权限决策依据RBACABAC综合对比3. 数据库表结构说明4. 实战开始5. MyBA