当前位置: 首页 > 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.lryc.cn/news/485353.html

相关文章:

  • Swift从0开始学习 函数和闭包 day2
  • 内网、公网(外网)划分
  • 【linux】centos7 换阿里云源
  • 用OMS进行 OceanBase 租户间数据迁移的测评
  • 【因果分析方法】MATLAB计算Liang-Kleeman信息流
  • 【Java基础知识系列】之Java类的初始化顺序
  • Swift 宏(Macro)入门趣谈(二)
  • vue elementui el-dropdown-item设置@click无效的解决方案
  • 如何用re从第1排第2个位置中找到两个数字返回(0,1)
  • vue中的keep-alive是什么,有哪些使用场景,使用了什么原理,缓存后如何更新数据
  • LeetCode105.从前序与中序遍历构造二叉树
  • LeetCode654.最大二叉树
  • C# 字段和属性
  • 【leetcode】N皇后 回溯法c++
  • Ubuntu 系统端口查询与管理详细分析
  • Unity中使用StartCoroutine协程和Lerp方法,使GameObject缓慢移动
  • C++根据特定字符截取字符串
  • 【How AI Works】读书笔记3 出发吧! AI纵览 第二部分
  • No Module named pytorchvideo.losses问题解决
  • Mac终端字体高亮、提示插件
  • Flowable 构建后端服务(后端以及数据库搭建) Flowable Modeler 设计器搭建(前端)
  • [Java]微服务拆分
  • JavaScript逆向爬虫教程-------基础篇之JavaScript混淆原理
  • qt移植到讯为rk3568,包含一些错误总结
  • 使用阿里云快速搭建 DataLight 平台
  • ubuntu设置自启动
  • Paddle分布式训练报NCCL错
  • PD3.1快充对我们到底有没有必要?
  • Android OpenGL ES详解——立方体贴图
  • Bugku CTF_Web——字符?正则?