036集——查询CAD图元属性字段信息:窗体显示(CAD—C#二次开发入门)
提取CAD图元所有属性字段,通过窗体显示,效果如下:
代码如下:
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);
}