AutoCAD 2006 VBA a Programmer’s Reference

ADVERTISEMENT


 AutoCAD 2006 VBA a Programmer's Reference cover page
Application-Level Events Changes to the AutoCAD application environment result in application-level events. These include the opening and saving of drawings, running of AutoCAD commands, changes to system variables, and changes to the AutoCAD application window. Application-level events aren’t enabled when you load a VBA project. The following example illustrates the steps you need to take to enable application-level events. First, insert a new class module by selecting Insert ?Class Module, and name the new class module appropriately, for example clsApplicationEvents. Then declare an object of type AcadApplicationusing the WithEventskeyword. Public WithEvents objApp As AcadApplication…

You can do this as follows. In the ThisDrawingor any code module, declare a variable to be a new instance of the class module you just created, and in a subroutine set this variable to hold a reference to the Applicationobject. Option Explicit Public objApp As New cls Application Events Public Sub InitializeEvents () Set objApp.objApp = This Drawing.Application End Sub As soon as the Initialize Eventssubroutine is called, in this case by running the App_StartMacromacro shown next, the application-level events are enabled. Public Sub App_StartMacro() InitializeEvents End Sub The following examples illustrate writing code within the event procedures of the class module to execute when those events occur. The first informs the user when a system variable changes, and the second ensures that the AutoSaveinterval for a new drawing is always set to 30 minutes. Private Sub objApp_SysVarChanged(ByVal SysvarName As String, _ ByVal newVal As Variant) MsgBox “The System Variable: ” & SysvarName & ” has changed to ” & newVal End Sub Private Sub objApp_NewDrawing() ThisDrawing.SetVariable “SAVETIME”, 30 MsgBox “The autosave interval is currently set to 30 mins” End Sub…

Download AutoCAD 2006 VBA a Programmer’s Reference.pdf

Leave a Reply


Map: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67