CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ActiveX 开发指南

关于启用对象级别事件 (VBA/ActiveX)

2023-1-4 21:22| 发布者: admin| 查看: 542| 评论: 0|来自: AutoCAD

摘要: 在使用对象级事件之前,必须创建一个新的类模块,并使用事件声明一个 AcadObject 类型的对象。

在使用对象级事件之前,必须创建一个新的类模块并声明一个 typewith 事件的对象。AcadObject

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

每当更新折线时,显示闭合折线的区域

本示例创建一条包含事件的轻量级折线。然后,每当更改折线时,折线的事件处理程序都会显示新区域。要触发事件,只需在AutoCAD中更改折线的大小。请记住,必须在激活事件处理程序之前运行子例程。CreatePLineWithEvents

Public WithEvents PLine As AcadLWPolyline

Sub CreatePLineWithEvents()
 ' This example creates a light weight polyline
 Dim points(0 To 9) As Double
 points(0) = 1: points(1) = 1
 points(2) = 1: points(3) = 2
 points(4) = 2: points(5) = 2
 points(6) = 3: points(7) = 3
 points(8) = 3: points(9) = 2
 Set PLine = ThisDrawing.ModelSpace. _
 AddLightWeightPolyline(points)
 PLine.Closed = True
 ThisDrawing.Application.ZoomAll
End Sub

Private Sub PLine_Modified _
 (ByVal pObject As AutoCAD.IAcadObject)
 ' This event is triggered when the polyline is resized.
 ' If the polyline is deleted the modified event is still
 ' triggered, so we use the error handler to avoid
 ' reading data from a deleted object.
 On Error GoTo ERRORHANDLER
 MsgBox "The area of " & pObject.ObjectName & " is: " _
 & pObject.Area
 Exit Sub

ERRORHANDLER:
 MsgBox Err.Description
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

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

GMT+8, 2024-5-12 04:18

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部