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

Executing a command...

4 REPLIES 4
Reply
Message 1 of 5
Anonymous
145 Views, 4 Replies

Executing a command...

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
4 REPLIES 4
Message 2 of 5
Anonymous
in reply to: Anonymous

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
Message 3 of 5
Anonymous
in reply to: Anonymous

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
Message 4 of 5
Anonymous
in reply to: Anonymous

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
Message 5 of 5
Anonymous
in reply to: Anonymous

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

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

Post to forums  

Autodesk Design & Make Report

”Boost