- /// <summary>
- /// 从源数据库复制块到指定的数据库.
- /// </summary>
- /// <param name="sourceDb"></param>
- /// <param name="db"></param>
- /// <param name="blockName"></param>
- /// <param name="bReplace"></param>
- /// <returns></returns>
- public static ObjectId importBlock(Database sourceDb, Database db, string blockName, bool bReplace,DuplicateRecordCloning Cloing = DuplicateRecordCloning.Replace)
- {
- //返回Id
- ObjectId destId = ObjectId.Null;
- //对照关系
- IdMapping idmap;
- using (Transaction sourceTr = sourceDb.TransactionManager.StartTransaction())
- {
- //块表
- BlockTable sourceBt = sourceTr.GetObject(sourceDb.BlockTableId, OpenMode.ForRead) as BlockTable;
- if (sourceBt.Has(blockName))
- {
- ObjectId sourceId = sourceBt[blockName];
- idmap = new IdMapping();
- sourceDb.WblockCloneObjects(new ObjectIdCollection(new[] { sourceId }), db.BlockTableId, idmap, Cloing, false);
- destId = idmap[sourceId].Value;
- idmap.Dispose();
- }
- //销毁对象
- sourceBt.Dispose();
- sourceTr.Commit();
- }
- //返回
- return destId;
- }
|