代码如下,我的思路是通过CreateBox()函数返回Solid3d列表 ,然后用DrawSolids进行一次性绘制,但是DrawSolids运行到
btr.AppendEntity(solid)时发出如题异常,字面意思可以理解为实体已存在于数据库中,但是之前CreateBox函数并没有进行相关操作,难道创建的任何实体不需要进行事务操作就进入数据库了?求解答
-
- private static Solid3d CreateBox(PipeInfo info) {
- Solid3d box = new Solid3d();
- box.CreateBox(info.lenght, info.width, info.pipeLine.Length);
- box.Layer = info.layer;
- return box;
- }
-
- private static void DrawSolids(List<Solid3d> solids) {
- Database db = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Database;
- using (Transaction tran =db.TransactionManager.StartTransaction()) {
- BlockTable bt = tran.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
- BlockTableRecord btr = tran.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
- foreach (Solid3d solid in solids){
- btr.AppendEntity(solid);//-----------此句出现eAlreadyInDb异常
- tran.AddNewlyCreatedDBObject(solid, true);
- }
- tran.Commit();
- }
- }
|