我明明是以写的模式打开的,为什么会出现这种错误呢?
刚接触C# 好多东西还在摸索,希望路过的高手帮下忙。
我先贴出部分代码:
- //这是另外一个类的,这两行应该是没问题的。
- mDoc = Application. DocumentManager. MdiActiveDocument;
- mDb = mDoc. Database;
- public class MySymbolTableRecord
- {
- protected ObjectId AddEntity (BlockTableRecord btRecord, Entity ent)
- {
- ObjectId ObjId;
- using (Transaction tran = mDb. TransactionManager. StartTransaction( ))
- {
- //调试的时候每次都是运行到这位置就出错了
- //内部错误: !dbobji.cpp@7227:eNotOpenForWrite
- ObjId = btRecord. AppendEntity(ent);
- tran. AddNewlyCreatedDBObject(ent, true);
- tran. Commit( );
- }
- return ObjId;
- }
- protected DBObject GetDBObject (ObjectId id, OpenMode mode)
- {
- DBObject dbObj;
- using (Transaction tran = mDb. TransactionManager. StartTransaction( ))
- {
- dbObj = tran. GetObject(id, mode);
- }
- return dbObj;
- }
- }
- public class Drawing : MySymbolTableRecord
- {
- private BlockTableRecord mBlkTabRec;
- private Calculation mCalc;
- public Drawing ( )//构造函数
- {
- mBlkTabRec = GetDBObject(mDb. CurrentSpaceId, OpenMode. ForWrite) as BlockTableRecord;
- mCalc = new Calculation( );
- }
- public ObjectId AddLine (Point2d ptStart, Point2d ptEnd)//画直线
- {
- Line line = new Line(mCalc. P2ToP3(ptStart), mCalc. P2ToP3(ptEnd));
- return AddEntity(mBlkTabRec, line);
- }
- }
|