请教如何使自定义的选择事件在所有文档中有效
本帖最后由 cheng5276 于 2014-12-2 18:21 编辑编译后的DLL通过注册表加入了CAD自启动
Windows Registry Editor Version 5.00
"LOADER"="C:\工具包\LAND.dll"
"MANAGED"=dword:0001c101
"LOADCTRLS"=dword:0001c102
启动CAD时自动初始化
public void Initialize()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
acDoc.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged); //设定自定义选择事件
}
问题出在这个初始化只在CAD启动时执行一次,后续开图,都未执行,所以当新开图后,这个选择事件也就失效了,
请教如何能让这个 选择事件对所有及后续新建的Document都有效?
恭请各位老大们指点
恭请老大现身....... 本帖最后由 sieben 于 2014-12-4 13:48 编辑
public void Initialize()
{
aApp.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
aApp.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentActivated);
} using aApp = Autodesk.AutoCAD.ApplicationServices.Application; 本帖最后由 cheng5276 于 2014-12-4 15:10 编辑
谢谢老大,不过好像不管用,鉴于我对老大的指点出现了2种理解,均未成功,恭请继续指点.....
理解一:(依然只是在新建文件时只执行了一次)
using Autodesk.AutoCAD.Runtime;
using System;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Document = Autodesk.AutoCAD.ApplicationServices.Document;
namespace ClassLibrary1
{
public class Main : IExtensionApplication
{
Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
public void Initialize()
{
Application.DocumentManager.MdiActiveDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
ed.WriteMessage("\n+++初始化成功+++");
}
public void Terminate() { } //释放初始化,即CAD退出时才会执行
public void doc_ImpliedSelectionChanged(object sender, EventArgs e)
{
ed.WriteMessage("\n++选择模式++");
}
}
}
理解二 (只要新建或切换文档 立马致命错误)
using Autodesk.AutoCAD.Runtime;
using System;
using Application = Autodesk.AutoCAD.ApplicationServices.Application;
using Document = Autodesk.AutoCAD.ApplicationServices.Document;
using Autodesk.AutoCAD.ApplicationServices;
namespace ClassLibrary1
{
public class Main : IExtensionApplication
{
Autodesk.AutoCAD.EditorInput.Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
public void Initialize()
{
Application.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
Application.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentActivated);
Application.DocumentManager.MdiActiveDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
Application.DocumentManager.MdiActiveDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
ed.WriteMessage("\n+++初始化成功+++");
}
public void Terminate() { } //释放初始化,即CAD退出时才会执行
public void DocumentManager_DocumentCreated(object sender, EventArgs e)
{
Application.DocumentManager.MdiActiveDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
}
public void DocumentManager_DocumentActivated(object sender, EventArgs e)
{
Application.DocumentManager.MdiActiveDocument.ImpliedSelectionChanged += new EventHandler(doc_ImpliedSelectionChanged);
}
public void doc_ImpliedSelectionChanged(object sender, EventArgs e)
{
ed.WriteMessage("\n++选择模式++");
}
}
}
页:
[1]