您现在的位置是:首页 > 数码 > 

02

2025-07-27 02:24:52
02 Lock and Unlock a Document锁定和解锁文档 Requests to modify objects or access AutoCAD can occur in any context, and coming from any number of applicati. To prevent conflicts with other requests, you

02

Lock and Unlock a Document锁定和解锁文档

Requests to modify objects or access AutoCAD can occur in any context, and coming from any number of applicati. To prevent conflicts with other requests, you are respible for locking a document before you modify it. Failure to lock the document in certain contexts will cause a lock violation during the modification of the database. You want to lock the document when your application:

修改对象或访问AutoCAD的请求随时随地都发生,为避免与其他请求冲突,我们有责任在修改前锁定文档。某些情形下的锁定文档失败会导致在更新数据库过程中锁定犯规。当我们的应用程序进行下列操作是需要锁定文档:

·         Interacts with AutoCAD from a modeless dialog box 从无模式对话框与AutoCAD交互时;

·         Accesses a loaded document other than the current document 访问已调入的文档而不是当前文档时;

·         Used as a COM server 应用程序作为COM服务器时;

·         Registers a command with the Session command flag 用会话命令标志注册命令时

For example, when adding an entity to Model or Paper space in a document other than the current document, the document needs to be locked. You use the LockDocument method of the Database object you want to lock. When the LockDocument method is called, a DocumentLock object is returned.

例如,向非当前文档的模型或图纸空间添加实体时,就需要锁定文档。我们使用要锁定的数据库对象的LockDocument方法,调用LockDocument方法时,返回一个DocumentLock对象。

Once you are done modifying the locked database, you need to unlock the database. To unlock the database, you call the Dispose method of the DocumentLock object. You can also use the Using statement with the DocumentLock object, once the Using statement ends the database is unlocked.

一旦修改完已锁定数据库,就要将数据库解锁。解锁数据库,我们调用DocumentLock对象的Dispose方法。我们还可以使用Using语句,Using语句运行结束,数据库也就解锁了。(Using语句请参考C#中垃圾回收相关内容 – 译者)

oteWhen working in the context of a command that does not use the Session command flag, you do not need to lock the database for the current document before it is modified.

注意:执行没有使用会话命令标志的命令时,我们不需要在修改前锁定当前文档的数据库。

Lock a database before modifying an object 修改对象前锁定数据库

This example creates a new document and then draws a circle in it. After the document is created, the database for the new document is locked and then a circle is added to it. After the circle is added, the database is unlocked and the associated document window is set current.

本例新建一个文档然后绘制一个圆。文档创建后,新文档的数据库被锁定,然后圆添加到文档,添加完圆后数据库解锁,相应文档窗口置为当前。

VB.ET

Imports Autodesk.AutoCAD.ApplicationServices

Imports Autodesk.AutoCAD.DatabaseServices

Imports Autodesk.AutoCAD.Runtime

Imports Autodesk.AutoCAD.Geometry

 <CommandMethod(LockDoc, CommandFlags.Session)> _

Public Sub LockDoc()

  Create a new drawing

  Dim acDocMgr As DocumentCollection = Application.DocumentManager

  Dim acewDoc As Document = acDocMgr.Add(acad.dwt)

  Dim acDbewDoc As Database = acewDoc.Database

   Lock the new document

  Using acLckDoc As DocumentLock = acewDoc.LockDocument()

       Start a transaction in the new database

      Using acTrans As Transaction = acDbewDoc.TransactionManager.StartTransaction()

           Open the Block table for read

          Dim acBlkTbl As BlockTable

          acBlkTbl = acTrans.GetObject(acDbewDoc.BlockTableId, _

                                       OpenMode.ForRead)

           Open the Block table record Model space for write

          Dim acBlkTblRec As BlockTableRecord

          acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _

                                          OpenMode.ForWrite)

           Create a circle with a radius of at 5,5

          Dim acCirc As Circle = ew Circle()

          acCirc.Center = ew Pointd(5, 5, 0)

          acCirc.Radius =

           Add the new object to Model space and the transaction

          acBlkTblRec.AppendEntity(acCirc)

          acTrans.AddewlyCreatedDBObject(acCirc, True)

           Save the new object to the database

          acTrans.Commit()

      End Using

       Unlock the document

  End Using

   Set the new document current

  acDocMgr.MdiActiveDocument = acewDoc

End Sub

C#

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.Runtime;

using Autodesk.AutoCAD.Geometry;

 [CommandMethod(LockDoc, CommandFlags.Session)]

