Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi everyone,
I've been receiving amazing help from reading other people's posts on this forum. Thank you!
I've been working on capturing (or taking a screenshot of) specific coordinates using the attached function.
The code works fine, but it's extremely SLOW!!.
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.
Could you please help me out with this issue?
Thank you in advance!
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();
}
Solved! Go to Solution.