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