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 UserConfigurationManager 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 UserConfigurationManagerEvents1
{
public void Register()
{
AcadApplication.UserConfigurationManager.ProfileSaving += UserConfigManagerEvent_ProfileSaving_Handler;
AcadApplication.UserConfigurationManager.ProfileSaved += UserConfigManagerEvent_ProfileSaved_Handler;
AcadApplication.UserConfigurationManager.ProfileResetting += UserConfigManagerEvent_ProfileResetting_Handler;
AcadApplication.UserConfigurationManager.ProfileReset += UserConfigManagerEvent_ProfileReset_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileSaving += UserConfigManagerEvent_CurrentProfileSaving_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileSaved += UserConfigManagerEvent_CurrentProfileSaved_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileResetting += UserConfigManagerEvent_CurrentProfileResetting_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileReset += UserConfigManagerEvent_CurrentProfileReset_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileChanging += UserConfigManagerEvent_CurrentProfileChanging_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileChanged += UserConfigManagerEvent_CurrentProfileChanged_Handler;
}
public void UnRegister()
{
AcadApplication.UserConfigurationManager.ProfileSaving -= UserConfigManagerEvent_ProfileSaving_Handler;
AcadApplication.UserConfigurationManager.ProfileSaved -= UserConfigManagerEvent_ProfileSaved_Handler;
AcadApplication.UserConfigurationManager.ProfileResetting -= UserConfigManagerEvent_ProfileResetting_Handler;
AcadApplication.UserConfigurationManager.ProfileReset -= UserConfigManagerEvent_ProfileReset_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileSaving -= UserConfigManagerEvent_CurrentProfileSaving_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileSaved -= UserConfigManagerEvent_CurrentProfileSaved_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileResetting -= UserConfigManagerEvent_CurrentProfileResetting_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileReset -= UserConfigManagerEvent_CurrentProfileReset_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileChanging -= UserConfigManagerEvent_CurrentProfileChanging_Handler;
AcadApplication.UserConfigurationManager.CurrentProfileChanged -= UserConfigManagerEvent_CurrentProfileChanged_Handler;
}
public void UserConfigManagerEvent_CurrentProfileChanged_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileChanged {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_CurrentProfileChanging_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileChanging {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_CurrentProfileReset_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileReset {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_CurrentProfileResetting_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileResetting {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_CurrentProfileSaved_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileSaved {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_CurrentProfileSaving_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nCurrentProfileSaving {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_ProfileReset_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nProfileReset {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_ProfileResetting_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nProfileResetting {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_ProfileSaved_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nProfileSaved {0}\n", e.ProfileName));
}
public void UserConfigManagerEvent_ProfileSaving_Handler(object sender, ProfileEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nProfileSaving {0}\n", e.ProfileName));
}
}
}
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();
mUserConfigurationManagerEvents1.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();
mUserConfigurationManagerEvents1.UnRegister();
}
#endregion
AppEvents1 mAppEvents1 = new AppEvents1();
DocumentCollectionEvents1 mDocumentCollectionEvents1 = new DocumentCollectionEvents1();
DynamicLinkerEvents1 mDynamicLinkerEvents1 = new DynamicLinkerEvents1();
LayoutManagerEvents1 mLayoutManagerEvents1 = new LayoutManagerEvents1();
PublisherEvents1 mPublisherEvents1 = new PublisherEvents1();
UserConfigurationManagerEvents1 mUserConfigurationManagerEvents1 = new UserConfigurationManagerEvents1();
}
}
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