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 LayerStateManager 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 AcadNetAddinWizard_Namespace
{
public class LayerStateManagerEvents1
{
public void Register()
{
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeRestored += LayerStateManager_LayerStateToBeRestored_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeRenamed += LayerStateManager_LayerStateToBeRenamed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeDeleted += LayerStateManager_LayerStateToBeDeleted_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateRestored += LayerStateManager_LayerStateRestored_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateRenamed += LayerStateManager_LayerStateRenamed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateDeleted += LayerStateManager_LayerStateDeleted_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateCreated += LayerStateManager_LayerStateCreated_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateCompareFailed += LayerStateManager_LayerStateCompareFailed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateRestore += LayerStateManager_AbortLayerStateRestore_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateRename += LayerStateManager_AbortLayerStateRename_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateDelete += LayerStateManager_AbortLayerStateDelete_Handler;
}
public void UnRegister()
{
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeRestored -= LayerStateManager_LayerStateToBeRestored_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeRenamed -= LayerStateManager_LayerStateToBeRenamed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateToBeDeleted -= LayerStateManager_LayerStateToBeDeleted_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateRestored -= LayerStateManager_LayerStateRestored_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateRenamed -= LayerStateManager_LayerStateRenamed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateDeleted -= LayerStateManager_LayerStateDeleted_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateCreated -= LayerStateManager_LayerStateCreated_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.LayerStateCompareFailed -= LayerStateManager_LayerStateCompareFailed_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateRestore -= LayerStateManager_AbortLayerStateRestore_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateRename -= LayerStateManager_AbortLayerStateRename_Handler;
HostApplicationServices.WorkingDatabase.LayerStateManager.AbortLayerStateDelete -= LayerStateManager_AbortLayerStateDelete_Handler;
}
public void LayerStateManager_AbortLayerStateDelete_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAbortLayerStateDelete\n");
}
public void LayerStateManager_AbortLayerStateRename_Handler(object sender, LayerStateRenameEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAbortLayerStateRename\n");
}
public void LayerStateManager_AbortLayerStateRestore_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nAbortLayerStateRestore\n");
}
public void LayerStateManager_LayerStateCompareFailed_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateCompareFailed\n");
}
public void LayerStateManager_LayerStateCreated_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateCreated\n");
}
public void LayerStateManager_LayerStateDeleted_Handler(object sender, LayerStateDeletedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateDeleted\n");
}
public void LayerStateManager_LayerStateRenamed_Handler(object sender, LayerStateRenameEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateRenamed\n");
}
public void LayerStateManager_LayerStateRestored_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateRestored\n");
}
public void LayerStateManager_LayerStateToBeDeleted_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateToBeDeleted\n");
}
public void LayerStateManager_LayerStateToBeRenamed_Handler(object sender, LayerStateRenameEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateToBeRenamed\n");
}
public void LayerStateManager_LayerStateToBeRestored_Handler(object sender, LayerStateEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLayerStateToBeRestored\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 AcadNetAddinWizard_Namespace
{
public class AcadNetAddinWizard_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.
mBlockTableRecordEvents1.Register();
mEditorEvents1.Register();
mGraphicsManagerEvents1.Register();
mLayerStateManagerEvents1.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.
mBlockTableRecordEvents1.UnRegister();
mEditorEvents1.UnRegister();
mGraphicsManagerEvents1.UnRegister();
mLayerStateManagerEvents1.UnRegister();
}
#endregion
BlockTableRecordEvents1 mBlockTableRecordEvents1 = new BlockTableRecordEvents1();
EditorEvents1 mEditorEvents1 = new EditorEvents1();
GraphicsManagerEvents1 mGraphicsManagerEvents1 = new GraphicsManagerEvents1();
LayerStateManagerEvents1 mLayerStateManagerEvents1 = new LayerStateManagerEvents1();
}
}
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.
Posted by: |