当前位置: 首页 > news >正文

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

提取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.mrgr.cn/news/76399.html

相关文章:

  • Spark RDD sortBy算子什么情况会触发shuffle
  • LC12:双指针
  • 【苍穹外卖】学习日志-day1
  • 实用且免费的 IP 地域查询 API 接口推荐
  • css-50 Projects in 50 Days(4)
  • gitlab与jenkins
  • 蓝桥杯c++算法学习【3】之思维与贪心(重复字符串、翻硬币、乘积最大、皮亚诺曲线距离【难】:::非常典型的必刷例题!!!)
  • 两行命令搭建深度学习环境(Docker/torch2.5.1+cu118/命令行美化+插件),含完整的 Docker 安装步骤
  • SpringMVC跨线程获取requests请求对象(子线程共享servletRequestAttributes)和跨线程获取token信息
  • 2:Vue.js 父子组件通信:让你的组件“说话”
  • 从0开始学习机器学习--Day26--聚类算法
  • uniapp微信登录的流程
  • 数据结构(基本概念及顺序表)
  • [JAVA]有关MyBatis环境配置介绍
  • docker busybox作为initContainers
  • 系统架构设计师:软件架构的演化和维护
  • 解决laravel框架生成的pdf过大的问题
  • Linux应用层学习——Day2(文件IO)
  • centos7安装Chrome使用selenium-wire
  • STM32单片机CAN总线汽车线路通断检测
  • uniapp 实现 ble蓝牙同时连接多台蓝牙设备,支持app、苹果(ios)和安卓手机,以及ios连接蓝牙后的一些坑
  • 【linux】进程等待与进程替换
  • Pytest-Bdd-Playwright 系列教程(9):datatable 参数的使用
  • vue3:computed
  • 我谈二值形态学基本运算——腐蚀、膨胀、开运算、闭运算
  • web安全漏洞之ssrf入门