<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Optimizing Interop Plotting to PDF - C# in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8664152#M23211</link>
    <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;If the use of .bat file(s) (as in the &lt;A href="https://www.keanw.com/2012/02/the-autocad-2013-core-console.html" target="_blank" rel="noopener"&gt;Kean example&lt;/A&gt;) does not suit you, you can call AutoLISP expressions from the script file or, if you prefer, create a custom .NET command (with &lt;/SPAN&gt;&lt;SPAN class=""&gt;only references to accoremgd.dll and acbdmgd.dll), NETLOAD it and run it from the script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 17 Mar 2019 16:55:24 GMT</pubDate>
    <dc:creator>_gile</dc:creator>
    <dc:date>2019-03-17T16:55:24Z</dc:date>
    <item>
      <title>Optimizing Interop Plotting to PDF - C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8660392#M23208</link>
      <description>&lt;P&gt;Like many here before, I am needing to essentially batch plot a set of drawings to PDF. I originally thought I would be using ObjectARX to do this but then found that ObjectARX projects are typically addins for AutoCAD. My second thought was to take advantage of accoreconsole but I am not sure my use case fits necessarily works since accoreconsole expects a script to do anything. This would probably be my preferred method of saving my drawings to PDF so if there is a way to use accoreconsole I am open to suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So far I have functional code that sends a set of drawings to AutoCAD through COM and gives me PDF files. I have a few problems however:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;I cannot figure out how to prevent the resulting PDF from being opened.&lt;/LI&gt;
&lt;LI&gt;Once all of the drawings are processed and I quit AutoCAD, the first file processed asks if I want to save changes. What type of object to I need for "object SaveChanges" when calling Close() on a document?&lt;/LI&gt;
&lt;LI&gt;The process is relatively slow. To process 32 files takes around 2 minutes. I am using a single instance of AutoCAD so the slowdown shouldn't be occurring there. Obviously using Interop is never going to be the quickest but maybe there's a way to speed this up?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Code for reference:&lt;/P&gt;
&lt;PRE&gt;static void Main(string[] args)
        {
            Type acType = Type.GetTypeFromProgID("AutoCAD.Application.23");
            AutoCAD.AcadApplication acApp = null; //new AutoCAD.AcadApplication();

            try
            {
                acApp = (AutoCAD.AcadApplication)Marshal.GetActiveObject("AutoCAD.Application");
            }
            catch
            {
                acApp = new AutoCAD.AcadApplication();
                //AutoCAD.AcadApplication acApp = (AutoCAD.AcadApplication)Activator.CreateInstance(acType, true);
            }

            acApp.Visible = false;

            AutoCAD.AcadDocument acDoc = null;

            string dwgDir = @"H:\Development\C#\Misc\44OP-257468\44OP-257468\MDT\";
            var dwgs = Directory.EnumerateFiles(dwgDir, "*.dwg");
            foreach (var dwg in dwgs)
            {
                FileInfo dwgInfo = new FileInfo(dwg);
                string outputFile = String.Format("G:\\temp\\{0}.pdf", dwgInfo.Name);
                acDoc = acApp.Documents.Open(dwg);
                    
                while (!acApp.GetAcadState().IsQuiescent)
                {
                    System.Threading.Thread.Sleep(25);
                }

                acDoc.ActiveSpace = AutoCAD.Common.AcActiveSpace.acModelSpace;

                var acPlotCfg = acDoc.PlotConfigurations;
                acPlotCfg.Add("PDF", true); // If second parameter is not true, exception is caused by acDoc.ActiveLayout.CopyFrom(PlotConfig);
                AutoCAD.Common.AcadPlotConfiguration PlotConfig = acPlotCfg.Item("PDF");
                PlotConfig.ConfigName = "DWG To PDF.pc3";
                PlotConfig.CanonicalMediaName = "ANSI_expand_A_(8.50_x_11.00_Inches)";
                PlotConfig.PlotHidden = true;
                PlotConfig.StandardScale = AutoCAD.Common.AcPlotScale.acScaleToFit;
                PlotConfig.PlotType = AutoCAD.Common.AcPlotType.acExtents;
                PlotConfig.PaperUnits = AutoCAD.Common.AcPlotPaperUnits.acInches;
                PlotConfig.PlotRotation = AutoCAD.Common.AcPlotRotation.ac90degrees;
                PlotConfig.CenterPlot = false;
                PlotConfig.PlotWithLineweights = true;
                PlotConfig.PlotWithPlotStyles = true;
                //PlotConfig.StyleSheet = "acad.ctb";
                PlotConfig.RefreshPlotDeviceInfo();

                acDoc.ActiveLayout.CopyFrom(PlotConfig);    // Need to have this or resulting PDF does not seem to apply the PlotConfig.
                acDoc.SetVariable("BACKGROUNDPLOT", 0);
                acDoc.Plot.QuietErrorMode = true;
                acDoc.Plot.PlotToFile(outputFile, PlotConfig.ConfigName);

                acDoc.Close(false, null);

                Console.WriteLine(String.Format("PDF Created For: {0}", dwgInfo.Name));
            }
            acApp.Quit();

            Console.WriteLine("Done");
            Console.ReadLine();
        }&lt;/PRE&gt;
