<?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 I want to make my plotting code faster. in .NET Forum</title>
    <link>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12521534#M5779</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I've been receiving amazing help from reading other people's posts on this forum. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been working on capturing (or taking a screenshot of) specific coordinates using the attached function.&lt;/P&gt;&lt;P&gt;The code works fine, but it's extremely SLOW!!.&lt;/P&gt;&lt;P&gt;I expected it to take less than a second, but it takes at least 10 seconds. It executes all the way down to the "this.Show()" function almost immediately, but generating the actual file takes a long time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me out with this issue?&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;private void CaptureAndSaveImage(Point3d startPoint, Point3d endPoint, string outputPath)
{
    
    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    using (DocumentLock docLock = doc.LockDocument())

    {
        // Start a transaction
        using (Transaction trans = db.TransactionManager.StartTransaction())
        {

            // Get the current layout
            //Layout layout = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as Layout;
            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);

            Layout layout = (Layout)trans.GetObject(btr.LayoutId, OpenMode.ForRead);
            //ObjectId modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
            //Layout layout = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as Layout;
            // Create a new PlotInfo object

            PlotSettings plotSettings = new PlotSettings(layout.ModelType);
            plotSettings.CopyFrom(layout);

            // Get the PlotSettingsValidator
            PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;

            // Calculate the extents from the two points
            Extents2d plotWindowExtents = new Extents2d(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

            plotSettings.ScaleLineweights = true;


            // Set the plot area
            plotSettingsValidator.SetPlotWindowArea(plotSettings, plotWindowExtents);
            plotSettingsValidator.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
            plotSettingsValidator.SetUseStandardScale(plotSettings, true);

            plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
            plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees180);
            
            plotSettingsValidator.SetPlotCentered(plotSettings, false);
            // Set the plot configuration name
            plotSettingsValidator.SetPlotConfigurationName(plotSettings, "PublishToWeb PNG.pc3", "VGA_(640.00_x_480.00_Pixels)");

            //plotSettingsValidator.SetPlotConfigurationName(plotSettings, "AutoCAD PDF (Web and Mobile).pc3", "ISO_A4_(210.00_x_297.00_MM)");
            // Update the PlotInfo object with the new settings
            PlotInfo plotInfo = new PlotInfo();
            plotInfo.Layout = btr.LayoutId;
            plotInfo.OverrideSettings = plotSettings;

            PlotInfoValidator piv = new PlotInfoValidator();

            piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;

            piv.Validate(plotInfo);

            //// Commit the changes to the transaction
            trans.Commit();

            // Plot the image
            using (PlotEngine plotEngine = PlotFactory.CreatePublishEngine())
            {
                plotEngine.BeginPlot(null, null);

                plotEngine.BeginDocument(plotInfo, doc.Name, null, 1, true, Path.Combine("C:\\Users\\YR_VM\\Desktop\\cad backup", Guid.NewGuid() + ".png"));

                // Define the plot output
                PlotPageInfo pageInfo = new PlotPageInfo();
                try
                {
                    plotEngine.BeginPage(pageInfo, plotInfo, true, null);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                plotEngine.BeginGenerateGraphics(null);
                plotEngine.EndGenerateGraphics(null);


                plotEngine.EndPage(null);
                plotEngine.EndDocument(null);

                // End the plot
                plotEngine.EndPlot(null);
            }
        }
    }


    this.Show();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2024 08:07:32 GMT</pubDate>
    <dc:creator>goforlee</dc:creator>
    <dc:date>2024-01-26T08:07:32Z</dc:date>
    <item>
      <title>I want to make my plotting code faster.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12521534#M5779</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I've been receiving amazing help from reading other people's posts on this forum. Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been working on capturing (or taking a screenshot of) specific coordinates using the attached function.&lt;/P&gt;&lt;P&gt;The code works fine, but it's extremely SLOW!!.&lt;/P&gt;&lt;P&gt;I expected it to take less than a second, but it takes at least 10 seconds. It executes all the way down to the "this.Show()" function almost immediately, but generating the actual file takes a long time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me out with this issue?&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;private void CaptureAndSaveImage(Point3d startPoint, Point3d endPoint, string outputPath)
{
    
    Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
    Database db = doc.Database;
    using (DocumentLock docLock = doc.LockDocument())

    {
        // Start a transaction
        using (Transaction trans = db.TransactionManager.StartTransaction())
        {

            // Get the current layout
            //Layout layout = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as Layout;
            BlockTableRecord btr = (BlockTableRecord)trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead);

            Layout layout = (Layout)trans.GetObject(btr.LayoutId, OpenMode.ForRead);
            //ObjectId modelSpaceId = SymbolUtilityServices.GetBlockModelSpaceId(db);
            //Layout layout = trans.GetObject(db.CurrentSpaceId, OpenMode.ForRead) as Layout;
            // Create a new PlotInfo object

            PlotSettings plotSettings = new PlotSettings(layout.ModelType);
            plotSettings.CopyFrom(layout);

            // Get the PlotSettingsValidator
            PlotSettingsValidator plotSettingsValidator = PlotSettingsValidator.Current;

            // Calculate the extents from the two points
            Extents2d plotWindowExtents = new Extents2d(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y);

            plotSettings.ScaleLineweights = true;


            // Set the plot area
            plotSettingsValidator.SetPlotWindowArea(plotSettings, plotWindowExtents);
            plotSettingsValidator.SetPlotType(plotSettings, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
            plotSettingsValidator.SetUseStandardScale(plotSettings, true);

            plotSettingsValidator.SetStdScaleType(plotSettings, StdScaleType.ScaleToFit);
            plotSettingsValidator.SetPlotRotation(plotSettings, PlotRotation.Degrees180);
            
            plotSettingsValidator.SetPlotCentered(plotSettings, false);
            // Set the plot configuration name
            plotSettingsValidator.SetPlotConfigurationName(plotSettings, "PublishToWeb PNG.pc3", "VGA_(640.00_x_480.00_Pixels)");

            //plotSettingsValidator.SetPlotConfigurationName(plotSettings, "AutoCAD PDF (Web and Mobile).pc3", "ISO_A4_(210.00_x_297.00_MM)");
            // Update the PlotInfo object with the new settings
            PlotInfo plotInfo = new PlotInfo();
            plotInfo.Layout = btr.LayoutId;
            plotInfo.OverrideSettings = plotSettings;

            PlotInfoValidator piv = new PlotInfoValidator();

            piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;

            piv.Validate(plotInfo);

            //// Commit the changes to the transaction
            trans.Commit();

            // Plot the image
            using (PlotEngine plotEngine = PlotFactory.CreatePublishEngine())
            {
                plotEngine.BeginPlot(null, null);

                plotEngine.BeginDocument(plotInfo, doc.Name, null, 1, true, Path.Combine("C:\\Users\\YR_VM\\Desktop\\cad backup", Guid.NewGuid() + ".png"));

                // Define the plot output
                PlotPageInfo pageInfo = new PlotPageInfo();
                try
                {
                    plotEngine.BeginPage(pageInfo, plotInfo, true, null);

                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }
                plotEngine.BeginGenerateGraphics(null);
                plotEngine.EndGenerateGraphics(null);


                plotEngine.EndPage(null);
                plotEngine.EndDocument(null);

                // End the plot
                plotEngine.EndPlot(null);
            }
        }
    }


    this.Show();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 08:07:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12521534#M5779</guid>
      <dc:creator>goforlee</dc:creator>
      <dc:date>2024-01-26T08:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: I want to make my plotting code faster.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12522440#M5780</link>
      <description>&lt;P&gt;Plotting would obviously take longer than a graphics dump of the current view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;While output to PDF may not be possible using other means, the code at &lt;A href="https://www.keanw.com/2007/04/taking_a_snapsh_1.html" target="_blank" rel="noopener"&gt;this link&lt;/A&gt; will generate a screenshot.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2024 17:37:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12522440#M5780</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-01-26T17:37:05Z</dc:date>
    </item>
    <item>
      <title>Re: I want to make my plotting code faster.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12523549#M5781</link>
      <description>&lt;P&gt;I am not really great at coding... but the link doesn't seem like I can specify coordinates of objects as my code. Did I understand it wrong? or I can implement that kind of function with the code in the link ??&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jan 2024 12:57:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12523549#M5781</guid>
      <dc:creator>goforlee</dc:creator>
      <dc:date>2024-01-27T12:57:48Z</dc:date>
    </item>
    <item>
      <title>Re: I want to make my plotting code faster.</title>
      <link>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12523796#M5782</link>
      <description>&lt;P&gt;The code at that link really doesn't specify what to take a snapshot of it just shows how to take a snapshot. So, you would have to first set the view before taking the snapshot through code.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jan 2024 17:41:04 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/net-forum/i-want-to-make-my-plotting-code-faster/m-p/12523796#M5782</guid>
      <dc:creator>ActivistInvestor</dc:creator>
      <dc:date>2024-01-27T17:41:04Z</dc:date>
    </item>
  </channel>
</rss>

