|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk..Runtime;
using Autodesk.AutoCAD.EditorInput;
using System.Windows.Forms;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.ApplicationServices;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Document = Autodesk.AutoCAD.ApplicationServices.Document;
[assembly: CommandClass(typeof(Cheng5276_CAD.Class1))]
namespace Cheng5276_CAD
{
public class Class1
{
public void doc_ImpliedSelectionChanged(object sender, EventArgs e)
{
Autodesk.AutoCAD.EditorInput.Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
PromptSelectionResult pkf = ed.SelectImplied();
if (pkf.Status != PromptStatus.OK)
{ //取消选择状态
return;
}
else
{ //对象选择状态
ObjectId[] objIds = pkf.Value.GetObjectIds();
Document doc = Application.DocumentManager.MdiActiveDocument;
Transaction trans = doc.TransactionManager.StartTransaction();
foreach (ObjectId objId in objIds)
{
try
{
DBObject obj = trans.GetObject(objId, OpenMode.ForRead);
ResultBuffer rb = obj.XData;
if (rb != null)
{
foreach (TypedValue tv in rb)
{
if (tv.TypeCode == 1000)
{
string zg_t = tv.Value.ToString();
break;
}
}
rb.Dispose();
}
trans.Commit();
obj.Dispose();
}
catch { }
}
doc.Dispose();
trans.Dispose();
}
}
[CommandMethod("FF")]
public void Initialize()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
acDoc.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged); //定义对象选择事件
}
}
}
NET加载后,执行FF启用事件。
但是只要选择对象后,随便干什么,都会引起CAD崩溃,实在不明原因,请老大们指点
|
|