&lt;P&gt;One thought I had that may or may not have any performance benefit at all would be to create an ObjectARX add-in that builds on the concepts of &lt;A href="https://help.autodesk.com/view/OARX/2019/ENU/?guid=GUID-6E0B1F7B-7B0E-4E3E-B1FD-018E0A3673BE" target="_blank" rel="noopener"&gt;this&lt;/A&gt;&amp;nbsp;example code. My thought is that perhaps I could send the add-in a list of drawings, output folder and filenames, and page orientation information and handle the plot that way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another thought would be to automate accoreconsole as I mentioned above. This *may* be the best option as I could spawn a bunch of instances and process files concurrently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any direction of which way to go is much appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Mar 2019 23:58:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8660392#M23208</guid>
      <dc:creator>grindstaffp</dc:creator>
      <dc:date>2019-03-14T23:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing Interop Plotting to PDF - C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8660819#M23209</link>
      <description>&lt;P&gt;Did you try using the &lt;A href="https://www.keanw.com/2012/02/the-autocad-2013-core-console.html" target="_blank" rel="noopener"&gt;Core Console&lt;/A&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 08:12:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8660819#M23209</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-15T08:12:42Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing Interop Plotting to PDF - C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8661595#M23210</link>
      <description>&lt;P&gt;I have used the core console and manually created a pdf running through the PLOT command but I am unsure of how to automate the use of core console without providing it a script to run. If I want to provide different output directories based on a given project I don't know a way to do that.&lt;/P&gt;
&lt;P&gt;Any pointers?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Mar 2019 14:32:22 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8661595#M23210</guid>
      <dc:creator>grindstaffp</dc:creator>
      <dc:date>2019-03-15T14:32:22Z</dc:date>
    </item>
    <item>
      <title>Re: Optimizing Interop Plotting to PDF - C#</title>
      <link>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8664152#M23211</link>
      <description>&lt;P&gt;&lt;SPAN class="tlid-translation translation"&gt;&lt;SPAN&gt;If the use of .bat file(s) (as in the &lt;A href="https://www.keanw.com/2012/02/the-autocad-2013-core-console.html" target="_blank" rel="noopener"&gt;Kean example&lt;/A&gt;) does not suit you, you can call AutoLISP expressions from the script file or, if you prefer, create a custom .NET command (with &lt;/SPAN&gt;&lt;SPAN class=""&gt;only references to accoremgd.dll and acbdmgd.dll), NETLOAD it and run it from the script.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Mar 2019 16:55:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/optimizing-interop-plotting-to-pdf-c/m-p/8664152#M23211</guid>
      <dc:creator>_gile</dc:creator>
      <dc:date>2019-03-17T16:55:24Z</dc:date>
    </item>
  </channel>
</rss>

