如何循环插入同一个块
我想实现的功能是点击插入块时,能插入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, 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;
}
}
Trans.commit()放循环外 循环里应该放一个QueueForGraphicsFlush 楼主你好,小弟是新人。想请教个问题:
blkId = CommonFunction.m_ImportBlock(filePath, fileName, blockName, true);
这段代码,是读取你的符号的。小弟完全不知道怎么实现的,求楼主教下~ 给下读取的源码最好拉~ .net还没接触过 把块先插入在内存中,完成后提交事务即可,即按飞弧大哥的提示修改即可 插入了要及时显示才好,仅在database循环时不直观
页:
[1]