Eventcode on Document-Level
Hallo everybody !We recently tranfered a comprehenesive vba.application (.dvb) for HVAC-purposes to Bricscad.This workes quite well except the enclosed code will not work in Briscad.We want to use the "BeginnCommand" and "EndCommand" structure in the ThisDrawing-Levelto activate certain Layers and Subroutines: Option Explicit Dim aktLayer As String Dim NeuerLayer As AcadLayer 'Schaltet bei ACAD-Befehl "xLine" (Hilfslinie) auf Layer "FC-S-Hilfslinie" um. '---------------------------------------------------------------------------- Private Sub AcadDocument_BeginCommand(ByVal Commandname As String) On Error GoTo Zeile1 '...wenn Layer "FC-S-Hilfslinie" fehlt Select Case Commandname Case "XLINE" Let aktLayer = ThisDrawing.ActiveLayer.Name ThisDrawing.ActiveLayer = ThisDrawing.Layers("FC-S-Hilfslinie") End Select Exit SubZeile1: '...Layer"Zng-Hilfslinie" anlegen: Set NeuerLayer = ThisDrawing.Layers.Add("FC-S-Hilfslinie") NeuerLayer.Lineweight = acLnWt005 NeuerLayer.color = 253 ThisDrawing.ActiveLayer = ThisDrawing.Layers("FC-S-Hilfslinie") End Sub '1.)Schaltet bei Beendigung von "xLine" wieder zum vorherigen Layer zurück. '2.)Aktiviert bei Beendigung von "vbaload" die Init-Routine. '----------------------------------------------------------------------- Private Sub AcadDocument_EndCommand(ByVal Commandname As String) Select Case Commandname Case "XLINE" ThisDrawing.ActiveLayer = ThisDrawing.Layers(aktLayer) Case "VBALOAD" Call Init '...setzt Initialwerte zB.für Maßstab=1:50 End Select End SubCan anybody help ? best regards Peter Schriebl
Comments
-
The problem is that AcadDocument is not initialized. On AutoCAD's VBA this happens automatically. Currently on Bricscad you still need to initialize it yourself....You can compare 'AcadDocument' to 'ThisDrawing'. ThisDrawing always points to the active drawing; it is available in VBA (both on Bricscad and on AutoCAD); you do not need to declare or intialize it - the VBA enviroment provides a ThisDrawing reference for you. Outside VBA, say in VB6.0 or VB.NET, you would have to declare AND initialize a ThisDrawing object before you could use it.Unlike on AutoCAD's VBA where AcadDocument is automatically available, in Bricscad's VBA you need to declare a document object withevents and initialize it. Once that has been done your code will catch the document events (BeginCommand and EndCommand in your code)Public WithEvents oDocEvents As AcadDocument...Set oDocEvents = ThisDrawing.Application.ActiveDocument...Private Sub oDocEvents_BeginCommand(ByVal Commandname As String)End SubPrivate Sub oDocEvents_EndCommand(ByVal Commandname As String)End Sub
0