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 Editor 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 EditorEvents1
{
public void Register()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.SelectionRemoved += EditorEvent_SelectionRemoved_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.SelectionAdded += EditorEvent_SelectionAdded_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.Rollover += EditorEvent_Rollover_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForString += EditorEvent_PromptingForString_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForSelection += EditorEvent_PromptingForSelection_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForPoint += EditorEvent_PromptingForPoint_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForNestedEntity += EditorEvent_PromptingForNestedEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForKeyword += EditorEvent_PromptingForKeyword_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForInteger += EditorEvent_PromptingForInteger_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForEntity += EditorEvent_PromptingForEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForDouble += EditorEvent_PromptingForDouble_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForDistance += EditorEvent_PromptingForDistance_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForCorner += EditorEvent_PromptingForCorner_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForAngle += EditorEvent_PromptingForAngle_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForString += EditorEvent_PromptedForString_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForSelection += EditorEvent_PromptedForSelection_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForPoint += EditorEvent_PromptedForPoint_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForNestedEntity += EditorEvent_PromptedForNestedEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForKeyword += EditorEvent_PromptedForKeyword_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForInteger += EditorEvent_PromptedForInteger_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForEntity += EditorEvent_PromptedForEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForDouble += EditorEvent_PromptedForDouble_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForDistance += EditorEvent_PromptedForDistance_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForCorner += EditorEvent_PromptedForCorner_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForAngle += EditorEvent_PromptedForAngle_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptForSelectionEnding += EditorEvent_PromptForSelectionEnding_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptForEntityEnding += EditorEvent_PromptForEntityEnding_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PointMonitor += EditorEvent_PointMonitor_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PointFilter += EditorEvent_PointFilter_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.LeavingQuiescentState += EditorEvent_LeavingQuiescentState_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.EnteringQuiescentState += EditorEvent_EnteringQuiescentState_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.DraggingEnded += EditorEvent_DraggingEnded_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.Dragging += EditorEvent_Dragging_Handler;
}
public void UnRegister()
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.SelectionRemoved -= EditorEvent_SelectionRemoved_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.SelectionAdded -= EditorEvent_SelectionAdded_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.Rollover -= EditorEvent_Rollover_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForString -= EditorEvent_PromptingForString_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForSelection -= EditorEvent_PromptingForSelection_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForPoint -= EditorEvent_PromptingForPoint_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForNestedEntity -= EditorEvent_PromptingForNestedEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForKeyword -= EditorEvent_PromptingForKeyword_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForInteger -= EditorEvent_PromptingForInteger_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForEntity -= EditorEvent_PromptingForEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForDouble -= EditorEvent_PromptingForDouble_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForDistance -= EditorEvent_PromptingForDistance_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForCorner -= EditorEvent_PromptingForCorner_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptingForAngle -= EditorEvent_PromptingForAngle_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForString -= EditorEvent_PromptedForString_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForSelection -= EditorEvent_PromptedForSelection_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForPoint -= EditorEvent_PromptedForPoint_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForNestedEntity -= EditorEvent_PromptedForNestedEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForKeyword -= EditorEvent_PromptedForKeyword_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForInteger -= EditorEvent_PromptedForInteger_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForEntity -= EditorEvent_PromptedForEntity_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForDouble -= EditorEvent_PromptedForDouble_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForDistance -= EditorEvent_PromptedForDistance_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForCorner -= EditorEvent_PromptedForCorner_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptedForAngle -= EditorEvent_PromptedForAngle_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptForSelectionEnding -= EditorEvent_PromptForSelectionEnding_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PromptForEntityEnding -= EditorEvent_PromptForEntityEnding_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PointMonitor -= EditorEvent_PointMonitor_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.PointFilter -= EditorEvent_PointFilter_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.LeavingQuiescentState -= EditorEvent_LeavingQuiescentState_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.EnteringQuiescentState -= EditorEvent_EnteringQuiescentState_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.DraggingEnded -= EditorEvent_DraggingEnded_Handler;
AcadApplication.DocumentManager.MdiActiveDocument.Editor.Dragging -= EditorEvent_Dragging_Handler;
}
public void EditorEvent_Dragging_Handler(object sender, DraggingEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDragging\n");
}
public void EditorEvent_DraggingEnded_Handler(object sender, DraggingEndedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nDraggingEnded\n");
}
public void EditorEvent_EnteringQuiescentState_Handler(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nEnteringQuiescentState\n");
}
public void EditorEvent_LeavingQuiescentState_Handler(object sender, EventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nLeavingQuiescentState\n");
}
public void EditorEvent_PointFilter_Handler(object sender, PointFilterEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPointFilter\n");
}
public void EditorEvent_PointMonitor_Handler(object sender, PointMonitorEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPointMonitor\n");
}
public void EditorEvent_PromptForEntityEnding_Handler(object sender, PromptForEntityEndingEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptForEntityEnding\n");
}
public void EditorEvent_PromptForSelectionEnding_Handler(object sender, PromptForSelectionEndingEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptForSelectionEnding\n");
}
public void EditorEvent_PromptedForAngle_Handler(object sender, PromptDoubleResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForAngle\n");
}
public void EditorEvent_PromptedForCorner_Handler(object sender, PromptPointResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForCorner\n");
}
public void EditorEvent_PromptedForDistance_Handler(object sender, PromptDoubleResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForDistance\n");
}
public void EditorEvent_PromptedForDouble_Handler(object sender, PromptDoubleResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForDouble\n");
}
public void EditorEvent_PromptedForEntity_Handler(object sender, PromptEntityResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForEntity\n");
}
public void EditorEvent_PromptedForInteger_Handler(object sender, PromptIntegerResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForInteger\n");
}
public void EditorEvent_PromptedForKeyword_Handler(object sender, PromptStringResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForKeyword\n");
}
public void EditorEvent_PromptedForNestedEntity_Handler(object sender, PromptNestedEntityResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForNestedEntity\n");
}
public void EditorEvent_PromptedForPoint_Handler(object sender, PromptPointResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForPoint\n");
}
public void EditorEvent_PromptedForSelection_Handler(object sender, PromptSelectionResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForSelection\n");
}
public void EditorEvent_PromptedForString_Handler(object sender, PromptStringResultEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptedForString\n");
}
public void EditorEvent_PromptingForAngle_Handler(object sender, PromptAngleOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForAngle\n");
}
public void EditorEvent_PromptingForCorner_Handler(object sender, PromptPointOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForCorner\n");
}
public void EditorEvent_PromptingForDistance_Handler(object sender, PromptDistanceOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForDistance\n");
}
public void EditorEvent_PromptingForDouble_Handler(object sender, PromptDoubleOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForDouble\n");
}
public void EditorEvent_PromptingForEntity_Handler(object sender, PromptEntityOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForEntity\n");
}
public void EditorEvent_PromptingForInteger_Handler(object sender, PromptIntegerOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForInteger\n");
}
public void EditorEvent_PromptingForKeyword_Handler(object sender, PromptKeywordOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForKeyword\n");
}
public void EditorEvent_PromptingForNestedEntity_Handler(object sender, PromptNestedEntityOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForNestedEntity\n");
}
public void EditorEvent_PromptingForPoint_Handler(object sender, PromptPointOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForPoint\n");
}
public void EditorEvent_PromptingForSelection_Handler(object sender, PromptSelectionOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForSelection\n");
}
public void EditorEvent_PromptingForString_Handler(object sender, PromptStringOptionsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nPromptingForString\n");
}
public void EditorEvent_Rollover_Handler(object sender, RolloverEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nRollover\n");
}
public void EditorEvent_SelectionAdded_Handler(object sender, SelectionAddedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSelectionAdded\n");
}
public void EditorEvent_SelectionRemoved_Handler(object sender, SelectionRemovedEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nSelectionRemoved\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();
}
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();
}
#endregion
BlockTableRecordEvents1 mBlockTableRecordEvents1 = new BlockTableRecordEvents1();
EditorEvents1 mEditorEvents1 = new EditorEvents1();
}
}
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