CAD 二开中,当要在除当前文档外的其它文档的模型空间或图纸空间中添加图元时,需要先锁定其文档。用户可用要锁定的Document对象的LockDocument方法进行锁定。在调用LockDocument方法后,将返回一个DocumentLock对象。
本例创建一个新的文档然后在里面画一个圆。文档创建后,新文档的数据库会被锁定,然后一个圆会被添加到里面。圆添加后,数据库会被解锁,并且与其关联的文档窗口会被设置成当前文档。
附代码:
using AcTools;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Runtime;
using System;
using System.Collections.Generic;
using System.Linq;
namespace Acdemo
{
public static class Acdemo
{
[CommandMethod("xx", CommandFlags.Session)]
public static void LockDoc()
{
// 创建新图形 Create a new drawing
DocumentCollection acDocMgr = Application.DocumentManager;
Document