AutoCAD .NET Addin Wizard (AcadNetAddinWizard) provides kinds of Event Handler Wizards to help automatically and intelligently generate start code of even handlers and register them in an chosen application extension or command method or both.
AutoCAD .NET Publisher Events Wizard is one of them. After a source file name is given and the Add button pressed, the event wizard Welcome page, Event Chosen page, Naming Convention and Application-Extension/Command-Method Setting page, and Summary page will show up one after another.
If all events are chosen and other settings are like above, the even handler class will look like this:
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 AcadNetAddinByVS2010
{
public class PublisherEvents1
{
public void Register()
{
AcadApplication.Publisher.InitPublishOptionsDialog += PublisherEvent_InitPublishOptionsDialog_Handler;
AcadApplication.Publisher.EndSheet += PublisherEvent_EndSheet_Handler;
AcadApplication.Publisher.EndPublish += PublisherEvent_EndPublish_Handler;
AcadApplication.Publisher.EndEntity += PublisherEvent_EndEntity_Handler;
AcadApplication.Publisher.CancelledOrFailedPublishing += PublisherEvent_CancelledOrFailedPublishing_Handler;
AcadApplication.Publisher.BeginSheet += PublisherEvent_BeginSheet_Handler;
AcadApplication.Publisher.BeginPublishingSheet += PublisherEvent_BeginPublishingSheet_Handler;
AcadApplication.Publisher.BeginEntity += PublisherEvent_BeginEntity_Handler;
AcadApplication.Publisher.BeginAggregation += PublisherEvent_BeginAggregation_Handler;
AcadApplication.Publisher.AboutToMoveFile += PublisherEvent_AboutToMoveFile_Handler;
AcadApplication.Publisher.AboutToEndPublishing += PublisherEvent_AboutToEndPublishing_Handler;
AcadApplication.Publisher.AboutToBeginPublishing += PublisherEvent_AboutToBeginPublishing_Handler;
AcadApplication.Publisher.AboutToBeginBackgroundPublishing += PublisherEvent_AboutToBeginBackgroundPublishing_Handler;
}
public void UnRegister()
{
AcadApplication.Publisher.InitPublishOptionsDialog -= PublisherEvent_InitPublishOptionsDialog_Handler;
AcadApplication.Publisher.EndSheet -= PublisherEvent_EndSheet_Handler;
AcadApplication.Publisher.EndPublish -= PublisherEvent_EndPublish_Handler;
AcadApplication.Publisher.EndEntity -= PublisherEvent_EndEntity_Handler;
AcadApplication.Publisher.CancelledOrFailedPublishing -= PublisherEvent_CancelledOrFailedPublishing_Handler;
AcadApplication.Publisher.BeginSheet -= PublisherEvent_BeginSheet_Handler;
AcadApplication.Publisher.BeginPublishingSheet -= PublisherEvent_BeginPublishingSheet_Handler;
AcadApplication.Publisher.BeginEntity -= PublisherEvent_BeginEntity_Handler;
AcadApplication.Publisher.BeginAggregation -= PublisherEvent_BeginAggregation_Handler;
AcadApplication.Publisher.AboutToMoveFile -= PublisherEvent_AboutToMoveFile_Handler;
AcadApplication.Publisher.AboutToEndPublishing -= PublisherEvent_AboutToEndPublishing_Handler;
AcadApplication.Publisher.AboutToBeginPublishing -= PublisherEvent_AboutToBeginPublishing_Handler;
AcadApplication.Publisher.AboutToBeginBackgroundPublishing -= PublisherEvent_AboutToBeginBackgroundPublishing_Handler;
}
public void PublisherEvent_AboutToBeginBackgroundPublishing_Handler(object sender, Autodesk.AutoCAD.Publishing.AboutToBeginBackgroundPublishingEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nAboutToBeginBackgroundPublishing\n");
}
public void PublisherEvent_AboutToBeginPublishing_Handler(object sender, Autodesk.AutoCAD.Publishing.AboutToBeginPublishingEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nAboutToBeginPublishing\n");
}
public void PublisherEvent_AboutToEndPublishing_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nAboutToEndPublishing\n");
}
public void PublisherEvent_AboutToMoveFile_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nAboutToMoveFile\n");
}
public void PublisherEvent_BeginAggregation_Handler(object sender, Autodesk.AutoCAD.Publishing.BeginAggregationEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nBeginAggregation\n");
}
public void PublisherEvent_BeginEntity_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEntityEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nBeginEntity\n");
}
public void PublisherEvent_BeginPublishingSheet_Handler(object sender, Autodesk.AutoCAD.Publishing.BeginPublishingSheetEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nBeginPublishingSheet\n");
}
public void PublisherEvent_BeginSheet_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishSheetEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nBeginSheet\n");
}
public void PublisherEvent_CancelledOrFailedPublishing_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nCancelledOrFailedPublishing\n");
}
public void PublisherEvent_EndEntity_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEntityEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nEndEntity\n");
}
public void PublisherEvent_EndPublish_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nEndPublish\n");
}
public void PublisherEvent_EndSheet_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishSheetEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nEndSheet\n");
}
public void PublisherEvent_InitPublishOptionsDialog_Handler(object sender, Autodesk.AutoCAD.Publishing.PublishUIEventArgs e)
{
System.Diagnostics.Debug.WriteLine("\nInitPublishOptionsDialog\n");
}
}
}
Here is the event registration code in the chosen IExtensionApplication implementation by the way:
#region Namespaces
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.Drawing;
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;
#endregion
namespace AcadNetAddinByVS2010
{
public class ExtApp : IExtensionApplication
{
#region IExtensionApplication Members
public void Initialize()
{
//TODO: add code to run when the ExtApp initializes. Here are a few examples:
// Checking some host information like build #, a patch or a particular Arx/Dbx/Dll;
// Creating/Opening some files to use in the whole life of the assembly, e.g. logs;
// Adding some ribbon tabs, panels, and/or buttons, when necessary;
// Loading some dependents explicitly which are not taken care of automatically;
// Subscribing to some events which are important for the whole session;
// Etc.
mAppEvents1.Register();
DbEvents1 mDbEvents1 = new DbEvents1(); //Subscribe to all databases in the whole AutoCAD session.
DocEvents1 mDocEvents1 = new DocEvents1(); //Subscribe to all documents in the whole AutoCAD session.
mDocumentCollectionEvents1.Register();
mDynamicLinkerEvents1.Register();
mLayoutManagerEvents1.Register();
mPublisherEvents1.Register();
}
public void Terminate()
{
//TODO: add code to clean up things when the ExtApp terminates. For example:
// Closing the log files;
// Deleting the custom ribbon tabs/panels/buttons;
// Unloading those dependents;
// Un-subscribing to those events;
// Etc.
mAppEvents1.UnRegister();
mDocumentCollectionEvents1.UnRegister();
mDynamicLinkerEvents1.UnRegister();
mLayoutManagerEvents1.UnRegister();
mPublisherEvents1.UnRegister();
}
#endregion
AppEvents1 mAppEvents1 = new AppEvents1();
DocumentCollectionEvents1 mDocumentCollectionEvents1 = new DocumentCollectionEvents1();
DynamicLinkerEvents1 mDynamicLinkerEvents1 = new DynamicLinkerEvents1();
LayoutManagerEvents1 mLayoutManagerEvents1 = new LayoutManagerEvents1();
PublisherEvents1 mPublisherEvents1 = new PublisherEvents1();
}
}
The leading edge AutoCAD .NET Addin Wizard (AcadNetAddinWizard) has provided many nice Event Wizards to auto-generate start code of even handlers and registers flexibly in no time. People can expect more and cooler wizards, coders, and widgets in the near future.
Recent Comments