Wednesday, April 4, 2012

How to start a VBS file using AutoLISP

If you in AutoCAD want to start a VBScript file with AutoLISP here are three ways where the variable app holds the full path to the VBS file:

(startapp "WSCRIPT.EXE" (strcat "\"" app "\""))

(command "START" app)

(if (setq WScript (vlax-get-or-create-object "WScript.Shell"))
  (vl-catch-all-apply 'vlax-invoke-method (list WScript "Run" app 1 :vlax-true))
)

If the START command is used you will quickly see the AutoCAD Shell so I prefer to use the startapp function.

If the path contains spaces like (C:\\Folder A\\test.vbs) the startapp function must have the path with double quotes like the snippet above, otherwise the Windows Script Host will show this error: There is no file extension in "C:\Folder".

Some of this works with starting or running other files (EXE, BAT, CMD,…) or open files in their associated application. See also how to Start a Windows application within AutoCAD.

1 comment:

  1. David Stein commented on Google+:
    You can invoke cscript within "cmd /c" or via a shell exec (invoke Wscript.Shell COM interface, use the Run method, and pass in window option 7/ minimized). But the advantage is you can control the "wscript.echo" outputs. Instead of popups, it's text (a la princ).

    ReplyDelete

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner