using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Runtime;
namespace doubleclick25
{
public class doubleclick
{
[CommandMethod("add")]
public void add()
{
Initialize();
Application.ShowAlertDialog("添加双击事件成功!");
}
static DocumentCollection dm = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
static int num = 0;
public void Initialize()
{
//初始化关联
dm.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
public void Terminate()
{
//终止关联
dm.DocumentLockModeChanged -= new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
private void dm_DocumentLockModeChanged(object sender, DocumentLockModeChangedEventArgs e)
{
dm.DocumentLockModeChanged -= new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
if (num == 2)
{
if (e.GlobalCommandName.ToUpper() == "PROPERTIES")
{
Editor ed = dm.MdiActiveDocument.Editor;
// PromptSelectionResult res = ed.GetSelection();
PromptSelectionResult res = ed.SelectImplied();
ObjectId[] objids = res.Value.GetObjectIds();
if (res.Status == PromptStatus.OK)
{
e.Veto();
Application.ShowAlertDialog("你双击了" + objids[objids.GetLength(0) - 1]);
}
num = 0;
}
}
else
num++;
dm.DocumentLockModeChanged += new DocumentLockModeChangedEventHandler(dm_DocumentLockModeChanged);
}
}
}