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

相关文章

JAVA读取MongoDB中的二进制图片并显示在页面上

1:Jsp页面: <td><img src="${ctx}/mongoImg/show"></td> 2:xml配置: <?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001

据阿谱尔APO Research调研显示,2023年全球髓内钉市场销售额约为4.7亿美元

根据阿谱尔 (APO Research)的统计及预测,2023年全球髓内钉市场销售额约为4.7亿美元,预计在2024-2030年预测期内将以超过3.82%的CAGR(年复合增长率)增长。 髓内钉市场是指涉及髓内钉制造、分销和销售的行业。髓内钉是一种用于整形外科手术的医疗器械,用于稳定长骨骨折,特别是股骨、胫骨和肱骨。髓内钉通常由不銹钢或钛等材料制成,并插入骨的髓管中,以在愈合过程中提供结构支

vue+elementUI下拉框联动显示

<el-row><el-col :span="12"><el-form-item label="主账号:" prop="partyAccountId" :rules="[ { required: true, message: '主账号不能为空'}]"><el-select v-model="detailForm.partyAccountId" filterable placeholder="

Windows中,.net framework 3.5安装

安装.net framework,目前已知2种方法,如下: 一、在MSDN下载对应的安装包,安装,这种可能无法安装成功,概率很大,不成功使用第二种方法,基本上没问题。 二、win8/8.1/10 下安装 .net framework 3.5.1: 1. 打开 win8/8.1/10 安装盘(这里指系统安装镜像文件),提取 sources\sxs 文件夹到 X:\sources\sxs (X代

青龙面板之Ninja无法安装无法拉库问题解决

因为之前的Ninja库已经不能用了,甚至新找到的库也不能用了,好尴尬,这里使用线下版本进行安装。 ninja安装新方法,其是方法还是原来的,只不过Ninja的库原作者删了,没法直接git了,但是我找到了源码包,我们可以直接通过宝塔面板拖进去。 源码包地址: https://download.csdn.net/download/u012134073/24813485 备用地址: 链接: h

青龙面板2.9之Cdle傻妞机器人编译教程

看到有的朋友对傻妞机器人感兴趣,这里写一下傻妞机器人的编译教程。 第一步,这里以linux amd64为例,去官网下载安装go语言安装包: 第二步,输入下方指令 cd /usr/local && wget https://golang.google.cn/dl/go1.16.7.linux-amd64.tar.gz -O go1.16.7.linux-amd64.tar.gz

【青龙面板辅助】JD商品自动给好评获取京豆脚本

1.打开链接 开下面的链接进入待评价商品页面 https://club.jd.com/myJdcomments/myJdcomments.action?sort=0 2.登陆后执行脚本 登陆后,按F12键,选择console,复制粘贴以下代码,先运行脚本1,再运行脚本2 脚本1代码 可以自行修改评价内容。 var content = '材质很好,质量也不错,到货也很快物流满分,包装快递满

青龙面板部署通用教程,含服务器、路由器、X86等部署方法

1. 拉取镜像/更新镜像 docker pull whyour/qinglong:latest 2. 删除镜像 docker rmi whyour/qinglong:latest 3. 启动容器 普通服务器 docker run -dit \-v $PWD/ql/config:/ql/config \-v $PWD/ql/log:/ql/log \-v $PWD/ql/db:

宝塔面板部署青龙面板教程【简单易上手】

首先,你得有一台部署了宝塔面板的服务器(自己用本地电脑也可以)。 宝塔面板部署自行百度一下,很简单,这里就不走流程了,官网版本就可以,无需开心版。 首先,打开宝塔面板的软件商店,找到下图这个软件(Docker管理器)安装,青龙面板还是安装在docker里,这里依赖宝塔面板安装和管理docker。 安装完成后,进入SSH终端管理,输入代码安装青龙面板。ssh可以直接宝塔里操作,也可以安装ssh连接

如何实现一台机器上运行多个MySQL实例?

在一台机器上一个MySQL服务器运行多个MySQL实例有什么好处?这里我先入为主给大家介绍这样做至少存在两个好处(看完这篇文章后理解会更透彻): (1)减轻服务器链接负担 (2)为不同的用户提供不同的mysqld服务器的访问权限以方便这些用户进行自我管理。   下面我介绍具体的实现过程: 一、准备工作     台式机一台、Windows系统、MySQL服务器(我安装的版本是MySQL