.NET

.NET

Reply
Member
3 Posts
0 Kudos
Registered: ‎10-06-2013
Post 1 of 7
Accepted Solution

How to get rid of the message after exporting layout

413 Views, 6 Replies
10-06-2013 07:50 PM

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.

Hi,

 

if you send a LISP-string to the SendCommand, the question is not asked.

(command "_EXPORTLAYOUT")

 

- alfred -

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?

*Expert Elite*
9,817 Posts
1,212 Kudos
Registered: ‎06-29-2007
Post 2 of 7

Re: How to get rid of the message after exporting layout

10-06-2013 08:15 PM in reply to: luvina_lyducdu

Hi,

 

if you send a LISP-string to the SendCommand, the question is not asked.

(command "_EXPORTLAYOUT")

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Member
3 Posts
0 Kudos
Registered: ‎10-06-2013
Post 3 of 7

Re: How to get rid of the message after exporting layout

10-06-2013 08:51 PM in reply to: Alfred.NESWADBA

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

*Expert Elite*
9,817 Posts
1,212 Kudos
Registered: ‎06-29-2007
Post 4 of 7

Re: How to get rid of the message after exporting layout

10-06-2013 09:52 PM in reply to: luvina_lyducdu

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 -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Member
3 Posts
0 Kudos
Registered: ‎10-06-2013
Post 5 of 7

Re: How to get rid of the message after exporting layout

10-07-2013 07:10 PM in reply to: luvina_lyducdu

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?

*Expert Elite*
9,817 Posts
1,212 Kudos
Registered: ‎06-29-2007
Post 6 of 7

Re: How to get rid of the message after exporting layout

10-07-2013 11:24 PM in reply to: luvina_lyducdu

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 :smileywink:

 

HTH, - alfred -

PS: another problem should be placed as new thread so anyone searching that issue can find it!

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Mentor
248 Posts
44 Kudos
Registered: ‎07-20-2011
Post 7 of 7

Re: How to get rid of the message after exporting layout

12-07-2013 04:24 PM in reply to: Alfred.NESWADBA

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();
                }
            }
        }

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!