/// <summary> /// 总结:用到DocumentManager.Open(filePath)时,如果是ForWrite,就需要用到lock文档锁。 /// </summary> [CommandMethod("T38")] //测试文档锁 public void T38() { //Document doc = Application.DocumentManager.MdiActiveDocument; //如果是MdiActiveDocument,不需要锁LockDocument。 Document doc = MyTool.MyTools.OpenDwgFile(@"E:\res\autocad\test.dwg"); Database db = doc.Database; //Database db = new Database(); //db.ReadDwgFile(@"E:\res\autocad\test.dwg", FileShare.Read, true, null); //这种方式打开db,不要要锁。 using(doc.LockDocument()) //这里不锁的话,ForWrite模式打开就会报错,但ForRead模式不报错。但如果是MdiActiveDocument,也不需要锁。 using (Transaction trans = db.TransactionManager.StartTransaction()) { BlockTable bt = db.BlockTableId.GetObject(OpenMode.ForRead) as BlockTable; BlockTableRecord modelSpace = bt[BlockTableRecord.ModelSpace].GetObject(OpenMode.ForWrite) as BlockTableRecord; /* ObjectId bRefId = ObjectId.Null; foreach (ObjectId id in modelSpace) { if (id.GetObject(OpenMode.ForRead) is BlockReference) { bRefId = id; } break; } BlockReference bRef = bRefId.GetObject(OpenMode.ForWrite) as BlockReference; bRef.DowngradeOpen(); * */ } }
个人总结,貌似有误,有待继续学习。,。。
时间: 2024-10-17 07:54:06