AutoCAD .NET has wrapped almost all ObjectARX events through one way or another using still the event concept or something slightly different. As a whole, the AutoCAD .NET event or notification system is powerful and useful and a professional and relatively big addin cannot totally ignore the important force.
In this article, we will be talking about the AutoCAD .NET PlotReactorManager events. It is always good to start with some cool, concise and still full sample code. Here it is:
using System;
using System.Text;
using System.Linq;
using System.Xml;
using System.Reflection;
using System.ComponentModel;
using System.Collections;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media.Imaging;
using System.Windows.Forms;
using System.IO;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.Windows;
using AcadApplication = Autodesk.AutoCAD.ApplicationServices.Application;
using AcadDocument = Autodesk.AutoCAD.ApplicationServices.Document;
using AcadWindows = Autodesk.AutoCAD.Windows;
namespace AcadNetAddinWizard_Namespace
{
public class PlotManagerEvents
{
[CommandMethod("RegisterPlotManagerEvents")]
public void RegisterPlotManagerEvents_Method()
{
PlotManagerEvents eventManager = new PlotManagerEvents();
eventManager.Register();
}
[CommandMethod("UnRegisterPlotManagerEvents")]
public void UnRegisterPlotManagerEvents_Method()
{
PlotManagerEvents eventManager = new PlotManagerEvents();
eventManager.UnRegister();
}
public void Register()
{
Autodesk.AutoCAD.PlottingServices.PlotReactorManager plotManager = new Autodesk.AutoCAD.PlottingServices.PlotReactorManager();
plotManager.BeginPlot += new Autodesk.AutoCAD.PlottingServices.BeginPlotEventHandler(plotManager_BeginPlot);
plotManager.EndPlot += new Autodesk.AutoCAD.PlottingServices.EndPlotEventHandler(plotManager_EndPlot);
plotManager.PlotCancelled += new Autodesk.AutoCAD.PlottingServices.PlotCancelledEventHandler(plotManager_PlotCancelled);
}
public void UnRegister()
{
Autodesk.AutoCAD.PlottingServices.PlotReactorManager plotManager = new Autodesk.AutoCAD.PlottingServices.PlotReactorManager();
plotManager.BeginPlot -= new Autodesk.AutoCAD.PlottingServices.BeginPlotEventHandler(plotManager_BeginPlot);
plotManager.EndPlot -= new Autodesk.AutoCAD.PlottingServices.EndPlotEventHandler(plotManager_EndPlot);
plotManager.PlotCancelled -= new Autodesk.AutoCAD.PlottingServices.PlotCancelledEventHandler(plotManager_PlotCancelled);
}
void plotManager_PlotCancelled(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPlotCancelled\n");
}
void plotManager_EndPlot(object sender, Autodesk.AutoCAD.PlottingServices.EndPlotEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nEndPlot\n");
}
void plotManager_BeginPlot(object sender, Autodesk.AutoCAD.PlottingServices.BeginPlotEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nBeginPlot\n");
}
}
}
The code is short and self-explanatory so we will not waste our words here. Let us play around the command and look at some command outputs:
Command: RegisterPlotManagerEvents
Command: FILEDIA
Enter new value for FILEDIA <1>: 0
Command: -PLOT
Detailed plot configuration? [Yes/No] <No>:
Enter a layout name or [?] <Model>:
Enter a page setup name <>: DWG2PDF
Enter an output device name or [?] <DWG To PDF.pc3>:
Enter file name <C:\Temp\Test-Model.pdf>:
C:\Temp\Test-Model.pdf already exists, do you want to replace it? [Yes/No] <N>: y
Save changes to page setup [Yes/No]? <N> y
Proceed with plot [Yes/No] <Y>:
BeginPlot
Effective plotting area: 3.54 wide by 9.60 high
Plotting viewport 2.
EndPlot
Command: UnRegisterPlotManagerEvents
Command: -PLOT
Detailed plot configuration? [Yes/No] <No>:
Enter a layout name or [?] <Model>:
Enter a page setup name <DWG2PDF>:
Enter an output device name or [?] <DWG To PDF.pc3>:
Enter file name <C:\Temp\Test-Model.pdf>:
C:\Temp\Test-Model.pdf already exists, do you want to replace it? [Yes/No] <N>: y
Save changes to page setup [Yes/No]? <N>
Proceed with plot [Yes/No] <Y>:
Effective plotting area: 3.54 wide by 9.60 high
Plotting viewport 2.
Command:
As can be noticed, the event BeginPlot notification was sent out right before the plot really take effects and the EndPlot right after it finishes.
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides kinds of AutoCAD .NET Event Handler Wizards including an AutoCAD PlotReactorManager Event Wizard to help create start code of event handlers automatically, quickly, flexibly and reliably.
Recent Comments