国产精品黄页免费高清在线观看,中文字幕一区二区三区久久网站 ,亚洲老熟女 @ tubeum tv,在教室伦流澡到高潮hgl动漫,中文字幕丝袜精品久久

反復(fù)插入塊時(shí)閃退

我有一個(gè)開(kāi)發(fā)任務(wù)。程序的邏輯是先調(diào)用函數(shù)createBlock,將幾個(gè)圖形創(chuàng)建成塊,再反復(fù)調(diào)用creareBlockRef插入塊,當(dāng)插入幾個(gè)塊時(shí)無(wú)異常,但是插入較多塊時(shí)就會(huì)閃退

public override void createBlock(string sfn, string blkname, double[] bp)
{

try
{
// 加載源文件到臨時(shí)數(shù)據(jù)庫(kù)

using (var ttrans = db.TransactionManager.StartTransaction())
{
BlockTable tbt = ttrans.GetObject(db.BlockTableId, OpenMode.ForWrite) as BlockTable;// 獲取目標(biāo)塊表
if (tbt.Has(blkname)) throw new sys.Exception("塊名稱已存在:" + blkname);// 檢查塊名是否存在,若存在則可以選擇處理或報(bào)錯(cuò)

var newBlock = new BlockTableRecord();// 創(chuàng)建新塊定義
newBlock.Name = blkname;
newBlock.Origin = toP3d(bp);

using (Database sdb = new Database(false, true))
{
if (!File.Exists(sfn)) throw new sys.Exception("文件不存在:\n" + sfn);
sdb.ReadDwgFile(sfn, FileOpenMode.OpenForReadAndAllShare, true, null);
sdb.CloseInput(true);

using (var strans = sdb.TransactionManager.StartTransaction())
{

// 復(fù)制源模型空間中的實(shí)體到新塊
var sbt = (BlockTable)strans.GetObject(sdb.BlockTableId, OpenMode.ForRead);
var sbtr = (BlockTableRecord)strans.GetObject(sbt[BlockTableRecord.ModelSpace], OpenMode.ForRead);

var linearcs = new List();
foreach (ObjectId entityId in sbtr)
{
Entity entity = strans.GetObject(entityId, OpenMode.ForRead) as Entity;
if (entity != null)
{
// 深拷貝實(shí)體到當(dāng)前數(shù)據(jù)庫(kù)
Entity clonedEntity = entity.Clone() as Entity;
clonedEntity.SetDatabaseDefaults(db);

if (!(clonedEntity is Line || clonedEntity is Arc) ||
clonedEntity.Color.ColorIndex != 6/*洋紅*/)
{
newBlock.AppendEntity(clonedEntity);
}
else
{
linearcs.Add(clonedEntity);
}
}
}

linkLineArcCls.linkLineArc(linearcs, newBlock);

foreach (var tent in linearcs)
{
newBlock.AppendEntity(tent);
}

strans.Commit();
}
}//std
// 將新塊添加到目標(biāo)塊表并獲取其ID
tbt.Add(newBlock);
ttrans.AddNewlyCreatedDBObject(newBlock, true);//在塊中插入對(duì)象時(shí),不需要此函數(shù),創(chuàng)建塊或在模型空間插入對(duì)象時(shí)需要此函數(shù),刪除實(shí)體前,實(shí)體需要open模式

ttrans.Commit();
}//trans
}
catch (sys.Exception ex)
{
throw new sys.Exception("創(chuàng)建塊失敗:" + ex.ToString());
}
}//s

public override void creareBlockRef(blockrefInfo refinfo)
{
using (var trans = db.TransactionManager.StartTransaction())
{
try
{
var bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
var btr = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);

var blkname = refinfo.blkname;
if (!bt.Has(blkname)) throw new sys.Exception("塊名稱不存在:" + blkname);
var blkid = bt[blkname];

var bref = new BlockReference(toP3d(refinfo.insertP), blkid);
bref.SetDatabaseDefaults();

if (refinfo.needRotate)
{
bref.TransformBy(Matrix3d.Rotation(refinfo.RotateAng, new Vector3d(0, 0, 1), toP3d(refinfo.RotateP)));
}

btr.AppendEntity(bref);
trans.AddNewlyCreatedDBObject(bref, true);

trans.Commit();

}
catch (System.Exception ex)
{
trans.Abort();
throw ex;
}
}
}
已邀請(qǐng):

浩辰軟件的糕糕

贊同來(lái)自:

你好,請(qǐng)私信我您的聯(lián)系方式,我聯(lián)系您溝通處理。

該問(wèn)題目前已經(jīng)被鎖定, 無(wú)法添加新回復(fù)