请教老大们关于取得对象扩展数据引起的CAD崩溃
本帖最后由 cheng5276 于 2014-9-12 18:05 编辑using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.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;
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 objIdin 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();
}
}
public void Initialize()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
acDoc.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged); //定义对象选择事件
}
}
}
NET加载后,执行FF启用事件。
但是只要选择对象后,随便干什么,都会引起CAD崩溃,实在不明原因,请老大们指点
文档相关的操作先加锁试试 另外你获取实体的代码呢 如果事务外调用实体会崩溃 因为实体已释放 老大,不好意思,能请您说的更详细些么?谢谢了 把所有的Dispose()都去掉 事务完成后会自动调用的 爱死您了,我的版主大人
页:
[1]