John,
It's definitely possible. There are several different methods:
1) In A2k you can use sendcommand or if you want a little more
versatility you can use the module below.
2) In R14 you can use acadunsupp.arx or the module below.
If you choose the module below, you need to be aware that third party
softwares which change the drawing caption will interfere.
syntax for use: ACAD "mycommand " & myvariable & "mynextcommand " ,ect.
-Josh
Option Explicit 'require
variable declarations
Option Compare Text 'so
comparisions are not case-sensitive
'----Win32 API
constants---------------------------------------------------------------------------
Public Const WM_COPYDATA = &H4A
'----Win32 API data
types--------------------------------------------------------------------------
Type CopyStringDataStruct
dwData As Long
cbData As Long
lpData As String
End Type
'----Win32 API function
declarations---------------------------------------------------------------
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal
lpClassName As String, _
ByVal lpWindowName As String) As Long
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal
hWnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, lParam As
Any) As Long
'----SendACADCommand-------------------------------------------------------------------------------
' This routine issues an AutoCAD command via the Win32 API
'SendMessage' function. If the command
' includes control characters (usually a control-c to cancel any
pending command) then include a
' '^' followed by the character, eg. ^c for control-c. Please note: It
appears that the command
' string must be less than about 320 characters. If your VBA routine
issues a series of commands
' then the total length of all command strings must be under this
limit.
'--------------------------------------------------------------------------------------------------
Public Sub ACAD(Cmd As String)
Dim n As Integer, ch As String, Cmd2 As String
Dim WinMsg As CopyStringDataStruct 'holds command
to send to AutoCAD
Dim hWnd As Long 'AutoCAD's
window handle
'----go through string looking for control
characters--------------------------------------------
Cmd2 = "" 'initialize
command string to build up
For n = 1 To Len(Cmd) 'check each
character
ch = Mid$(Cmd, n, 1) 'extract
character from string
If ch = "^" Then 'does it
signal a control-character?
n = n + 1 'advance to
next character
If n <= Len(Cmd) Then 'ensure
there's at least one more char
ch = StrConv(Mid$(Cmd, n, 1), vbUpperCase) 'extract
character to convert
ch = Chr$(Asc(ch) - 64) 'make it into
matching control-character
Else 'if string
ended with a '^' then...
ch = "" '...ignore it
End If
End If
Cmd2 = Cmd2 & ch 'append
character to new command string
Next n
'----send command to AutoCAD command
line--------------------------------------------------------
If Cmd2 <> "" Then 'make sure
there's a command to send
Cmd2 = Cmd2 & vbNullChar 'make it a
valid C-type string
hWnd = FindWindow(vbNullString, ThisDrawing.Application.Caption)
'get ACAD's window handle
If hWnd <> 0 Then 'make sure
found a valid handle
WinMsg.dwData = CLng(1) 'fill in
Window message
WinMsg.cbData = Len(Cmd2) + 1
WinMsg.lpData = Cmd2
SendMessage hWnd, WM_COPYDATA, hWnd, WinMsg 'send message
(command) to AutoCAD
Else
MsgBox "Could Not Find AutoCAD Window."
End If
End If
End Sub
John Walker wrote:
> Can anyone help...
>
> Is it possible to execute an Autolisp routine from with a VBA module
>
> if so... how??!
>
> Many TIA
>
> John