Plot Engine - Problems Cancelling Plot
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been working on plotting multiple page setups to a single PDF.
I am passing a list of validated PlotInfo objects, beginning a document, and looping through adding each as a page to the document. Everything works fine except when the "Cancel" button is clicked on the plot progress dialog.
My question is how should I properly catch and handle when the "Cancel" button is clicked on the dialog?
Wrapping engine.BeginPlot () ... engine.EndPlot() in a try block and returning from the function when catching a "PlotCancelled" runtime exception seems to work just fine when the PlotInfos are all set to use "DWG to PDF". However, when using a different multi-sheet device (such as Adobe PDF or my home printer) clicking the "Cancel" button exits my routine, but leaves the plotting device stuck in a "spooling" state. A subsequent call using the same device freezes AutoCAD.
Does anyone know if there is extra cleanup that I need to do? I can't seem to find anything in the .NET documentation about cancelling a plot.
Any help would be greatly appreciated.
void PlotDocument(List<PlotInfo> PlotInfos, string Filename)
{
Document document = Application.DocumentManager.MdiActiveDocument;
if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
{
using (PlotEngine engine = PlotFactory.CreatePublishEngine())
using (PlotProgressDialog dialog = new PlotProgressDialog(false, PlotInfos.Count, false))
using (PlotPageInfo pageInfo = new PlotPageInfo())
{
dialog.IsVisible = true ;
engine.BeginPlot(dialog, null);
engine.BeginDocument(PlotInfos[0],
document.Name, null, 1,
PlotInfos[0].ValidatedConfig.IsPlotToFile,
Filename);
foreach (PlotInfo plotInfo in PlotInfos)
{
LayoutManager.Current.SetCurrentLayoutId(plotInfo.Layout);
engine.BeginPage(pageInfo, plotInfo, plotInfo == PlotInfos[PlotInfos.Count-1], null);
engine.BeginGenerateGraphics(null);
engine.EndGenerateGraphics(null);
engine.EndPage(null);
}
engine.EndDocument(null);
engine.EndPlot(null);
}
}
}(In the code I'm sharing, I have removed checks for document compatibility, exception handling for devices that are not multi-sheet capable, and progress dialog setup because those are things I know how to deal with and the code just takes up space.)
I am working with AutoCAD 2018, developing in C#, with Visual Studio 2019, on Windows 10.