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 LayoutManager 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 LayoutManagerEvents1
{
public void Register()
{
LayoutManager.Current.PlotStyleTableChanged += LayoutManagerEvent_PlotStyleTableChanged_Handler;
LayoutManager.Current.LayoutsReordered += LayoutManagerEvent_LayoutsReordered_Handler;
LayoutManager.Current.LayoutToBeRenamed += LayoutManagerEvent_LayoutToBeRenamed_Handler;
LayoutManager.Current.LayoutToBeRemoved += LayoutManagerEvent_LayoutToBeRemoved_Handler;
LayoutManager.Current.LayoutToBeCopied += LayoutManagerEvent_LayoutToBeCopied_Handler;
LayoutManager.Current.LayoutSwitched += LayoutManagerEvent_LayoutSwitched_Handler;
LayoutManager.Current.LayoutRenamed += LayoutManagerEvent_LayoutRenamed_Handler;
LayoutManager.Current.LayoutRemoved += LayoutManagerEvent_LayoutRemoved_Handler;
LayoutManager.Current.LayoutCreated += LayoutManagerEvent_LayoutCreated_Handler;
LayoutManager.Current.LayoutCopied += LayoutManagerEvent_LayoutCopied_Handler;
LayoutManager.Current.AbortLayoutRename += LayoutManagerEvent_AbortLayoutRename_Handler;
LayoutManager.Current.AbortLayoutRemoved += LayoutManagerEvent_AbortLayoutRemoved_Handler;
LayoutManager.Current.AbortLayoutCopied += LayoutManagerEvent_AbortLayoutCopied_Handler;
}
public void UnRegister()
{
LayoutManager.Current.PlotStyleTableChanged -= LayoutManagerEvent_PlotStyleTableChanged_Handler;
LayoutManager.Current.LayoutsReordered -= LayoutManagerEvent_LayoutsReordered_Handler;
LayoutManager.Current.LayoutToBeRenamed -= LayoutManagerEvent_LayoutToBeRenamed_Handler;
LayoutManager.Current.LayoutToBeRemoved -= LayoutManagerEvent_LayoutToBeRemoved_Handler;
LayoutManager.Current.LayoutToBeCopied -= LayoutManagerEvent_LayoutToBeCopied_Handler;
LayoutManager.Current.LayoutSwitched -= LayoutManagerEvent_LayoutSwitched_Handler;
LayoutManager.Current.LayoutRenamed -= LayoutManagerEvent_LayoutRenamed_Handler;
LayoutManager.Current.LayoutRemoved -= LayoutManagerEvent_LayoutRemoved_Handler;
LayoutManager.Current.LayoutCreated -= LayoutManagerEvent_LayoutCreated_Handler;
LayoutManager.Current.LayoutCopied -= LayoutManagerEvent_LayoutCopied_Handler;
LayoutManager.Current.AbortLayoutRename -= LayoutManagerEvent_AbortLayoutRename_Handler;
LayoutManager.Current.AbortLayoutRemoved -= LayoutManagerEvent_AbortLayoutRemoved_Handler;
LayoutManager.Current.AbortLayoutCopied -= LayoutManagerEvent_AbortLayoutCopied_Handler;
}
public void LayoutManagerEvent_AbortLayoutCopied_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nAbortLayoutCopied {0}\n", e.Name));
}
public void LayoutManagerEvent_AbortLayoutRemoved_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nAbortLayoutRemoved {0}\n", e.Name));
}
public void LayoutManagerEvent_AbortLayoutRename_Handler(object sender, LayoutRenamedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nAbortLayoutRename {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutCopied_Handler(object sender, LayoutCopiedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutCopied {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutCreated_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutCreated {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutRemoved_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutRemoved {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutRenamed_Handler(object sender, LayoutRenamedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutRenamed {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutSwitched_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutSwitched {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutToBeCopied_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutToBeCopied {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutToBeRemoved_Handler(object sender, Autodesk.AutoCAD.DatabaseServices.LayoutEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutToBeRemoved {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutToBeRenamed_Handler(object sender, LayoutRenamedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutToBeRenamed {0}\n", e.Name));
}
public void LayoutManagerEvent_LayoutsReordered_Handler(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nLayoutsReordered {0}\n", ""));
}
public void LayoutManagerEvent_PlotStyleTableChanged_Handler(object sender, PlotStyleTableChangedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage(string.Format("\nPlotStyleTableChanged {0}\n", e.NewName));
}
}
}
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();
}
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();
}
#endregion
AppEvents1 mAppEvents1 = new AppEvents1();
DocumentCollectionEvents1 mDocumentCollectionEvents1 = new DocumentCollectionEvents1();
DynamicLinkerEvents1 mDynamicLinkerEvents1 = new DynamicLinkerEvents1();
LayoutManagerEvents1 mLayoutManagerEvents1 = new LayoutManagerEvents1();
}
}
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