//SrcPath 源文件
String shortName = System.IO.Path.GetFileName(SrcPath);
Database srcdb = new Database(false, true);
srcdb.ReadDwgFile(SrcPath, FileShare.Read, false, "");
srcdb.CloseInput(true);
//Document doc 要插入的文档,
// Database srcdb 数据源
public bool InsertAllBlock(Document doc, Database srcdb)
{
using (DocumentLock doclock = doc.LockDocument())
{
using (Transaction Trans = doc.TransactionManager.StartTransaction()) // 开始事务
{
BlockTable acBlkTbl = Trans.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
ObjectId tmpid = doc.Database.Insert(System.Guid.NewGuid().ToString(), srcdb, true);
BlockTableRecord btr = tmpid.GetObject(OpenMode.ForWrite) as BlockTableRecord;
btr.Erase();
Trans.Commit();
return true;
}
}
}