Hello,
I'm trying to update a xref path of a autocad document without open it. I've tried something like this to access the database of a document
using (Database db = new Database(true, false))
{
db.ReadDwgFile(fullpath, System.IO.FileShare.ReadWrite, false, "");
// rest of the code ....
}
In order to do that the readdwgfile the document must be locked right? Because i'm going to modify blocks of the document. So how can I lock a document without open it?
Thanks and kind regards,
Diogo
You do not need to lock "Document", because there is no "Document" to lock.
The concept of Document in locking document refers to an Autodesk.AutoCAD.ApplicationServices.Document obkect existing in memory of an AutoCAD session. The need to lock is, is due to the relation of Document object and Database object in an MDI environment.
While you read a file form a dwg "document", the document refers a file, which is different thing from Document class object in memory.
Of course, your code may need to handle possible file acess exception, such as, if the drawing you try to read has alreay been opened by someone else for wrtie, then your code will throw file access exception.
Uhm ok, i see what you are saying, but I have another question.
Doing something like this:
doc = autoCadApp.DocumentManager.Open(fullpath);
autoCadApp.DocumentManager.MdiActiveDocument = doc;
doc.LockDocument(DocumentLockMode.Write, null, null, false);
Database db = doc.Database
is differente from doing this?
Database db = new Database(true, false);
db.ReadDwgFile(fullpath, FileShare.ReadWrite, false, string.Empty);
Because what I'm trying to do is modify the xref path of documents, and when i detach the xref and then attach the newer xref, if i access the database from the alternative 1, I don't get any error and the xref is updated. But when I use the alternative number 2, when I attach a newer xref i get and ePermantlyErased exception. Shouldn't that be the same? By the way, I need to open the document silently that is why I'm using alternative number 2.
Thanks and kind regards,
Diogo