CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

AutoCAD 2025 开发者帮助

关于启用应用程序级事件 (VBA/ActiveX)

2024-5-18 19:19| 发布者: admin| 查看: 72| 评论: 0|原作者: admin|来自: AutoCAD

关于启用应用程序级事件 (VBA/ActiveX)

在使用应用程序级事件之前,必须创建一个新的类模块,并使用事件声明一个类型的对象。AcadApplication

例如,假定创建了一个新的类模块并命名为 EventClassModule。新的类模块包含使用 VBA 关键字的应用程序声明。WithEvents

将图形拖放到 AutoCAD 中时提示继续

本示例在将文件拖放到 AutoCAD 中时截获加载过程。一个消息框,其中包含删除的文件的名称和“是/否/继续”按钮,允许用户决定是否应继续加载或显示文件。如果用户选择取消操作,则通过事件的 Cancel 参数返回该决定,并且不会加载文件。BeginFileDrop

Public WithEvents ACADApp As AcadApplication

Sub Example_AcadApplication_Events()
 ' This example intializes the public variable (ACADApp)
 ' which will be used to intercept AcadApplication Events
 '
 ' Run this procedure FIRST!

 ' We could get the application from the ThisDocument
 ' object, but that would require having a drawing open,
 ' so we grab it from the system.
 Set ACADApp = GetObject(, "AutoCAD.Application.25.0")
End Sub

Private Sub ACADApp_BeginFileDrop _
 (ByVal FileName As String, Cancel As Boolean)
 ' This example intercepts an Application BeginFileDrop event.
 '
 ' This event is triggered when a drawing file is dragged
 ' into AutoCAD.
 '
 ' To trigger this example event:
 '     1) Make sure to run the example that initializes
 '     the public variable (named ACADApp) linked to this event.
 '
 '     2) Drag an AutoCAD drawing file into the AutoCAD
 '        application from either the Windows Desktop
 '        or File Explorer

 ' Use the "Cancel" variable to stop the loading of the
 ' dragged file, and the "FileName" variable to  notify
 ' the user which file is about to be dragged in.

 If MsgBox("AutoCAD is about to load " & FileName & vbCrLf _
 & "Do you want to continue loading this file?", _
 vbYesNoCancel + vbQuestion) <> vbYes Then
 Cancel = True
 End If
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1   苏公网安备32011402011833)

GMT+8, 2024-12-15 22:29

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部