- 积分
- 949
- 明经币
- 个
- 注册时间
- 2014-12-1
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
我想实现的功能是点击插入块时,能插入4个相同的块。把For循环去掉,单独插入一个块是没有错误的,能正常插入块。但加上就出错了,提示“内部错误:!dbobji.cpp@6266:eNotOpenForWrite”请给位大侠给小妹看看呗,十分感谢!!!
public void InsIcons()
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
ObjectId blkId;
Point3d point3d = new Point3d();
BlockReference br = null;
try
{
ed.WriteMessage(fileName);
using (Transaction trans = db.TransactionManager.StartTransaction())
{
blkId = CommonFunction.m_ImportBlock(filePath, fileName, blockName, true);
if (blkId != ObjectId.Null)
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord modelSpace = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
for (int i = 0; i < 4; i++)
{
if (i == 0)
point3d = CommonFunction.GetPoint(ed, "请选择一个插入点");
else
point3d = new Point3d(point3d.X, point3d.Y + 7 * scale3d, 0);
br = new BlockReference(point3d, blkId);
br.ScaleFactors = new Scale3d(scale3d);
modelSpace.AppendEntity(br);
trans.AddNewlyCreatedDBObject(br, true);
trans.Commit();
}
}
else
{
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog("您要插入的块不存在!");
return;
}
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.StackTrace + "\n" + ex.Message + "\n" + ex.TargetSite);
return;
}
}
|
|