Thisdrawing.Sendcommand cannot be used from Macro

Thisdrawing.Sendcommand cannot be used from Macro

Anonymous
Not applicable
310 Views
2 Replies
Message 1 of 3

Thisdrawing.Sendcommand cannot be used from Macro

Anonymous
Not applicable
I've noticed that Thisdrawing.Sendcommand will not work until I quit the program. I wrote the following code to test problem. The drawing cannot be changed to " view-ucs" until I quit the program. Can you tell me what the problem is?.
The program is composed of an Userform1 and a Module.
The code in Userform1
Private Sub CommandButton1_Click()
Me.Hide
Dim objViewPort As AcadViewport
Dim dblViewDirection(2) As Double
Set objViewPort = ThisDrawing.Viewports.Add("Side")
dblViewDirection(0) = 1
dblViewDirection(1) = 0
dblViewDirection(2) = 0
objViewPort.Direction = dblViewDirection
'make the viewport active
ThisDrawing.ActiveViewport = objViewPort
'make the drawing fit the modalspace
ThisDrawing.Application.ZoomExtents
'Change UCS to x-y plane
ThisDrawing.SendCommand "_ucs" & vbCr & "_v" & vbCr
Me.Show
End Sub
The code in Module
Public Sub Test()
UserForm1.Show
End Sub
0 Likes
311 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable
The problem is simple: VBA is not waiting for the "Command" you sent to
finish before it moves on to the next line of code. This problem has been
addressed in many ways, but I prefer to harp on the merits of using
adcgSendCmdSync.arx. It registers a new command, VBARUNEX that allows VBA to
"release" control back to AutoCAD when using SendCommand.
VBARUNEX can be called silently, so it is compatible with lisp functions
and toolbar macros that call your procedure, and you can use it from the
command line for testing during development.
Oh, I nearly forgot, you can download it here:

http://www.vbdesign.net/cadpages/tbox.htm

Look toward the bottom of the page for the "send synchronous command" link.

Randall Rath
VB Design
http://www.vbdesign.net/cadpages/
0 Likes
Message 3 of 3

Anonymous
Not applicable
Thanks a lot. However, I'm wondering if it is possible to embed that command in my program. In other words, I don't want to call "VBARUNEX" in command line. If it possible to call my program from Macros and "CommandSync" is activated automatically ?
0 Likes