Saturday, January 19, 2013

Use Startup Switch /b to Add AutoCAD Support Path When Launching AutoCAD

We have talked about loading a specific network based AutoCAD profile when AutoCAD is launched. To do this we use the Profile startup switch /p at the AutoCAD startup command line. For example, "C:\Program Files\Autodesk\AutoCAD 2011\acad.exe" /p "C:\SLD\Support\Profile.arg" in the AutoCAD Shortcut Target will launch AutoCAD 2011 into the profile defined in the Profile.arg file. If a Profile parameter is not specified AutoCAD will load the last used AutoCAD user profile. Also, if a .dwg file is opened by double clicking on it in Windows Explorer the last used AutoCAD user profile will be loaded (this may not be a desirable workflow).

/p is called a startup switch. There are several other switches that can be passed to AutoCAD during the startup sequence. Visit this Autodesk page for a complete list of startup switches. Let's look at a very flexible switch, the Script switch /b. This switch executes an AutoCAD script during the startup sequence. Once we have an access point via a script we can do almost anything. This example will execute a script file that calls a lisp routine. The lisp routine will add a support path to the existing AutoCAD support paths defined by the current AutoCAD user profile. This can be handy if you are not controlling which profile a user is launching but want to ensure they have certain support paths available.

To start, we need to create our lisp file that the script will call. The lisp code is accessing the AutoCAD environment variable to determine the current defined AutoCAD support paths and then adds the new support path (or paths) at the end.

Next, we will create a script file that calls the command defined in our lisp routine. The script file just needs to load the lisp routine and execute our command.
Now we need an AutoCAD desktop icon that launches the version you are working with and calls our script file. I copied the out-of-the-box AutoCAD Shortcut and renamed it for this example.

Then right click and select properties and on the Shortcut tab add the /b startup switch in the target to point to your script file. Note, the .scr extension is left off and use quotes especially if there are spaces in the path location.
The /b startup switch is added just after the acad.exe action. You can have multiple startup switches so we could also point to a profile (using /p) or several other options. In this example the full Target text path is:

"C:\Program Files\Autodesk\AutoCAD 2011\acad.exe" /b "C:\SLD\Support\Script\addSupportPath"

Now when AutoCAD is launched from this icon since we are not specifying a profile with the /p startup switch, the last used AutoCAD based user profile will load. Regardless of which profile that is our /b startup switch will call our script file. Our script file loads our lisp routine and executes the command to update the AutoCAD support path.
The AutoCAD startup switches can provide quite a bit of flexibility. Especially once you gain access to the startup sequence with a script file that opens the door to load lisp code, .Net dll's, and more. Depending on how you choose to manage your environment or what you are trying to accomplish this can provide a streamlined solution.