Friday, August 17, 2007

Start a Windows application within AutoCAD

One way is achieved by the AutoLISP function startapp. Notice that the control of what is started is not in the hand of AutoCAD. So if you have an AutoLISP program the code will just continue executing.

Here is an example how it can be used to open with Notepad the acad.pgp file that AutoCAD uses. If you do edit the acad.pgp file you need to run the ReInit command and select the PGP file check box so the changes will be used by AutoCAD. Or if you want to use AutoLISP: (setvar "re-init" 16)

Command: (startapp "notepad" (findfile "acad.pgp"))
33

33 is the return value. As long as not nil is returned the function is successful.

Notice that if one of the arguments contain spaces you need to use double quotes like this sample: (startapp "notepad.exe" "\"file with spaces in the name.txt\"")

If you want to launch Windows Explorer here is one way to open the folder of the current drawing: (startapp (strcat "explorer /e," (getvar "dwgprefix")))

To open a PDF file in the default PDF reader.
(startapp "explorer.exe" "C:\\PDFs\\test.pdf")

If you want to open a PDF file in Adobe Reader 8.0 at a specific page this can be used.(startapp "\"C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\AcroRd32.exe\"" "\"/A page=5 C:\\Program Files\\Adobe\\Reader 8.0\\Reader\\plug_ins\\Annotations\\Stamps\\ENU\\StandardBusiness.pdf\"")

If you want to open a DWF file in Autodesk Design Review here is how:(startapp "\"C:\\Program Files\\Autodesk\\Autodesk Design Review\\DesignReview.exe\"" "\"C:\\Program Files\\Autodesk\\Autodesk Design Review\\Tutorial\\IRD Addition Autodesk Design Review Sample.dwf\"")

And another one if you want to open a DWF in your favorite web browser:
(command "_browser" "http://freewheel.autodesk.com/dwf.aspx?path=http://freewheel.autodesk.com/sample/Hotel5.dwf&sec=1")

To run a VBScript this can be used:
(startapp "wscript" "c:/MyCoolScript.vbs")

There is also the AutoCAD command SHELL.

With SHELL, you can execute operating system (OS) commands while remaining in this program. When SHELL prompts you for an OS command, you can enter most valid commands for your OS. When the command has been executed, SHELL returns you to the Command prompt. You can also call the SHELL command with AutoLISP like this: (command "_shell" "dir *.dwg /p")

Another alternative is if you have DOSLib. In that case you can use the function dos_execute (Runs an external program), dos_exewait (Runs a program and waits for completion) or dos_shellexe (Opens or prints a program or file). You can with these also control how the newly opened window is to be displayed.

I think you pretty much get the idea. If you have any sample you want to share please add a comment below.

2 comments:

  1. You forgot the ACET-functions, i.e. acet-sys-command. More info: http://www.jtbworld.com/download/acetutil.zip

    ReplyDelete
  2. Stephan, thanks for the reminder.

    ReplyDelete

Some of the latest blog posts

Subscribe to RSS headline updates from:
Powered by FeedBurner

Contact Us | About JTB World | Website General Terms of Use | Privacy Policy
^ Top of page

© 2004- JTB World. All rights reserved.