提取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 I4
            Editor 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;
        }
    }


















