Posts: 5
Registered: ‎09-12-2013
Message 1 of 2 (126 Views)
Accepted Solution

eNoDocument when Disposing DocumentLock

126 Views, 1 Replies
11-04-2013 02:43 PM

Hello, I am attempting to run a command over many files in a directory. I have a function that successfully iterates over the files in a directory and opens them, and then closes them again. However when I try to run a command on each file, my DocumentLock throws an eNoDocument exception. Maybe it has something to do with the fact that when my documents are opened, they have dialog boxes come up asking whether or not to show proxy images? Here is my code:


delegate void DoSomething(Document doc);

[CommandMethod("MASSINSERTGP4")] public void MassInsertGP4() { DoSomethingEnMasse(delegate(Document doc) { doc.SendStringToExecute("IEMBED all\n\n", true, false, false); }, true); } private void DoSomethingEnMasse(DoSomething something, bool savechanges) { Editor ed = Application.DocumentManager.MdiActiveDocument.Editor; try { PromptResult pr1 = ed.GetString("Directory path"); if (pr1.Status != PromptStatus.OK) { ed.WriteMessage("incorrect usage"); return; } ed.WriteMessage("Starting at " + DateTime.Now + "\n"); IEnumerable<string> files = new DirectoryInfo(pr1.StringResult).GetFiles().Where(x => x.Extension.ToLower() == ".dwg").Select(x => x.FullName); int i = 0; int count = files.Count(); foreach (string file in files) { try { i++; ed.WriteMessage("Processing " + i + " of " + count + ": " + file + "\n"); Document doc = Application.DocumentManager.Open(file, false); // DO THE THING THAT GETS DONE EN MASSE using (doc.LockDocument()) { something(doc); } if (savechanges) doc.CloseAndSave(file); else doc.CloseAndDiscard(); } catch (System.Exception ex) { ed.WriteMessage("Error occured: " + ex.Message + "\n" + ex.StackTrace); } } ed.WriteMessage("Done at " + DateTime.Now + "\n"); } catch(System.Exception ex) { ed.WriteMessage("Error occured: " + ex.Message + "\n" + ex.StackTrace); } }


Posts: 5
Registered: ‎09-12-2013
Message 2 of 2 (102 Views)

Re: eNoDocument when Disposing DocumentLock

11-04-2013 05:59 PM in reply to: schwabg
My problem was that I did not understand that executing a command changes the document context and stops execution, so i was manually closing these documents, and then the execution would continue, and find no document.

Furthermore, I needed to change the attributes on my method to be
[CommandMethod("MASSINSERTGP4", CommandFlags.Session)]
and then everything was fixed.

You are not logged in.

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

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