本帖最后由 Real_King 于 2015-6-2 11:43 编辑
雪山飞狐_lzh 发表于 2015-6-2 10:31
这个没办法 必须是文档才有的
飞狐老师,我又试过新建一个dwg,然后获取其database和document进行编辑,
参考了.NET人员开发手册 锁定和解锁文档- [CommandMethod("LockDoc", CommandFlags.Session)]
- public static void LockDoc()
- {
- // 创建新图形 Create a new drawing
- DocumentCollection acDocMgr = Application.DocumentManager;
- Document acNewDoc = acDocMgr.Add("acad.dwt");
- Database acDbNewDoc = acNewDoc.Database;
-
- // 锁定新文档 Lock the new document
- using (DocumentLock acLckDoc = acNewDoc.LockDocument())
- {
- // 在新数据库中启动事务 Start a transaction in the new database
- using (Transaction acTrans = acDbNewDoc.TransactionManager.StartTransaction())
- {
- // 以只读方式打开块表 Open the Block table for read
- BlockTable acBlkTbl;
- acBlkTbl = acTrans.GetObject(acDbNewDoc.BlockTableId,
- OpenMode.ForRead) as BlockTable;
-
- // 以写方式打开模型空间块表记录 Open the Block table record Model space for write
- BlockTableRecord acBlkTblRec;
- acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
- OpenMode.ForWrite) as BlockTableRecord;
-
- // 创建一个半径为3圆心在5,5的圆 Create a circle with a radius of 3 at 5,5
- Circle acCirc = new Circle();
- acCirc.SetDatabaseDefaults();
- acCirc.Center = new Point3d(5, 5, 0);
- acCirc.Radius = 3;
-
- // 添加新对象到模型空间和事务中 Add the new object to Model space and the transaction
- acBlkTblRec.AppendEntity(acCirc);
- acTrans.AddNewlyCreatedDBObject(acCirc, true);
-
- // 保存新对象到数据库中 Save the new object to the database
- acTrans.Commit();
- }
-
- // 解锁文档 Unlock the document
- }
-
- // 设置新文档为当前文档 Set the new document current
- acDocMgr.MdiActiveDocument = acNewDoc;
- }
但是,我需要把这样的 新建-编辑 代码放到已有的代码里,所以[CommandMethod("LockDoc", CommandFlags.Session)]是没法加进去的。对其进行编辑时,始终没有效果,请问如何让Session
的效果在已有函数内起作用呢?谢谢 |