開始往cad資料庫中添加實體了。
一、添加實體到模型空間【圖紙空間類似】
// 加入實體到模型空間
public static ObjectId Append(Entity ent, Database db)
{
ObjectId id;
using(Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForWrite);
BlockTableRecord modeSpce = (BlockTableRecord)tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
id = modeSpce.AppendEntity(ent);
tr.AddNewlyCreatedDBObject(ent, true);
tr.Commit();
}
return id;
}
// 為了避免重複打開資料庫,這裡就單獨列出數組形式重載
public static ObjectIdCollection Append(DBObjectCollection ents, Database db)
{
ObjectIdCollection ids = new ObjectIdCollection();
using (Transaction tr = db.TransactionManager.StartTra