.NET

Reply
Contributor
DiogoSantos
Posts: 17
Registered: ‎06-19-2012
Message 1 of 3 (170 Views)

Lock document wtihout open it

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

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

 

*Expert Elite*
norman.yuan
Posts: 965
Registered: ‎04-27-2009
Message 2 of 3 (165 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.

Contributor
DiogoSantos
Posts: 17
Registered: ‎06-19-2012
Message 3 of 3 (156 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,

Diogo

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community