saving a model AutoCAD, Civil3D .Net api errors with Drawing Write Protected

saving a model AutoCAD, Civil3D .Net api errors with Drawing Write Protected

pari_dhanakoti
Enthusiast Enthusiast
353 Views
4 Replies
Message 1 of 5

saving a model AutoCAD, Civil3D .Net api errors with Drawing Write Protected

pari_dhanakoti
Enthusiast
Enthusiast

I have an add-in that lets user selects mutliple models and for each, it is made the active document, some properties are added to it, then the document is saved and closed. This works for models that are local to my machine. But if I run it on the model that is in Drive (accessed via Autodesk Docs that mirrors Autodesk Construction Cloud), it fails with the error that "Drawing is write protected".

 

My snippet of the code that does the save:

db.SaveAs(acadDoc.Name, true, DwgVersion.Current, acadDoc.Database.SecurityParameters);
doc.CloseAndSave(doc.Name);

 

Question: 

I observe that when the model from Autodesk Docs (shared drive) is opened via the add-in, a lock gets applied. so db.SaveAs is not working. How do I prevent this?

0 Likes
Accepted solutions (1)
354 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor

The issue has nothing to do with the code calling Database.SaveAs(). You can try to pass a full file name that points to a folder of the computer's local drive that you have full access to verify that the code works. The "lock" file you saw, if they are like [FileName].dwl, is AutoCAD created file whenever it opens a drawing file. It does not actually lock the drawing from being saved from the same AutoCAD session.

 

It is likely that the Autodesk Docs permission issue (when your computer connect to the Autodesk Docs via Autodesk Desktop Connector?).

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

pari_dhanakoti
Enthusiast
Enthusiast

Hi @norman.yuan , yes the computer connects to Autodesk Docs via Autodesk Desktop connector.

The issue does not happen if its a local model. The exact error that happens when trying to save the changes to model opened via Autodesk Docs / Desktop Connector is "Drawing file is write protected". Sometimes I also see  Error: eLockViolation

0 Likes
Message 4 of 5

norman.yuan
Mentor
Mentor
Accepted solution

Error message "eLockViolation" HAS NOTHING to do with saving drawing database as drawing file. If you run into this error, it is your code error when dealing with database-residing objects, and you may want to start another discussion thread for this topic.

 

Again, the error of not able to save the drawing file directly in the Autodesk DOCS' drive is not because of Database.SaveAs(). I do not use Autodesk DOCS, but a business document management system of this kind should/must have some kind version control/check in/out rules, rather than allow users to save whatever changes back freely. So, you must find out what kind of permissions you are given to the drawings in the Autodesk DOCS drive.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 5

pari_dhanakoti
Enthusiast
Enthusiast

agreed, I have to see what is causing the issue with saving. But you are right that Write Protected error is different from "elockViolation". Posting my solution for "elockViolation" error here. Any add-in that uses CommandFlags.Session should also lock a document before starting a transaction. Otherwise it causes the eLockViolation error. Locking a document can be done within a scope
Eg: 

 

using (DocumentLock acLckDoc = acadDoc.LockDocument()) 
{
          .... all the logic for transaction, adding an object / editing the 
          drawing etc happens here
}

 

 

0 Likes