Active commandline while executing VBA code?

Active commandline while executing VBA code?

Anonymous
Not applicable
385 Views
2 Replies
Message 1 of 3

Active commandline while executing VBA code?

Anonymous
Not applicable
Is it possible to send and execute commands to the commandline
while executing VBA code? I have not been able to do this so far,
the commands are executed only after closing the VBA application.
I wonder if it is at all possible.
(Autocad R14)

TIA,

Frans
0 Likes
386 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
paste the following code into a module and then use the sendcmd procedure
using this syntax:

sendcmd "cmd" & vbcr, objAcad

be aware that commands to the commandline run asynchronous to other vba code

------------------------------------
look frank, i finally helped someone!
abe

Option Explicit
Option Compare Text 'so comparisions are not case-sensitive
'===========================================================================
=======================
' basWinMsg Last Revision: C.French
24/06/98
'---------------------------------------------------------------------------
-----------------------
' This module provides code to use the Win32 API 'SendMessage' function to
send commands to the
' AutoCAD command line.
'
' If you want to 'pause' while AutoCAD carries out your commands, your VBA
code must be divided
' up into a routine which executes before sending the commands and another
routine which will run
' after the commands are completed. As it's last action, the first routine
uses SendCmd
' to tell AutoCAD to run the second section. This second routine could send
more commands and
' specify a third VBA routine which will follow them, and so on.
'===========================================================================
=======================
Public Const WM_COPYDATA = &H4A

Type CopyStringDataStruct
dwData As Long
cbData As Long
lpData As String
End Type

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
'----SendCmd----------------------------------------------------------------
--------------- ' 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 SendCmd(Cmd As String, objAcad As Object)
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, objAcad.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 "didn't get a hwnd"
End If
End If
End Sub

Frans wrote in message news:[email protected]...
> Is it possible to send and execute commands to the commandline
> while executing VBA code? I have not been able to do this so far,
> the commands are executed only after closing the VBA application.
> I wonder if it is at all possible.
> (Autocad R14)
>
> TIA,
>
> Frans
>
0 Likes
Message 3 of 3

Anonymous
Not applicable
Hiya,

Sendcmd works ok, but the real problem is the VBARUN interface which does not release the command line.

There is a special ARX file called VBARUNEX.ARX which will allow you to use Thisdrawing.SendCommand and it
will work synchronously. I will try to attach the file here, if that doesnt work just let me know and I will email it to you.

Micah
0 Likes