Hi everyone.
I want to export all layouts in a DWG file automatically with this kind of code:
LayoutManager.Current.CurrentLayout = "Layout1"
Application.DocumentManager.MdiActiveDocument.SendStringToExecute("EXPORTLAYOUT " & strFilePath, True, False, False)
The layout is exported well, but each time a layout has been exported, a message appears with a question: "The file was successfully created. Do you want to open it now?", and the next layout won't be exported until user click button "Open" or "Don't open". I want export all layouts automatically without user input, so I don't want the message displays after exporting. How can I get rid of the dialog?
Thank you for any suggestion.
Solved! Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Solved by Alfred.NESWADBA. Go to Solution.
Hi,
if you send a LISP-string to the SendCommand, the question is not asked.
(command "_EXPORTLAYOUT")
- alfred -
Hi Alfred
Do you mean SendCommand from the COM document object, like this:
Dim app As AcadApplication = Application.AcadApplication
app.ActiveDocument.SendCommand("_EXPORTLAYOUT")
I tried but the result is the same, the message still appear
Hi,
no, instead of sending "_EXPORTLAYOUT" you should send "(command ""_EXPORTLAYOUT"")", it does not matter if you send it via COM or like shown in OP.
- alfred -
Hi Alfred
Thank you for your advice. I tried that way and it was OK.
I have an another little problem.
When the command EXPORTLAYOUT is executed, the AutoCAD window appears, despite the fact that I forced it to hide by this statement: Application.MainWindow.Visible = False. I want the program works silently so don't want it to show to users. How can I make it?
Hi,
sorry, I know it happens sometimes, but I haven't tried to avoid that.
I would first look for events reacting to window status changes.
If that does not work, maybe it's a help to not minimize the application window to taskbar, instead let the application window stay on desktop, but make it as small as possible 😉
HTH, - alfred -
PS: another problem should be placed as new thread so anyone searching that issue can find it!
Bit late but for not too large drawings this export a layout in the background with acceptable performance
[CommandMethod("EL")] public void ExportLayout() { Document dwg = Application.DocumentManager.MdiActiveDocument; Editor ed = dwg.Editor; string dwgSourcePathname = @"C:\temp\test.dwg"; string dwgDestPatname = Regex.Replace(dwgSourcePathname, ".dwg", "_2.dwg"); string layoutNameToExport = "ThatsTheOne"; try { ExportLayout(dwgSourcePathname, dwgDestPatname, layoutNameToExport); ed.WriteMessage("\n{0} saved in {1}", layoutNameToExport, dwgDestPatname); } catch (System.Exception ex) { ed.WriteMessage("\n{0}", ex.Message); } } public void ExportLayout(string dwgSourcePathname,string dwgDestPathname,string layoutNameToExport) { using (Database db = new Database(false, true)) { db.ReadDwgFile(dwgSourcePathname, FileShare.ReadWrite, false, null); using (Transaction tr = db.TransactionManager.StartTransaction()) { DBDictionary layoutDICT = (DBDictionary)tr.GetObject(db.LayoutDictionaryId, OpenMode.ForWrite); foreach (DBDictionaryEntry dictEntry in layoutDICT) { Layout layout = (Layout)tr.GetObject(dictEntry.Value, OpenMode.ForRead); if (!layout.ModelType && !Regex.IsMatch(layout.LayoutName, layoutNameToExport, RegexOptions.IgnoreCase)) { layout.UpgradeOpen(); layout.Erase(); } } string tmpPathname = Path.GetTempFileName(); db.SaveAs(tmpPathname, DwgVersion.Current); if (!File.Exists(dwgDestPathname)) File.Move(tmpPathname, dwgDestPathname); else { try { File.Copy(tmpPathname,dwgDestPathname,true); } catch { throw new System.Exception(string.Format("Error: Failed to overwrite: {0}, {1} saved in {2}",dwgDestPathname,layoutNameToExport,tmpPathname)); } } tr.Commit(); } } }
Can't find what you're looking for? Ask the community or share your knowledge.