首先读取一个dwg文件中的实体到List<Entity>集合,再将其添加到当前模型空间,但是提示eAlreadyInDb,求教各位大神- Database db = HostApplicationServices.WorkingDatabase;
- List<Entity> entities = ReadIn("D://sourcefiles//zz2.dwg");
- ObjectId entityId = ObjectId.Null;
- //插入对象
- using (Transaction trans = db.TransactionManager.StartTransaction())
- {
- BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
- BlockTableRecord modelSpace = (BlockTableRecord)trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
-
- foreach(Entity entity in entities)
- {
- entityId = modelSpace.AppendEntity(entity);// ------ ----eAlreadyInDb异常
- trans.AddNewlyCreatedDBObject(entity, true);
- }
- trans.Commit();
- }
|