Executing a command...

Executing a command...

Anonymous
Not applicable
203 Views
4 Replies
Message 1 of 5

Executing a command...

Anonymous
Not applicable
How do I execute an AutoCAD command in vba? I want to add a viewport button
to my form that simply hides the form and executes the command, then returns
the form.

thanks,
Doc
0 Likes
204 Views
4 Replies
Replies (4)
Message 2 of 5

Anonymous
Not applicable
Use the Document Objects SendCommand(strCommandString) method

Example from AutoCad Help:
ThisDrawing.SendCommand "_Circle" & vbCr & "2,2,0" & vbCr & "4" & vbCr

Jade Jacobsen wrote:

> How do I execute an AutoCAD command in vba? I want to add a viewport button
> to my form that simply hides the form and executes the command, then returns
> the form.
>
> thanks,
> Doc
0 Likes
Message 3 of 5

Anonymous
Not applicable
Depending on what your trying to do, You would be better off using the Viewport
Object if possible.

Jade Jacobsen wrote:

> How do I execute an AutoCAD command in vba? I want to add a viewport button
> to my form that simply hides the form and executes the command, then returns
> the form.
>
> thanks,
> Doc
0 Likes
Message 4 of 5

Anonymous
Not applicable
Can you give me some more information on what you want to do - like what
command and more about your application.

"Jade Jacobsen" wrote in message
news:F3B83B050ABB687B6BCBC710FD866C84@in.WebX.maYIadrTaRb...
How do I execute an AutoCAD command in vba? I want to add a viewport button
to my form that simply hides the form and executes the command, then returns
the form.

thanks,
Doc
0 Likes
Message 5 of 5

Anonymous
Not applicable
Hi Jade,
Sounds like a simple task, doesn't it? The truth is, in this case, it is,
but the code would differ depending on the version of AutoCAD that you are
working with. Let's say it's AutoCAD 2000, and your button is named
cmdVport:

Private Sub cmdVport_Click()
Me.Hide
ThisDrawing.SendCommand "VPORTS" & vbCr
Me.Show
End Sub

Will do it.
But, if you pass a command that doesn't initiate a dialog of it's own, the
form will show again, before the command has completed, leaving the user
unable to interact with the main AutoCAD window (the drawing) . For
instance, if you used this:

Private Sub cmdVport_Click()
Me.Hide
Call VPortIt
Me.Show
End Sub

Private Sub VPortIt()
ThisDrawing.SendCommand "-VPORTS" & vbCr
End Sub

You will not be able to interact with the drawing UNTIL you dismiss the user
form. There are several solutions for this problem, let me know if you find
that you need help with it!

If you are using R14, you will need to create a sendcommand function using
the Win32API..
Place this into a module (NOT a class module or user form)

Option Explicit

Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long

Public Declare Function FindWindow Lib _
"user32" Alias "FindWindowA" (ByVal _
lpClassName As String, ByVal lpWindowName _
As String) As Long

Public Const WM_COPYDATA = &H4A

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

Public Sub R14SendCommand(CommandString As String)
Dim udtData As COPYDATASTRUCTURE
Dim lngHwnd As Long
udtData.dwData = 1
udtData.lpData = CommandString
udtData.cbData = Len(CommandString) + 2
lngHwnd = FindWindow(vbNullString, Application.Caption)
SendMessage lngHwnd, WM_COPYDATA, 0, udtData
End Sub

Then you can use it very much like the code above:

Private Sub cmdVport_Click()
Me.Hide
R14SendCommand "VPORTS" & vbCr
Me.Show
End Sub

Randall Rath
VB Design
http://www.vbdesign.net/cadpages/tbox.htm
0 Likes