using System;
using System.Collections.Generic;
using System.Text;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Iesi.Collections.Generic;
using System.Threading;
//[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]
[assembly: ExtensionApplication(typeof(GateConnectionAnalyzer.MainEntry))]
[assembly: CommandClass(typeof(GateConnectionAnalyzer.MainEntry))]
namespace GateConnectionAnalyzer
{
public class MainEntry
: Autodesk.AutoCAD.Runtime.IExtensionApplication
{
private bool initialized = false;
public void Initialize()
{
//setup event handlers for application
AppSessionData.readConfigSettings();
NHibernateUtil.buildSessionFactory(true);
Application.DocumentManager.DocumentToBeDestroyed += new DocumentCollectionEventHandler
(DocumentManager_DocumentToBeDestroyed);
Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
}
[CommandMethod("drtest", CommandFlags.Session)]
public void begin()
{
FileSelectorForm fsf = new FileSelectorForm();
fsf.Show();
}
[CommandMethod("iembed")]
public void insertField()
{
BlockForm bf = new BlockForm();
bf.Show();
}
[CommandMethod("drupdb", CommandFlags.Session)]
public void runUpdateMethod()
{
BlockEvents.updateDb2();
}
internal void DocumentManager_DocumentToBeDestroyed(object sender, DocumentCollectionEventArgs e)
{
if (initialized)
{
Document doc = e.Document;
doc.Database.ObjectErased -= new ObjectErasedEventHandler(BlockEvents.Database_ObjectErased);
doc.CommandWillStart -= new CommandEventHandler(BlockEvents.doc_CommandBegin);
doc.CommandCancelled -= new CommandEventHandler(BlockEvents.doc_CommandEnded);
doc.CommandEnded -= new CommandEventHandler(BlockEvents.doc_CommandEnded);
}
}
internal void DocumentManager_DocumentCreated(object sender, DocumentCollectionEventArgs e)
{
e.Document.CommandWillStart +=new CommandEventHandler(BlockEvents.doc_CommandBegin);
e.Document.CommandCancelled +=new CommandEventHandler(BlockEvents.doc_CommandEnded);
e.Document.CommandEnded += new CommandEventHandler(BlockEvents.doc_CommandEnded);
initialized = true;
}
public void Terminate()
{
}
}
}
Norman Yuan
This is very useful for me, also an artical on http://tson.com/net-autocad-commands-regist/