AutoCAD Plant3d 数据读取(类似Revit的Lookup) (一)
背景
在Plant3d的开发过程中,发现缺少一个类似revit的信息查看工具,同时做一些数据验证
思路
- 启动拾取
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptEntityResult res = ed.GetEntity("\n选择一个实体: ");
- 读取信息
using (Transaction transaction = dwg.TransactionManager.StartTransaction())
{
DBObject ent = transaction.GetObject(res.ObjectId, OpenMode.ForRead);
if (ent == null)
{
return string.Empty;
}
if (res.ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Pipe))))
{
return Read(ent as Pipe);
}
else if (res.ObjectId.ObjectClass.IsDerivedFrom(RXObject.GetClass(typeof(Equipment))))
{
return Read(ent as Equipment);
}
return "未识别对象";
}
每多学一点知识,就少写一行代码