AfraLisp Blog

The AutoLisp/Visual Lisp/VBA Resource Website

AfraLisp Blog

Home Newsletter Utter Rubbish Coding Tips AutoCAD Tips Contact Downloads WAUN

VBA Command Line Project.

As good as VBA is, there are still certain things that are difficult or just impossible to achieve using VBA. For example, have you ever tried to Explode a block using VBA or Load and Run an AutoLisp routine. Not easy is it?

The following code module sends a user defined string to the AutoCAD command line. Theoretically, this means that you can run any AutoCAD command that you wish.
Copy and paste the following coding into a module in VBA and run any of the 4 sub- routines. The four sub-routines available as examples are :

  • Zoome - This simply Zooms to the drawing extents.
  • Xplode - Will explode a block. The block must be
    the last item entered into the drawing.
  • DwfExport - This will export the current drawing as a DWF File.
  • RunLisp - This will Load and Run an AutoLisp file.

Thanks to Michael Hunter, ActiveCad, and Joe Sutphin for this Module and the idea. Sorry guys, but it is to good not to spread around :-) 
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
    (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
    lParam As Any) As Long
Declare Function GetForegroundWindow Lib "user32" () As Long

Public Const WM_COPYDATA = &H4A


dwData As Long
cbData As Long
lpData As String

End Type
Public Sub SendToCommandPrompt(strMessage As String) Dim DataStruct As COPYDATASTRUCT DataStruct.dwData = 1 DataStruct.lpData = strMessage DataStruct.cbData = Len(strMessage) + 2 AppActivate ThisDrawing.Application.Caption SendMessage GetForegroundWindow, WM_COPYDATA, 0, DataStruct End Sub

Sub xplode() SendToCommandPrompt "explode" & vbCr & "last" & vbCr & vbCr End Sub

Sub DwfExport() SendToCommandPrompt "DWFOUT" & vbCr & vbCr & "A" & vbCr & "YES" & vbCr End Sub

Sub Zoome() SendToCommandPrompt "ZOOM" & vbCr & "EXTENTS" & vbCr End Sub

Sub RunLisp() SendToCommandPrompt "(Load ""ALispFile"")" & vbCr & "ALispFile" & vbCr End Sub 

If you would like a copy of this module, just click here. Enjoy.......

The AutoLisp/Visual Lisp/VBA Resource Website

Copyright 1999-Perpetuity by AfraLisp

All rights reserved.
Information in this document is subject to change without notice.
Site created and maintained by Kenny Ramage

The AutoLisp/Visual Lisp/VBA Resource Website