对“才鸟”——动态显示扩展数据的改写

才鸟再论坛上发布的动态显示扩展数据的程序,有些人反应不能调试过去,并且必须要加载DNA,经常报错,今天有时间对其进行了改写,测试运行正常。

代码
using System;

using System.Text;

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

//using DNA;



public class Class1

{

Editor ed
= Application.DocumentManager.MdiActiveDocument.Editor;

Database db
= HostApplicationServices.WorkingDatabase;

string xdatas;

[CommandMethod(
"DisplayText")]

public void DisplayText()

{

ed.Rollover
+= new RolloverEventHandler(ed_Rollover);

ed.PointFilter
+= new PointFilterEventHandler(ed_PointFilter);

}



void ed_PointFilter(object sender, PointFilterEventArgs e)

{

e.Result.ToolTipText
= xdatas;

}



void ed_Rollover(object sender, RolloverEventArgs e)

{

xdatas
= null;

using (Transaction trans = db.TransactionManager.StartTransaction())

{

ObjectId[] ids
= e.Highlighted.GetObjectIds();

if (ids.GetLength(0) > 0)

{

DBObject ob
=(DBObject) trans.GetObject(ids[0], OpenMode.ForRead);

ResultBuffer xDataOut
= ob.XData;

if (xDataOut == null)

{

return;

}

foreach (TypedValue xdata in xDataOut)

{

xdatas
+= string.Format("\nTypeCode={0},Value={1}", xdata.TypeCode, xdata.Value);

}

}

}

}

}

 


posted @ 2010-11-28 21:38  hunklee  阅读(214)  评论(0编辑  收藏  举报