public static void LockDoc()

{

  // Create a new drawing新建图形

  DocumentCollection acDocMgr = Application.DocumentManager;

  Document acewDoc = acDocMgr.Add(acad.dwt);

  Database acDbewDoc = acewDoc.Database;

   // Lock the new document锁定新文档

  using (DocumentLock acLckDoc = acewDoc.LockDocument())

  {

      // Start a transaction in the new database启动新数据库事务

      using (Transaction acTrans = acDbewDoc.TransactionManager.StartTransaction())

      {

          // Open the Block table for read打开并读块表,

          BlockTable acBlkTbl;

          acBlkTbl = acTrans.GetObject(acDbewDoc.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;

           // Create a circle with a radius of at 5,5

          //以半径圆心(5,5)绘圆

          Circle acCirc = new Circle();

          acCirc.Center = new Pointd(5, 5, 0);

          acCirc.Radius = ;

           // Add the new object to Model space and the transaction

          //向模型空间和事务添加新对象

          acBlkTblRec.AppendEntity(acCirc);

          acTrans.AddewlyCreatedDBObject(acCirc, true);

           // Save the new object to the database提交事务,保存新对象到数据库

          acTrans.Commit();

      }

       // Unlock the document解锁文档using语句到此结束

  }

   // Set the new document current将新文档置为当前

  acDocMgr.MdiActiveDocument = acewDoc;

}

 

 

 

 

 

#感谢您对电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格的认可,转载请说明来源于"电脑配置推荐网 - 最新i3 i5 i7组装电脑配置单推荐报价格

本文地址:http://www.dnpztj.cn/shuma/707485.html

相关标签:无
上传时间: 2023-11-21 21:18:49

上一篇:2020

下一篇:iconv java

留言与评论(共有 15 条评论)
本站网友 什么是亲和力
6分钟前 发表
5           Dim acCirc As Circle = ew Circle()           acCirc.Center = ew Pointd(5
本站网友 杜玉涛
28分钟前 发表
5           //以半径圆心(5,5)绘圆           Circle acCirc = new Circle();           acCirc.Center = new Pointd(5
本站网友 境界梅江
22分钟前 发表
文档创建后,新文档的数据库被锁定,然后圆添加到文档,添加完圆后数据库解锁,相应文档窗口置为当前
本站网友 男士延时喷剂
21分钟前 发表
you need to unlock the database. To unlock the database
本站网友 万岁寿司
17分钟前 发表
0);           acCirc.Radius = ;            // Add the new object to Model space and the transaction           //向模型空间和事务添加新对象           acBlkTblRec.AppendEntity(acCirc);           acTrans.AddewlyCreatedDBObject(acCirc
本站网友 飞橙
6分钟前 发表
02 Lock and Unlock a Document锁定和解锁文档 Requests to modify objects or access AutoCAD can occur in any context
本站网友 东升伟业股票
19分钟前 发表
VB.ET Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.Geometry  <CommandMethod(LockDoc
本站网友 研究生报名信息网
5分钟前 发表
OpenMode.ForRead) as BlockTable;            // Open the Block table record Model space for write           //打开并写模型空间的块表记录           BlockTableRecord acBlkTblRec;           acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace]
本站网友 淮口二手房
5分钟前 发表
CommandFlags.Session)] public static void LockDoc() {   // Create a new drawing新建图形   DocumentCollection acDocMgr = Application.DocumentManager;   Document acewDoc = acDocMgr.Add(acad.dwt);   Database acDbewDoc = acewDoc.Database;    // Lock the new document锁定新文档   using (DocumentLock acLckDoc = acewDoc.LockDocument())   {       // Start a transaction in the new database启动新数据库事务       using (Transaction acTrans = acDbewDoc.TransactionManager.StartTransaction())       {           // Open the Block table for read打开并读块表,           BlockTable acBlkTbl;           acBlkTbl = acTrans.GetObject(acDbewDoc.BlockTableId
本站网友 索引越界
2分钟前 发表
5
本站网友 咬唇
19分钟前 发表
5
本站网友 少数民族生二胎政策
23分钟前 发表
and coming from any number of applicati. To prevent conflicts with other requests
本站网友 七彩虹c3
29分钟前 发表
解锁数据库,我们调用DocumentLock对象的Dispose方法
本站网友 广元博爱医院
13分钟前 发表
once the Using statement ends the database is unlocked. 一旦修改完已锁定数据库,就要将数据库解锁