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 BlockTableRecord 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 BlockTableRecordEvents1
{
public void Register()
{
BlockTableRecord.BlockInsertionPoints += BlockTableRecord_BlockInsertionPoints_Handler;
}
public void UnRegister()
{
BlockTableRecord.BlockInsertionPoints -= BlockTableRecord_BlockInsertionPoints_Handler;
}
public void BlockTableRecord_BlockInsertionPoints_Handler(object sender, BlockInsertionPointsEventArgs e)
{
AcadApplication.DocumentManager.MdiActiveDocument.Editor.WriteMessage("\nBlockInsertionPoints\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();
}
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();
}
#endregion
BlockTableRecordEvents1 mBlockTableRecordEvents1 = new BlockTableRecordEvents1();
}
}
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