Quickly written example:
Code:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using acApp = Autodesk.AutoCAD.ApplicationServices.Application;
[assembly: ExtensionApplication(typeof(Augi.Sample.Events.Save))]
namespace Augi.Sample.Events
{
public class Save : IExtensionApplication
{
public void Initialize()
{
DocumentCollection acDocs = acApp.DocumentManager;
Document doc = acDocs.MdiActiveDocument;
Editor ed = doc.Editor;
acDocs.DocumentCreated += OnDocumentCreated;
doc.CommandWillStart += OnCommandWillStart;
}
public void Terminate()
{
}
public void BowtiesAreCool(Document doc) //<-- Change this to something useful
{
doc.Editor.WriteMessage("\n** Bowties are cool ** \n");
}
void OnCommandWillStart(object sender, CommandEventArgs e)
{
string cmd = e.GlobalCommandName.ToUpper();
if (cmd.Contains("SAVE") || cmd.Contains("OPEN"))
BowtiesAreCool((Document)sender); //<-- Change this to something useful
}
void OnDocumentCreated(object sender, DocumentCollectionEventArgs e)
{
if (e.Document != null)
e.Document.CommandWillStart += OnCommandWillStart;
}
}
}