乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 73|回复: 4

请教如何使自定义的选择事件在所有文档中有效

[复制链接]

32

主题

140

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
268
发表于 2014-12-2 17:48:00 | 显示全部楼层 |阅读模式
编译后的DLL通过注册表加入了CAD自启动
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Autodesk\\R18.0\ACAD-8001:804\Applications\包]
"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都有效?
恭请各位老大们指点
回复

使用道具 举报

32

主题

140

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
268
发表于 2014-12-4 13:12:00 | 显示全部楼层
恭请老大现身.......
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2014-12-4 13:46:00 | 显示全部楼层

    public void Initialize()
    {
        aApp.DocumentManager.DocumentCreated += new DocumentCollectionEventHandler(DocumentManager_DocumentCreated);
          aApp.DocumentManager.DocumentActivated += new DocumentCollectionEventHandler(DocumentManager_DocumentActivated);
    }
回复

使用道具 举报

32

主题

651

帖子

8

银币

中流砥柱

Rank: 25

铜币
779
发表于 2014-12-4 13:46:00 | 显示全部楼层
using aApp = Autodesk.AutoCAD.ApplicationServices.Application;
回复

使用道具 举报

32

主题

140

帖子

5

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
268
发表于 2014-12-4 14:46:00 | 显示全部楼层

谢谢老大,不过好像不管用,鉴于我对老大的指点出现了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++选择模式++");
        }
    }
}
理解二 (只要新建或切换文档 立马致命错误)

owg0fm1mrc0.jpg

owg0fm1mrc0.jpg


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++选择模式++");
        }
    }
}
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 18:35 , Processed in 0.717764 second(s), 65 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表