twitter youtube facebook linkedin email
Connect with:


Bootstrap AutoCAD Deployments for Customizations (4)

R. Robert Bell
January 29, 2016

In Bootstrap AutoCAD Deployments for Customizations Part 3 I told you the bootstrap process adds only one file, acad.lsp, to the deployment. You won’t ever edit it, and any files that may need to be edited will be located on the network and edited outside of the deployment. This will make the IT department happy.

A brief explanation of AutoLISP file

AutoLISP® files are text-based files (.lsp instead of .txt). They can be edited in Notepad or your favorite text editor, but I recommend using the Visual LISP® editor built into AutoCAD® software and accessed with the command VLIDE. One reason I like the Visual LISP editor: It color-codes the file syntax. See Figure 1.

Color coding in the Visual LISP editor. Bootstrap AutoCAD Deployments for Customizations.

Figure 1: Color coding in the Visual LISP editor.

The code includes a lot of parentheses (I’ve heard LISP referred to, affectionately, as standing for Lost In Stupid Parentheses) plus AutoLISP functions (those odd bits of text that aren’t normal words) and normal words. (I’ve written so much AutoLISP code that I overuse parentheses in my normal writing, much to the despair of my editors.)

Never written AutoLISP code? Don’t worry. I will explain everything clearly and you can always reach out to me if you have issues.

The only acad.lsp file you need for bootstrapping AutoCAD

I advocate placing customizations on the network when possible. The locally deployed acad.lsp file placed in %ProgramFiles%\Autodesk\AutoCAD 2016\Support should do no more than locate another .lsp file on the network and execute it.

This, in essence, is bootstrapping: Our acad.lsp file will be deployed with AutoCAD—but its sole purpose is to find, and execute, another .lsp file, bootstrap.lsp, that is located on the network.

Trusted locations, recently introduced to AutoCAD, complicate things a bit. The acad.lsp file not only has to load the required code; it also adds the code’s location to trusted locations.

All this is easily accomplished and does not violate the AutoCAD security model because it takes place in a trusted location.

Ready? OK, deep breath. Below is the code for the acad.lsp file. Simply copy it into your text editor and save it as “acad.lsp” to your My Documents folder for now.

