twitter youtube facebook linkedin email
Connect with:

AUTOCAD BLOG

Bootstrap AutoCAD Deployments for Customizations (5)

R. Robert Bell
February 4, 2016

Wasn’t that fun last week?

In Bootstrap AutoCAD Deployments for Customizations Part 4, you worked with some code. Editing it was no big deal because you only needed to change one line.

This week we take the next step: Writing the code that will live on the network and do the “heavy lifting” of installing any missing profiles. I will explain each line of code and point out the ones you need to change for your own use.

Most edits will be made to the beginning of the code. But if you’re supporting multiple profiles—e.g., you have a main profile and also a metric profile—you will need to copy and edit a section of code, in the middle, for each secondary profile. If you’re supporting a single profile, you simply comment out that small section.

Additional files you will need for bootstrapping AutoCAD

First things first: Locate the profiles.lsp file you downloaded from JTB World. It should be on the network where you put the rest of your code and/or customizations. The bootstrap code will load the profiles.lsp file—this is easy to do—and use some of its functions.

Also, you will need to:

  • Ensure your code is in an AutoCAD trusted location.
  • Place exported copies of your profiles on the network. Use the Options dialog box to export profiles from AutoCAD. The Export button saves the desired profiles as .arg files, which, I advise, you put in a network location specific to your AutoCAD version. Such as p:\autocad_2016.
  • Create shortcuts for each supported profile, and place them with the .arg files (shortcuts are also version-specific). Note: these shortcuts could be added to the network deployment. The bootstrap code will place the shortcuts on the user’s own desktop if they are missing from the public desktop.

The main event: Bootstrap.lsp

Here is this week’s code. Don’t go running for the hills screaming in panic!

Yes, there is a lot more of it. But you need to edit only a few lines. And it will all become much clearer after you read the following section.

(setq pathCodePrefix "p:\\autocad\\code\\")
(setq pathAcadPrefix "p:\\autocad_2016\\")
(setq myMainProfile "Company AutoCAD")
(setq myMainProfileFile "Company AutoCAD.arg")
(setq allShortcuts (list "Company AutoCAD.lnk" "Company AutoCAD Metric.lnk"))
(setq msgAlert (strcat "Your profiles have been imported."
"\nAutoCAD must be restarted to update the support paths."
"\n\nAutoCAD will be closed after dismissing this dialog box."))
;; Edit lines above for your environment
(cond ((and (setvar "TrustedPaths"
(strcat (vl-string-right-trim ";" (getvar "TrustedPaths"))
";"
pathCodePrefix))
(setq fqnProfileUtils (strcat pathCodePrefix "profiles.lsp"))
(findfile fqnProfileUtils)
(load fqnProfileUtils)
(setq allProfiles (getAllProfileNames)))
(cond ((not (existProfile myMainProfile))
(princ "\nExecuting Bootstrap.")
(setq includePaths 1)
;; Add main profile and make it the current profile
(forceImport myMainProfile
(strcat pathAcadPrefix myMainProfileFile)
includePaths)
;; Copy the below and edit as needed for each secondary profile
(importProfile "Company AutoCAD Metric"
(strcat pathAcadPrefix "Company AutoCAD Metric.arg")
includePaths)
;; This comment ends the copy and edit section
(foreach lnkFilename (cond ((not (findfile (strcat (getenv "Public") "\\Desktop\\" lnkFilename)))
(vl-file-copy (strcat pathAcadPrefix lnkFilename)
(strcat (getenv "UserProfile") "\\Desktop\\" lnkFilename))))
allShortcuts)
(alert msgAlert)
(command "._Quit")))))
(princ)

A detailed look at AutoCAD bootstrapping code: What you WILL edit

(setq pathCodePrefix "p:\\autocad\\code\\")
Change the text within the double quotes to the location where you put profiles.lsp. Double backslashes: Use them, be sure there’s a set at the end of the text.

(setq pathAcadPrefix "p:\\autocad_2016\\")
You change the text within the double quotes to the location where you put the .arg and .lnk files.

Note: The bootstrap.lsp file should also be placed in this location, which is the same place you put the acad.lsp file from Bootstrap AutoCAD Deployments for Customizations Part 4.

(setq myMainProfile "Company AutoCAD")
This is the actual name of your main profile. Change the text within the double quotes to match the AutoCAD Profiles tab in Options. This should be the profile you want your users to use by default. Note: Once the bootstrap is done, users can use any shortcut to load another profile.

(setq myMainProfileFile "Company AutoCAD.arg")
Change the text within the double quotes to the filename of the .arg file exported from your main profile.

(setq allShortcuts (list "Company AutoCAD.lnk" "Company AutoCAD Metric.lnk"))
This is a list of the filenames for all of your needed shortcuts. There are two shortcuts listed here: Company AutoCAD.lnk and Company AutoCAD Metric.lnk. But: you are not limited to just two. Edit as needed for the filenames of the .lnk files and add any additional ones right before the closing parentheses. If you are providing only one profile, simply delete the unneeded one; a one-element list is fine.

(setq msgAlert (strcat "Your profiles have been imported."
"\nAutoCAD must be restarted to update the support paths."
"\n\nAutoCAD will be closed after dismissing this dialog box."))

These three lines will let the user know the profiles were added and that AutoCAD will be closed. From this point forward, the user should start AutoCAD from the correct shortcuts.

;; Edit lines above for your environment
This is just a comment in the code so you know where to edit things. Comments are ignored when the code is running.

A detailed look at AutoCAD bootstrapping code: What you WILL NOT edit

