Running an Autolisp routine from VBA

Running an Autolisp routine from VBA

Anonymous
Not applicable
195 Views
3 Replies
Message 1 of 4

Running an Autolisp routine from VBA

Anonymous
Not applicable
Can anyone help...

Is it possible to execute an Autolisp routine from with a VBA module

if so... how??!

Many TIA

John
0 Likes
196 Views
3 Replies
Replies (3)
Message 1 of 4

Anonymous
Not applicable
Can anyone help...

Is it possible to execute an Autolisp routine from with a VBA module

if so... how??!

Many TIA

John
0 Likes
Message 3 of 4

Anonymous
Not applicable
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
0 Likes
Message 4 of 4

Anonymous
Not applicable
John,
I use the following: (The only assumption is that the path to the lisp must
be in your preferences files path).
This is a rather simple way to do the same thing as typing (load
"mylisproutine"), enter, and then typing the lisp routine name. The "~" is a
return. I use this method to allow our users to browse a tabbed form
containing all our lisps and save their selections to a personalized list.
The {} tell VBA that I want literally what is inside them.

Private Sub runlisp()
mylisp = typelisp.Text (typed (or selected) text in a textbox)
temp = """" (gives the double quotes needed in AutoCAD load statement)
SendKeys "{(}load " & temp & mylisp & temp & "{)}~" (sends the load
statement and lisp name to the command line)
SendKeys mylisp & "~" (sends the lisp name and a retrun to the command
line)
End Sub
--
Bud Miller
VBA/Office/Survey
http://www.BudCAD.com

John Walker wrote in message
news:memo.19991101130731.36437D@jwp.compulink.co.uk...
> Can anyone help...
>
> Is it possible to execute an Autolisp routine from with a VBA module
>
> if so... how??!
>
> Many TIA
>
> John
0 Likes