VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FATAL ERROR - On open using SendCommand

0 REPLIES 0
Reply
Message 1 of 1
Profex13
549 Views, 0 Replies

FATAL ERROR - On open using SendCommand

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?

 

 

 

 

 

 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost