036集——查询CAD图元属性字段信息:窗体显示(CAD—C#二次开发入门)

ops/2024/11/18 3:33:17/

提取CAD图元所有属性字段,通过窗体显示,效果如下:(curve改为entity)

 代码如下:

   public void 属性查询()       {List<Curve> ents = Z.db.SelectEntities<Curve>();if (ents is null ||ents.Count ==0){Z.ed.WriteMessage("未选择!\n");return;}object obj = ents[0];string str = "";str += "对象全部属性:  >\n";str += "类型:    " + obj.GetType() + "\n";PropertyInfo[] pis = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);foreach (var pi in pis){try { str += pi.Name + " :    " + pi.GetValue(obj, null).ToString() + "\n"; }catch { str += pi.Name + "     " + "Null" + "\n"; }}//MessageBox.Show(str);TextForm f = new TextForm();f.richTextBox1.Text = str;Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(f);}

  public class Class1{private bool ev = false;[CommandMethod("netloadx")]public void Netloadx(){//IL_0017: Unknown result type (might be due to invalid IL or missing references)//IL_001d: Expected O, but got Unknown//IL_0036: Unknown result type (might be due to invalid IL or missing references)//IL_003c: Invalid comparison between Unknown and I4Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;string text = "山水qq443440204";OpenFileDialog val = new OpenFileDialog();((FileDialog)val).Filter = "dll文件(*.dll)|*.dll";((FileDialog)val).Title = "打开dll文件";if ((int)((CommonDialog)val).ShowDialog() != 1){return;}text = ((FileDialog)val).FileName;AssemblyDependent assemblyDependent = new AssemblyDependent(text);bool flag = true;AssemblyDependent.LoadDllMessage[] array = assemblyDependent.Load().ToArray();foreach (AssemblyDependent.LoadDllMessage loadDllMessage in array){if (!loadDllMessage.LoadYes){editor.WriteMessage("\n" + loadDllMessage.Path + "失败!");flag = false;}}if (flag){editor.WriteMessage("\n加载成功!\n");}}[CommandMethod("ww")]public void ww(){var doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;var db = doc.Database;var ed = doc.Editor;var ad = new AssemblyDependent(@"G:\Csharp\李小科CSharp\AcTools\bin\Debug\AcTools.dll");  //写上你dll的路径var msg= ad.Load();bool allyes = true;foreach (var item in msg){if (!item.LoadYes){ed.WriteMessage("\n**" + item.Path +"**重复版本号,无需再次加载!" + System.Environment.NewLine);allyes = false;}}if (allyes){ed.WriteMessage( "\n加载成功!\n");}if (!ev) { System.AppDomain.CurrentDomain.AssemblyResolve += RunTimeCurrentDomain.DefaultAssemblyResolve; ev = true; }}[CommandMethod("sxcx")]public void 属性查询(){List<Entity> ents = SelectEntities<Entity>();if (ents is null || ents.Count == 0){Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("未选择!\n");return;}object obj = ents[0];string str = "";str += "对象全部属性:  >\n";str += "类型:    " + obj.GetType() + "\n";PropertyInfo[] pis = obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);foreach (var pi in pis){try { str += pi.Name + " :    " + pi.GetValue(obj, null).ToString() + "\n"; }catch { str += pi.Name + "     " + "Null" + "\n"; }}str += "\n";//MessageBox.Show(str);TextForm f = new TextForm();f.richTextBox1.Text = str;Autodesk.AutoCAD.ApplicationServices.Application.ShowModalDialog(f);}public  List<T> SelectEntities<T>() where T : Entity{List<T> result = new List<T>();Editor editor = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;var pso = new PromptSelectionOptions();pso.MessageForAdding = "\n请选择:";PromptSelectionResult psr = editor.GetSelection(pso);if (psr.Status == PromptStatus.OK){ObjectId[] objectids = psr.Value.GetObjectIds();Database database = HostApplicationServices.WorkingDatabase;using (Transaction tran = database.TransactionManager.StartTransaction()){foreach (var item in objectids){Entity entity = item.GetObject(OpenMode.ForRead) as Entity;if (entity is T){result.Add(entity as T);}}}}return result;}}


http://www.ppmy.cn/ops/134209.html

相关文章

如何绕过Captcha并使用OCR技术抓取数据

背景/引言 在现代的网页数据抓取中&#xff0c;Captcha&#xff08;全自动区分计算机和人类的图灵测试&#xff09;作为一种防止爬虫和恶意访问的有效措施&#xff0c;广泛应用于各种网站。Captcha的主要目的是区分用户是人类还是程序&#xff0c;因此对于爬虫技术来说&#x…

入侵检测算法平台部署LiteAIServer视频智能分析平台行人入侵检测算法:科技守护安全的新篇章

在现代化城市快速发展的背景下&#xff0c;安全防范已成为城市管理与社会生活中不可或缺的一环。随着人工智能、大数据、物联网等技术的飞速发展&#xff0c;智能化安防系统正逐步改变着传统的安全防护模式&#xff0c;特别是在行人入侵检测领域&#xff0c;视频智能分析平台Li…

大语言模型在序列推荐中的应用

一、简介 序列推荐技术通过分析用户的过往交互历史&#xff0c;能够有效挖掘出用户可能感兴趣的项目&#xff0c;对于提升各类应用的服务质量具有重要作用。近期&#xff0c;大语言模型&#xff08;LLMs&#xff09;的发展在应对复杂的推荐问题上展现出了显著的优势。不过&…

多智能体系统实现无直接通信协同

摘要&#xff1a;本文提出创新多智能体强化学习框架&#xff0c;通过对比学习构建全局共识&#xff0c;使智能体在没有直接通信的情况下实现协作行为。 近期&#xff0c;北京航空航天大学研究团队著作成果"Hierarchical Consensus-Based Multi-Agent Reinforcement Learn…

深度学习中的Pixel Shuffle和Pixel Unshuffle:图像超分辨率的秘密武器

在深度学习的计算机视觉任务中&#xff0c;提升图像分辨率和压缩特征图是重要需求。Pixel Shuffle和Pixel Unshuffle是在超分辨率、图像生成等任务中常用的操作&#xff0c;能够通过转换空间维度和通道维度来优化图像特征表示。本篇文章将深入介绍这两种操作的原理&#xff0c;…

Win10/11 安装使用 Neo4j Community Edition

如果你下载的是 Neo4j Community Edition 的压缩包&#xff0c;意味着你需要手动解压并配置 Neo4j。以下是详细的使用步骤&#xff1a; 0. 下载压缩包 访问Neo4j官网&#xff0c;找到 Community Edition 版本并选择 4.x 或者 5.x 下载&#xff1a;https://neo4j.com/deployme…

HelloMeme 上手即用教程

HelloMeme是一个集成空间编织注意力的扩散模型&#xff0c;用于生成高保真图像和视频。它提供了一个代码库&#xff0c;包含实验代码和预训练模型&#xff0c;支持PyTorch和FFmpeg。用户可以通过简单的命令行操作来生成图像和视频。 本文将详细介绍&#xff0c;如何在GPU算力租…

MFC图形函数学习08——绘图函数的重载介绍

在《MFC图形函数学习06——画椭圆弧线函数》中介绍了CPoint类、POINT结构体&#xff1b;在《MFC图形函数学习07——画扇形函数》中介绍了CRect类、RECT结构体。在介绍完后&#xff0c;没有介绍它们怎样使用。实际上&#xff0c;这些类和结构体对象或指针也是我们学习过的绘图函…