-
- public static ObjectId ToSpace(this Entity ent, Database db = null, string space = null)
- {
- db = db ?? Application.DocumentManager.MdiActiveDocument.Database;
- var id = ObjectId.Null;
- using (var trans = db.TransactionManager.StartTransaction())
- {
- var blkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- var mdlSpc = trans.GetObject(blkTbl[space ?? BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- id = mdlSpc.AppendEntity(ent);
-
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- return id;
- }
- ///
- /// 将实体集合添加到特定空间。
- ///
- ///
- ///
- ///
- ///
- public static ObjectIdCollection ToSpace(this IEnumerable ents,
- Database db = null, string space = null)
- {
- db = db ?? Application.DocumentManager.MdiActiveDocument.Database;
- var ids = new ObjectIdCollection();
- using (var trans = db.TransactionManager.StartTransaction())
- {
- var blkTbl = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- var mdlSpc = trans.GetObject(blkTbl[space ?? BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
- foreach (var ent in ents)
- {
- ids.Add(mdlSpc.AppendEntity(ent));
- trans.AddNewlyCreatedDBObject(ent, true);
- }
- trans.Commit();
- }
- return ids;
- }
数据库扩展类
|