Posts: 17
Registered: ‎06-19-2012
Message 1 of 3 (183 Views)

Lock document wtihout open it

183 Views, 2 Replies
06-19-2012 06:43 AM



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,




*Expert Elite*
Posts: 1,063
Registered: ‎04-27-2009
Message 2 of 3 (178 Views)

Re: Lock document wtihout open it

06-19-2012 07:14 AM in reply to: DiogoSantos

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.

Posts: 17
Registered: ‎06-19-2012
Message 3 of 3 (169 Views)

Re: Lock document wtihout open it

06-19-2012 08:38 AM in reply to: DiogoSantos

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,



Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.