I get a FATAL ERROR everytime I open a new file using multi-document interface (SDI = 0) in AutoCAD 2000i/2008/2010/2013 on Windows XP / Windows 7(x64) running my code. It always breaks on ThisDrawing.SendCommand (also ThisDrawing.SetVariable "CMDECHO", 0 doesn't work either). I thought that it used to work, but maybe I never had it in MDI mode. Basically I'm trying to define some lisp commands, which call VBA routines, when a new file opens up (instead of hardcoding them into a .lsp file, since I have a number of different files)
In ACAD.DVB I have the following code:
Private acApp As clsAppEvents Sub ACADStartup() ACADApp_Initialize ACADLoadMenus End Sub Sub ACADApp_Initialize() If acApp Is Nothing _ Then Set acApp = New clsAppEvents Set acApp.App = ThisDrawing.Application End If End Sub
And the clsAppEvents class that has the following code:
Public WithEvents App As AcadApplication Private Sub App_NewDrawing() ACADLoadMenus End Sub
ACADLoadMenus is also in the ACAD.DVB file and looks something like this:
Sub ACADLoadMenus() Dim strName As String, strFunction As String '. '. strName = "acad2XL.dvb" strFunction = "modMenu.LoadMyMenu" '. Call ThisDrawing.Application.LoadDVB(strName) Call ThisDrawing.Application.RunMacro(strFunction) '. End Sub
And so in the acad2XL.dvb file, I have the following code:
Public Sub LoadMyMenu() 'Call LoadMenu("bwaAutomation", "&ACAD2XL", "&Convert Table 2 Excel", "ACAD2XL.AcadBomtoExcel.ac2xl")
' Error on next line: ThisDrawing.SetVariable "CMDECHO", 0
' FATAL ERROR on following line:
ThisDrawing.SendCommand ("(defun c:acad2xl ()(vl-vbarun ""ac2xl""))" & vbCr) ThisDrawing.SetVariable "CMDECHO", 1 End Sub
The code works fine on first open and if I run it manually.
The error only happens when SDI is set to 0, and try to open a second file.
Am I calling the SendCommand too soon? Anyone know how to solve this?