Overview of Bootstrap Code for AutoCAD Customization
Last week, you made progress by altering a single line in the code from the previous installments of this series. This week, the focus shifts to creating a bootstrap code that will function on a network, aiding in the installation of any missing profiles. Understanding each line of code will ensure you know precisely what needs adjustments for your specific needs.
Preparing the Environment
Before diving into the code, certain preparations are essential:
-
Locate the Required Files: Acquire the
profiles.lspfile from JTB World, ensuring it’s stored on your network alongside your other codes or customizations. This file will be integral to the bootstrap process. -
Check Trusted Locations in AutoCAD: Ensure the directory where your code resides is recognized as a trusted location in AutoCAD.
-
Exporting Profiles: Use the Options dialog within AutoCAD to export profiles. The Export button will allow you to save them as
.argfiles. It’s advisable to store these in a network directory dedicated to your AutoCAD version, e.g.,p:autocad_2025. -
Creating Shortcuts: Generate shortcuts for each profile you intend to support, placing them within the same directory as
.argfiles. The bootstrap code will check the public desktop for these shortcuts and create them on the user’s desktop if they’re absent.
Crafting the Bootstrap.lsp Code
The bootstrap code represents a more intricate section of scripting, but only specific lines require modification. The following code snippet illustrates the structure:
lisp
(setq pathCodePrefix “p:autocadcode”)
(setq pathAcadPrefix “p:autocad_2025”)
(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.”
“nnAutoCAD 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)
Important Lines to Customize
-
Setting the Path for Code Files:
Modify the path that indicates whereprofiles.lspis stored.lisp
(setq pathCodePrefix “p:autocadcode”)Substitute the quoted text with the actual location of your
profiles.lspfile, ensuring proper syntax (double backslashes at the end). -
Adjusting the Profile Information:
Set the main profile and associated files with the following lines.lisp
(setq myMainProfile “Company AutoCAD”)
(setq myMainProfileFile “Company AutoCAD.arg”)Ensure the profile name matches the one within AutoCAD’s Options tab.
-
Creating Shortcut List:
This line specifies which shortcuts will be created on the desktop.lisp
(setq allShortcuts (list “Company AutoCAD.lnk” “Company AutoCAD Metric.lnk”))You can modify this list to include more shortcuts as necessary, or delete unnecessary ones.
-
Alert Messages:
Customize the alert messages shown to users.lisp
(setq msgAlert (strcat “Your profiles have been imported.”
“nAutoCAD must be restarted to update the support paths.”
“nnAutoCAD will be closed after dismissing this dialog box.”))
Understanding the Bootstrap Logic
The following critical lines of code manage the bootstrap operations:
-
Adding Trusted Paths:
Ensure the bootstrap code executes correctly by including the path toprofiles.lspas a trusted location.lisp
(setvar “TrustedPaths” (strcat (vl-string-right-trim “;” (getvar “TrustedPaths”)) “;” pathCodePrefix)) -
Checking for Existing Profiles:
It checks if the main profile is loaded; if not, the bootstrap process is initiated.lisp
(cond ((not (existProfile myMainProfile))
Managing Secondary Profiles
If your set-up includes multiple profiles, it’s essential to duplicate and modify certain lines accordingly. Use the commented section in the bootstrap code to adjust for each additional profile you wish to install. For configurations with only one profile, disabling the unnecessary code by commenting it out can simplify your script management.
Frequently Asked Questions
Q1: Can multiple profiles exist simultaneously in AutoCAD?
Yes, AutoCAD allows for multiple profiles to be loaded. The bootstrap code can be adjusted to handle as many profiles as necessary by adding similar import lines for each new profile.
Q2: What happens if I forget to set the trusted path?
If the trusted path is not established, AutoCAD will not load the profiles.lsp correctly, potentially leading to errors when trying to import profiles.
Q3: Is it possible to change the profile once AutoCAD is open?
Yes, users can switch between profiles via the various shortcuts created on their desktop, allowing them to customize their experience as needed even after AutoCAD is already running.