(princ "\nLoading bootstrap version of acad.lsp... ")
(setq myFile "p:\\autocad_2016\\bootstrap.lsp")
(cond ((findfile myFile)
(setq oldPaths (getvar "TrustedPaths"))
(setq newPaths (strcat (vl-string-right-trim ";" oldPaths)
(cond ((> (strlen oldPaths) 0) ";") (""))
(vl-filename-directory myFile)
(setvar "TrustedPaths" newPaths)
(load myFile)))
(princ "done.")

That wasn’t so scary, was it?

Note: If you are using Notepad, enclose the filename in double quotes so Notepad does not add the .txt extension. However, if you are using the Visual LISP editor, .lsp is automatically used. See Figure 2.

Saving a .lsp file in Notepad. Bootstrap AutoCAD Deployments for Customizations.

Figure 2: Saving a .lsp file in Notepad.

Note: AutoLISP usually doesn’t care whether text is lower case or in caps except when you display something at the AutoCAD command prompt. I use capitalizations to help make the code clearer.

OK, now let’s talk through each line in detail.

A detailed look at the acad.lsp code for bootstrapping AutoCAD

(princ "\nLoading bootstrap version of acad.lsp... ")
This line prints “Loading bootstrap version of acad.lsp… ” to the AutoCAD command prompt. I intentionally added a blank space to the end of the text so that the cursor does not blink right after the ellipsis. This is how most AutoCAD commands do their prompts. The “\n” places the text on a new line on the AutoCAD command prompt.

Note: In one of the few AutoLISP cases where capitalization matters, the “\n” must be lower case.

(setq myFile "p:\\autocad_2016\\bootstrap.lsp")
This line sets the location and filename for the bootstrap code—the one that will be available outside of the deployment created by the IT department.

Note: This is the only line of code in this file that you need to edit for your own use!

I named the bootstrap code file bootstrap.lsp and I suggest you do the same. In the above example, the network location for the file is p:\autocad_2016. Your actual location will vary.

“Wait a minute!” you may be saying. “The network location is p:\autocad_2016 but there are two backslashes in the code.” Is that a mistake? No.

For every normal backslash in your path, the AutoLISP code requires two backslashes. This is because the backslash is a special character to AutoLISP code. For example, if the bootstrap.lsp file is located on your network at m:\autocad\programs, then the code needs to use “m:\\autocad\\programs\\bootstrap.lsp” in the double quotes. Paths can have spaces, so “s:\\autocad 2016\\code\\bootstrap.lsp” is valid, too.

(cond ((findfile myFile)
This line checks to see if the bootstrap.lsp file can be found in the location you provided. If not, no problem: AutoCAD will not attempt to alter the environment. This is part of the beauty of bootstrapping. If a special AutoCAD environment cannot be supported because the bootstrap code is missing, out-of-the-box AutoCAD continues to load without issue or errors.

Note: The opening parentheses in (cond ((findfile myFile) won’t have their matching closing parentheses until later in the code.

(setq oldPaths (getvar "TrustedPaths"))
This gets the original setting for the AutoCAD system variable TrustedPaths and saves it to a variable called “oldPaths.”

(setq newPaths (strcat (vl-string-right-trim ";" oldPaths)
(cond ((> (strlen oldPaths) 0) ";") (""))
(vl-filename-directory myFile)

These four lines work together to add the bootstrap.lsp file path to the end of any current trusted locations. The first line strips out any semicolons (;) at the end of the old paths. The second line checks to see if there are any old paths, and, if there are, puts a semicolon on the end. The third line adds the path to the bootstrap.lsp file. The last line adds a trailing backslash to the end of our new path because that’s how AutoCAD stores them.

You may be asking, “Why strip out any trailing semicolons in the first line and then just add one back in the second line?” Answer: To avoid multiple semicolons at the end of the old paths before adding our new path. Does it harm anything to have multiple semicolons? Not at this time. But it is sloppy to let semicolons proliferate.

(setvar "TrustedPaths" newPaths)
This sets the AutoCAD system variable to the new paths, which we set based on the old paths plus our new path.

(load myFile)))
This line loads the found bootstrap.lsp file we specified at the beginning of the code. (Again, if the file cannot be found, this loading attempt will never occur, so there will be no error for the user to see.) The two closing parentheses (load myFile))) complete the opening parentheses earlier in the code.

(princ "done.")
This line will print “done.” at the AutoCAD command prompt, whether the bootstrap.lsp file is found or not. Also note there is no new-line character “\n” at the beginning. This is intentional, so the “done.” prompt goes at the end of the “Loading bootstrap version of acad.lsp… ” prompt. Here’s what you’ll see:

Command: Loading bootstrap version of acad.lsp… done.

This provides a “clean exit” to the code at the AutoCAD prompt.

Bootstrapped AutoCAD deployments are easy—no?

Even though the acad.lsp file contains 12 lines of code, there is only one line you need to edit on your own. That’s not so bad, is it? Just remember to use two backslashes for every single backslash in the path you provide.

Stay tuned! Bootstrap AutoCAD Deployments for Customizations Part 5

My next post (Bootstrap AutoCAD Deployments for Customizations Part 5) looks at how we use the bootstrap.lsp file to add needed profiles to the user’s AutoCAD environment.

Here’re all the previous installments:

Bootstrap AutoCAD Deployments for Customizations Part 1

Bootstrap AutoCAD Deployments for Customizations Part 2

Bootstrap AutoCAD Deployments for Customizations Part 3



Try AutoCAD Now

AutoCAD Blog Free Trial


Have subscription pricing questions? Check out our Subscription info page.

Need to find a service pack for a legacy version of AutoCAD? Our Downloads page has everything you need.

Running into a problem? Our Troubleshooting site should be able to help.

Getting started? Download a free trial of AutoCAD, AutoCAD LT, or AutoCAD Mobile!

Check Out AutoCAD 2018.1

R. Robert Bell

A longtime AUGI director—and the organization’s current President—Robert has been active in the MEP industry for over 25 years and an AutoCAD user since version 2.18. He provides strategic direction, technical oversight, and high-level support for Stantec. Follow him on Twitter @r_robert_bell.


View by:
Most Recent Oldest
  1. clindner

    This is a great series, Robert!

    In reference to the (findfile myFile) code, you state that if myFiale isn’t found: “AutoCAD will not attempt to alter the environment.”
    This is true, it will simple launch AutoCAD with the previous (current) profile. If, however, the reason it didn’t find myFile was because of a network glitch (as happens in our office), and if the current profile contains search paths which also point to the network (and are also unavailable), then AutoCAD will not find (and subsequently forget) these paths. So, AutoCAD will appear to start successfully, but there will be search paths missing.

    Does your bootstrap.lsp attempt to re-import the profile each launch to make sure that the search paths (and other settings) are kept consistent?

    (Sorry if I’m getting ahead of your series.)

    1. R. Robert Bell (Post author)

      Excellent question, Chris. As it is written, it will not repair missing search paths. However, it is relatively easy to add it. In fact, I had to do this very thing not long ago for our own bootstrap! I think it will make an excellent follow-up post.

    2. ArchD

      Is there a way to have the acad.lsp check for redundancy? I’m having an issue where it imports the profiles and sets them on the first run, but once the profiles are there and Autocad is run by it’s default shortcut, it just adds a second, thirds, forth, ect. set of trusted locations, adding a new set each time it’s run.

      I feel like I’m missing something because I thought it was supposed to force a profile to use if it so happens to use one that is not in the profile list in the bootstrap.lsp.

    3. R. Robert Bell (Post author)

      Archie, if you add a line to the bootstrap to copy a shortcut to the user’s desktop that launches AutoCAD with the correct profile that will take care of your issue. You can add a check in the bootstrap to make sure that duplicated trusted locations aren’t added if they are already there. Use wcmatch to check the current value and skip adding if the path(s) are already there. But the real key is to copy that shortcut for the users so they don’t continue to use the out of the box shortcuts.