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 Application 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 AppEvents1
{
bool mSuppressMsgOutput = false;
void OptionalMessageOutput(EventArgs obj, string eventName)
{
if (!mSuppressMsgOutput)
{
string msg = string.Format("Info about the {0} event:{1}", eventName, Environment.NewLine);
PropertyInfo[] piArr = obj.GetType().GetProperties();
foreach (PropertyInfo pi in piArr)
{
string attValue = pi.GetValue(obj, null).ToString();
msg += string.Format("\t{0}: {1}{2}", pi.Name, attValue, Environment.NewLine);
}
MessageBox.Show(msg, "Event: " + eventName, MessageBoxButtons.OK, MessageBoxIcon.Information);
System.Diagnostics.Debug.Write(msg);
}
}
public void Register()
{
AcadApplication.SystemVariableChanging += AppEvent_SystemVariableChanging_Handler;
AcadApplication.SystemVariableChanged += AppEvent_SystemVariableChanged_Handler;
AcadApplication.QuitWillStart += AppEvent_QuitWillStart_Handler;
AcadApplication.QuitAborted += AppEvent_QuitAborted_Handler;
AcadApplication.PreTranslateMessage += AppEvent_PreTranslateMessage_Handler;
AcadApplication.LeaveModal += AppEvent_LeaveModal_Handler;
AcadApplication.Idle += AppEvent_Idle_Handler;
AcadApplication.EnterModal += AppEvent_EnterModal_Handler;
AcadApplication.DisplayingOptionDialog += AppEvent_DisplayingOptionDialog_Handler;
AcadApplication.DisplayingDraftingSettingsDialog += AppEvent_DisplayingDraftingSettingsDialog_Handler;
AcadApplication.DisplayingCustomizeDialog += AppEvent_DisplayingCustomizeDialog_Handler;
AcadApplication.BeginQuit += AppEvent_BeginQuit_Handler;
}
public void UnRegister()
{
AcadApplication.SystemVariableChanging -= AppEvent_SystemVariableChanging_Handler;
AcadApplication.SystemVariableChanged -= AppEvent_SystemVariableChanged_Handler;
AcadApplication.QuitWillStart -= AppEvent_QuitWillStart_Handler;
AcadApplication.QuitAborted -= AppEvent_QuitAborted_Handler;
AcadApplication.PreTranslateMessage -= AppEvent_PreTranslateMessage_Handler;
AcadApplication.LeaveModal -= AppEvent_LeaveModal_Handler;
AcadApplication.Idle -= AppEvent_Idle_Handler;
AcadApplication.EnterModal -= AppEvent_EnterModal_Handler;
AcadApplication.DisplayingOptionDialog -= AppEvent_DisplayingOptionDialog_Handler;
AcadApplication.DisplayingDraftingSettingsDialog -= AppEvent_DisplayingDraftingSettingsDialog_Handler;
AcadApplication.DisplayingCustomizeDialog -= AppEvent_DisplayingCustomizeDialog_Handler;
AcadApplication.BeginQuit -= AppEvent_BeginQuit_Handler;
}
public void AppEvent_BeginQuit_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "BeginQuit");
}
public void AppEvent_DisplayingCustomizeDialog_Handler(object sender, TabbedDialogEventArgs e)
{
OptionalMessageOutput(e, "DisplayingCustomizeDialog");
}
public void AppEvent_DisplayingDraftingSettingsDialog_Handler(object sender, TabbedDialogEventArgs e)
{
OptionalMessageOutput(e, "DisplayingDraftingSettingsDialog");
}
public void AppEvent_DisplayingOptionDialog_Handler(object sender, TabbedDialogEventArgs e)
{
OptionalMessageOutput(e, "DisplayingOptionDialog");
}
public void AppEvent_EnterModal_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "EnterModal");
}
public void AppEvent_Idle_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "Idle");
}
public void AppEvent_LeaveModal_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "LeaveModal");
}
public void AppEvent_PreTranslateMessage_Handler(object sender, PreTranslateMessageEventArgs e)
{
OptionalMessageOutput(e, "PreTranslateMessage");
}
public void AppEvent_QuitAborted_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "QuitAborted");
}
public void AppEvent_QuitWillStart_Handler(object sender, EventArgs e)
{
OptionalMessageOutput(e, "QuitWillStart");
}
public void AppEvent_SystemVariableChanged_Handler(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangedEventArgs e)
{
OptionalMessageOutput(e, "SystemVariableChanged");
}
public void AppEvent_SystemVariableChanging_Handler(object sender, Autodesk.AutoCAD.ApplicationServices.SystemVariableChangingEventArgs e)
{
OptionalMessageOutput(e, "SystemVariableChanging");
}
}
}
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();
}
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();
}
#endregion
AppEvents1 mAppEvents1 = new AppEvents1();
}
}
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.
Very useful information in this article! its really useful in
asp.net web development services
Posted by: janu3vj | 10/05/2016 at 08:02 AM
Thanks for liking it.
Posted by: Spiderinnet1 | 10/17/2016 at 06:03 AM