/// <summary> ///Summary: When using Documentmanager.open (FilePath), lock document Lock is required if it is forwrite. /// </summary>[Commandmethod ("T38")]//Test Document Lock Public voidT38 () {//Document doc = Application.DocumentManager.MdiActiveDocument; //if it is mdiactivedocument, you do not need to lock 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); //this way open the db, do not want to lock. using(Doc. LockDocument ())//if not locked here, Forwrite mode will be error, but Forread mode does not error. But if it's mdiactivedocument, it doesn't need a lock. using(Transaction trans =db. Transactionmanager.starttransaction ()) {blocktable BT= db. Blocktableid.getobject (Openmode.forread) asblocktable; Blocktablerecord Modelspace= Bt[blocktablerecord.modelspace]. GetObject (Openmode.forwrite) asBlocktablerecord; /*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 (); * */ } }
Personal summary, seemingly wrong, pending further study. ,。。
Test document Lock: Doc. LockDocument ()