You won’t edit the next few lines of code. My descriptions are just to help you understand what the code is doing.

(cond ((and
This sets up a test. All the following needs to be true for the bootstrap to run correctly.

(setvar "TrustedPaths"
(strcat (vl-string-right-trim ";" (getvar "TrustedPaths"))
";"
pathCodePrefix))

This adds the profiles.lsp file location to AutoCAD trusted locations. Note: For security, ensure IT provides a location that is read-only to normal users, and where only specific, secure logins can modify the files.

(setq fqnProfileUtils (strcat pathCodePrefix "profiles.lsp"))
This adds the path to the plain filename; it is used by the next two lines of code.

(findfile fqnProfileUtils)
This looks for the file in the location you specified. If the file isn’t be found, the code will not continue to run.

(load fqnProfileUtils)
This loads the profile.lsp file so that its functions can be used with the AutoCAD profiles.

(setq allProfiles (getAllProfileNames)))
This gets all the profiles configured in AutoCAD. The getAllProfileNames function comes from the profile.lsp file. Note: This is the last line to test if the bootstrap can run. We have not yet tested whether the bootstrap needs to run.

(cond ((not (existProfile myMainProfile))
This is a new test, looking to see if your main profile is loaded in AutoCAD. If it is not, the bootstrap needs to run.

(princ "\nExecuting Bootstrap.")
Because we determined the main profile was missing, the code tells the user what is going on at the AutoCAD command prompt.

(setq includePaths 1)
This is here only to make the next few lines of code a little easier to read.

We are going to include paths. A setting in some of the profiles.lsp functions allow an imported profile to include paths or to ignore paths; the value for that setting is 1. That number won’t be easy to understand later, when you need to create a new copy of the bootstrap for AutoCAD 2017. So we assign the number to a variable that makes it easier for us to read some of the rest of the code.

;; Add main profile and make it the current profile
This is another comment to let you know what the next few lines of code are doing.

(forceImport myMainProfile
(strcat pathAcadPrefix myMainProfileFile)
includePaths)

This function from the profile.lsp file loads a profile from an .arg file and makes it the current profile. It uses information you provided at the top of the code.

A detailed look at AutoCAD bootstrapping code: OK, I lied, you will need to edit this

;; Copy the below and edit as needed for each secondary profile
This comment tells you to copy the following three lines and edit them for as many secondary profiles as you need. You do not need to copy the comment. If you do not need any secondary profiles, you should comment out the code by adding two semi-colons to the start of each of the three lines.

Why not just delete the lines? You may later decide you need to add some secondary profiles. Then you can uncomment the lines by removing the semi-colons.

(importProfile "Company AutoCAD Metric"
(strcat pathAcadPrefix "Company AutoCAD Metric.arg")
includePaths)

This a function from the profile.lsp file only loads a profile from an .arg file. It uses information you provided at the top of the code.

;; This comment ends the copy and edit section
This comment tells you not to copy any of the remaining code.

A detailed look at AutoCAD bootstrapping code: I’m done lying, don’t edit the rest of this

(foreach lnkFilename (cond ((not (findfile (strcat (getenv "Public") "\\Desktop\\" lnkFilename)))
(vl-file-copy (strcat pathAcadPrefix lnkFilename)
(strcat (getenv "UserProfile") "\\Desktop\\" lnkFilename))))
allShortcuts)

This is the trickiest part of the code, but it isn’t code you need to edit! These four lines check to see if the shortcuts are on the desktop. If the shortcuts aren’t on the public desktop—i.e., they came from the deployment—then any missing ones are added to the user’s desktop. That’s because AutoCAD users typically won’t have rights to add shortcuts to the public desktop, so the shortcuts are added to the user’s desktop instead.

The list of shortcuts were provided by you at the top of the code.

(alert msgAlert)
When the bootstrap is complete, this shows the user a dialog box that says AutoCAD will close. The dialog box text is at the top of the code, and you can edit it.

(command "._Quit")))))
If the bootstrap executed, this quits AutoCAD. All of those closing parentheses are for the earlier tests.

(princ)
If the bootstrap was not executed, this provides a clean exit from the code.

AutoCAD bootstrap.lsp code as formatted in the Visual LISP® editor.

AutoCAD bootstrap.lsp code as formatted in the Visual LISP® editor.

Next up: Bootstrap AutoCAD Deployments for Customizations Part 6

In my next post (Bootstrap AutoCAD Deployments for Customizations Part 6) we’ll look at how you add the acad.lsp file to the AutoCAD deployment to enable bootstrapping.

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

Bootstrap AutoCAD Deployments for Customizations Part 4

KEEP UP WITH AUTOCAD

   

Try AutoCAD Now

AutoCAD Blog Free Trial

Questions?

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.

2 Comments;

View by:
Most Recent Oldest
  1. NNLAOR

    I have a small question about support files being on a shared drive on a domain network. The DWGtoPDF.pc3 file. The plotter .pc3 files. How do I go about setting permissions to the DWGtoPDF.pc3. I gave full access to the .pc3 and directory but my users are not able to modify custom pdf print sizes. Would the answer be to keep the DWGtoPDF.pc3 in a local directory on the machine?

    1. R. Robert Bell (Post author)

      Yes, DWGtoPDF.pc3 does not work well for users when it can be located in a read-only folder. I make sure the local computer’s plotter support folder is the first one specified in the plotter support paths and then don’t place DWGtoPDF.pc3 on the network location. The same thing applies to a few other PC3 files such as the ones to create image files.