c# 的CAD二次开发高手请进

lcawen 2012-05-04 01:36:11
请教各位大神,错误信息为:
System.AccessViolationException: 尝试读取或写入受保护的内存。这通常指示其他内存已损坏。
在 Autodesk.AutoCAD.Runtime.RXObject.DeleteUnmanagedObject()
在 Autodesk.AutoCAD.Runtime.DisposableWrapper.!DisposableWrapper()
在 Autodesk.AutoCAD.Runtime.DisposableWrapper.Dispose(Boolean )
在 Autodesk.AutoCAD.Runtime.DisposableWrapper.Finalize()

经调试,发现具体出错代码部分如下
using (Transaction ts = pdb.TransactionManager.StartTransaction())//pdb是当前操作的数据库
{
ObjectId lydiid = pdb.LayoutDictionaryId;
//ObjectId objid1 = pdb.GetObjectId(false, lydiid.Handle, 0);
DBDictionary lydi = (DBDictionary)ts.GetObject(lydiid, OpenMode.ForRead);//获取数据字典
//DBDictionary lydi = (DBDictionary)ts.GetObject(objid1, OpenMode.ForRead);//获取数据字典
DbDictionaryEnumerator di = lydi.GetEnumerator();//字典计数器
while (di.MoveNext())//由于在图纸中有多个布局,这里遍历布局
{
ObjectId lyid =di.Value ;
//Layout lyt = (Layout)ts.GetObject (lyid ,OpenMode.ForWrite);
Layout lyt = (Layout)ts.GetObject(lyid, OpenMode.ForRead);//获取布局
BlockTable lybt=(BlockTable)ts.GetObject(pdb.BlockTableId,OpenMode.ForRead);
//BlockTableRecord lybtr = (BlockTableRecord)ts.GetObject(lyt.BlockTableRecordId, OpenMode.ForWrite);//获取块表
BlockTableRecord lybtr = (BlockTableRecord)ts.GetObject(lyt.BlockTableRecordId, OpenMode.ForRead);//获取块表记录
BlockTableRecordEnumerator lybtret = lybtr.GetEnumerator();
while (lybtret.MoveNext())
{
ObjectId objid = lybtret.Current;
Entity ent = ts.GetObject(objid, OpenMode.ForWrite) as Entity;
if (ent.GetType() == typeof(Table))
{
Table tab = (Table)ent;
tab.InsertRows(1, 8,1);
tab.Cells[1, 0].TextString = "1";
tab.Cells[1, 0].TextHeight = 2.5;
for (int j = 1; j<=ljcanshu .Count ;j++)
{
tab.Cells[1, j].TextString = ljcanshu [j-1];
tab.Cells[1, j].TextHeight = 2.5;
}
tab.Dispose();
}
else
{
if (ent.GetType() == typeof(MText))
{
MText mt = (MText)ent;
if (mt.Text.Trim() == "xh")
{
mt.Contents = zwlqd;
mt.Height = 4;
mt.TextHeight = 2;
}
else
{
if (mt.Text.Trim() == "wlbm")
{
mt.Contents = ljcanshu[((ljcanshu.Count) - 1)];
mt.Height = 4;
mt.TextHeight = 2;
}
}
mt.Dispose();
}
}
}
lybtr.Dispose();
lyt.Dispose();
}
lydi.Dispose();
ts.Commit();
ts.Dispose();
//lydi.Dispose();
}
...全文
490 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hustermse2012 2012-12-11
  • 打赏
  • 举报
回复
这个问题貌似见过!
lcawen 2012-12-06
  • 打赏
  • 举报
回复
没有大神可以解决吗?泱泱中华!!!!!自己顶!

1,451

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计/Flash/Silverlight 开发 图象工具使用
社区管理员
  • 图象工具使用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