Deploy and Support Autolisp
Deploy and Support Autolisp
Learning Objectives
Learn how to create and implement custom help topics
Learn how to support multiple languages
Learn how to deploy programs and define plug-in bundles
Learn how to trust and digitally sign AutoLISP program files
Description
Do you write AutoLISP programs and need to share them with users inside or outside your
company? Do you have users who use different languages or releases of AutoCAD
software? Sharing—more commonly referred to as “deploying” in the programming
community—program files can get complicated and cause those new to programming to
feel overwhelmed. This session will provide an overview of the best practices that you can
use to simplify the deployment and support of your custom AutoLISP programs. This
session features AutoCAD.
Your AU Expert
Lee Ambrosius is a Principal Learning Experience Designer at Autodesk, Inc., for the AutoCAD
software and AutoCAD LT software products. He works primarily on the CAD administration,
customization, and developer documentation. Lee has also worked on the user documentation
for AutoCAD on Windows and Mac. He has presented on a wide range of topics at Autodesk
University over the past decade plus, from general AutoCAD customization to Autodesk
ObjectARX technology. Lee has authored a number of AutoCAD-related books, with his most
recent project being AutoCAD Platform Customization: User Interface, AutoLISP, VBA, and
Beyond published by Wiley & Son’s. When he’s not writing, you can find him roaming various
community forums, posting articles on his blog, or tweeting AutoCAD-related information.
Twitter: @leeambrosius
Email: lee.ambrosius@autodesk.com
Blog: http://hyperpics.blogs.com
Page 1
1 Introduction
Learning something new can be exhilarating and scary all at the same time, with time things that
were once new become part of the everyday norm. For me, the adventure into AutoLISP
programming started about 20 years ago, while for you it might have been hours, days, or years
ago. When you first started programming doesn’t matter, but you most likely had some doubt
and excitement in the beginning. While I had some doubt about whether the concept of
programming was appealing to me, it was the “siren call” of the benefits that pulled me in;
getting stuff done faster, reducing repetitive tasks, and enforcing consistencies across all
drawings. I am sure you might be able to tell a similar story as to why you initially got started
developing with the AutoLISP programming language.
As time went along and I became more secure in my programming skills and the programs I
wrote, I wanted to share those programs with others so they could benefit from them too. While
I was excited to share my programs with others and show off how cool I thought they were, I
learned quickly that sharing a custom program wasn’t just giving out an AutoLISP (LSP) file. All
the information about how to run and use the custom programs defined in the LSP files I wanted
to share was stuck in my head; good for me, but less than ideal for the users that didn’t know
how to program with AutoLISP.
Along with learning that everything can’t be stuck in my head when it came to sharing my
custom programs, I learned rather quickly that users seem to think programmers are interested
in providing support and without support they are less likely to actually use your custom
programs. Then once you do get them to use your custom programs, they tend to have
opinions about them, making you wonder why you even shared them to begin with. Supporting
custom programs can often be more time consuming than writing the actual programs
themselves, but it doesn’t have to be that way with a bit of planning. The type and level of
support you might need to provide is typically determined by:
Company size; individual (one man shop), small, medium, or large
Location of the users; local (on-site/nearby) or remote
Make-up of the user base; those that might know how to program versus those that
don’t
As the programmer of custom programs, some of the support tasks that you might need to get
involved with are:
Troubleshooting
Training and knowledge transfer
Deployment/installing
While this might sound a bit overwhelming or complicated, the sections in this handout will help
you understand and plan for these support tasks.
Page 2
2 Implement Custom Help
Documenting source code is one of the least favorite activities of a developer, but whether
comments are added to the source code isn’t very helpful to the end users. Documentation isn’t
something that many developers think about, but it is an essential part of the overall user
experience. Documentation is can be a broad subject that includes:
Prompt and error messages in a custom program
Listing of commands or functions exposed by custom programs in which the user
can utilize
Information about the options or expected values for exposed commands and
functions
Concepts required to understand the custom programs
Tutorials that explain how to use the custom programs
Documentation should be considered the first line of support and an integral part of any custom
program. Unless you want to give out your email address and phone number, and dedicate
time 24/7 to your deployed custom programs you will want to provide some level of basic
documentation. Start small, you don’t need to write a manual the first day you release your
custom programs.
When you write prompt messages, make sure they are clearly worded and short; long and
wordy prompt messages should be avoided to reduce confusion by the end user or even the
possibility of the message being missed entirely. If the user Command prompt is not docked
and is small, longer prompt messages might be pushed up and out of the history very quickly.
You might consider breaking a wordy prompt message, if related to request input, into multiple
requests for input or move some of the heavier explanatory text to the documentation.
Remember, once a user understands how your custom program works, the prompts become
less useful to them as they learn the input sequences.
Similar to prompt messages, error messages displayed by a custom program should be short
and right to the point. Longer explanations and steps needed to resolve an encountered
problem should be placed in the documentation, not the custom program itself. Problems
encountered by your custom programs should be handled by one of two types of error
messages: soft and hard. soft error messages provide the user with an indication something
went wrong, but doesn’t interrupt the user’s workflow for the most part and the
command/function continues. hard error messages are displayed prior to the termination of a
command/function and do interrupt the workflow of the user. An example of a soft error
message would be a prompt message at the Command prompt to have the user try a different
value, while an example of a hard error message would be an alert box that the user must
engage with before continuing.
Beyond the prompts and error messages used in a custom program, explanatory and reference
documentation should be provided with your custom programs. The explanatory documentation
can be as simple as a listing of exposed commands with a description of each option available,
to a more comprehensive set of documentation that explains when the user might use a certain
command along with what its benefits might be. The complexity of the documentation and the
desired user experience impacts how you deliver the documentation. You might choose to
deliver the documentation as a/an:
Set of loose web (HTML, JS, CSS) and image files
Compiled Help (CHM) file
WinHelp (HLP) file
Page 3
While your documentation should be accessible from outside of the AutoCAD-based program,
integrating it into the usage of your custom programs makes the experience more fluid and feel
like an extension of the AutoCAD-based program. The AutoLISP programming language
provides several functions that can be used to hook up your custom programs to the AutoCAD
Help system. These AutoLISP functions can be used to display custom help:
HELP – Displays a file in the native help window or a topic from a CHM/HLP file in its
respective application window
SETFUNHELP – Associates a file or topic from a CHM/HLP file to a command; the
file or topic is then displayed contextually in the native help window or its respective
application window when F1 is pressed from the AutoCAD user interface
STARTAPP – Launches an application with or without a specified file; can be used to
open file formats that are not supported by the HELP and SETFUNHELP functions
Along with the previously mentioned functions, plug-in bundles can be used to associate custom
help topics to each exposed command in a custom program. Plug-in bundles are covered
under the section “Build Plug-in Bundles for AutoLISP Programs” later in this handout.
Note: The examples in this section can be found in the 2 - help setfunhelp and startapp.lsp file
that is part of the dataset associated with this session.
;; Displays the LINE command topic from the AutoCAD help system
(help "" "LINE")
Page 4
Display a help file/topic with the SETFUNHELP function
The SETFUNHELP function is used to associate a help file that contains information related to a
specific command/function exposed by a custom program, typically this would be a topic within
a documentation set but could be a stand-alone file. You can display an HTML, CHM, or HLP
file with the SETFUNHELP function. Once the command/function is defined and the help file
has been associated, you can display the topic by pressing F1 under the following situations:
When AutoComplete is enabled and the full name of the command is displayed, but
the command has not been started yet
When the command is active
Note: While you are limited to HTML, CHM, and HLP files with the SETFUNHELP function, it is
possible to display a TXT or PDF file using an HTML page that performs a redirect. An example
of this can be found in the 2 - TXTRedirect.html and 2 - PDFRedirect.html files that are part of
the dataset for this session.
The syntax for the SETFUNHELP function is:
(setfunhelp c:function_name [help_file [chm_hlp_topic
[chm_help_window_command]]])
The following examples demonstrate how to set up contextual/F1 help for custom commands:
;; Displays the LINE command topic from the AutoCAD help system
(defun c:CMD1 () (getstring "\nEnter some text: "))
(setfunhelp "c:CMD1"
""
"LINE")
Page 5
Display a file with the STARTAPP function
While the STARTAPP function is not designed for displaying help, it can be used as an
alternative to the HELP function. The STARTAPP function is used to launch an application and
open a document. While it is possible to only open an HTML, CHM, or HLP file with the HELP
and SETFUNHELP functions, you can open the following file types using various applications
with the STARTAPP function and more:
ASCII text (TXT) file
Rich Text Format (RTF) file
Microsoft Word (DOC/DOCx) document file
Portable Document Format (PDF) file
The syntax for the SETFUNHELP function is:
(setfunhelp c:function_name [help_file [chm_hlp_topic
[chm_help_window_command]]])
The following examples demonstrate how to open various document types that could contain
help content:
Page 6
Once the HTM/HTML files have been authored, the files can then be added to a CHM project
file using Microsoft HTML Help Workshop (http://www.microsoft.com/en-
us/download/details.aspx?id=21138) which is free, or a specialized content
managing/publishing software such as Adobe RoboHelp
(http://www.adobe.com/products/robohelp.html) and MadCap Flare
(http://www.madcapsoftware.com/products/flare/).
The following steps outline how to create a CHM file using HTML Help Workshop.
1. In Windows, do one of the following:
a. Windows 7: Click the Windows Start button All Programs HTML Help
Workshop HTML Help Workshop.
b. Windows 8: On the Windows Start screen, right-click and click All Apps. Scroll to
the HTML Help Workshop section and click HTML Help Workshop.
c. Windows 8.1: On the Windows Start screen, click All Apps located near the
lower-left corner of the screen. Scroll to the HTML Help Workshop section and
click HTML Help Workshop.
d. Windows 10: Click the Windows Start button All Apps HTML Help
Workshop HTML Help Workshop.
2. In the HTML Help Workshop window, click File New.
3. In the New dialog box, select Project and click OK.
4. In the New Project Wizard, click Next.
5. In the New Project Wizard, Destination page, click Browse.
6. In the Open dialog box, browse to Documents (or My Documents) and enter the name
AU2016. Click Open.
7. In the New Project Wizard, Destination page, click Next.
8. In the New Project Wizard, Existing Files page, click Next.
9. In the New Project Wizard, Finish page, click Finish.
The following steps outline how to modify the properties of the project (HPP) file and add HTM
files to the project.
1. In the HTML Help Workshop window, Project tab, click Change Project Options.
2. In the Options dialog box, click in the Title field and enter AU 2016 Sample Help.
3. Click OK.
4. In the HTML Help Workshop window, Project tab, click Add/Remove Topic Files.
5. In the Topic Files dialog box, click Add.
6. In the Open dialog box, browse to and select the Topic1.htm, Topic2.htm, and
Topic3.htm files that are part of the dataset for this session. Click Open.
7. In the Topic Files dialog box, click OK.
8. In the HTML Help Workshop window, click File Save Project.
The following steps outline how to create a TOC for the help project.
1. In the HTML Help Workshop window, click the Contents tab.
Page 7
2. In the Table of Contents Not Specified dialog box, choose Create A New Contents File
and click OK.
3. In the Save As dialog box, browse to the location of the help project file and click Save.
4. In the HTML Help Workshop window, Contents tab, click Insert A Page.
5. In the Table of Contents Entry dialog box, General tab, click in the Entry Title text box
and enter Topic 1.
6. Click Add.
7. In the Path or URL dialog box, under HTML Titles, select Topic 1 and click OK.
8. Click OK.
9. In the HTML Help Workshop window, Contents tab, select Topic 1.
10. Click Insert A Page.
11. If the HTML Help Workshop message box is displayed, click No.
12. In the Table of Contents Entry dialog box, General tab, click in the Entry Title text box
and enter Topic 2.
13. Click Add.
14. In the Path or URL dialog box, under HTML Titles, select Topic 2 and click OK.
15. Click OK.
16. Select Topic 2 and click Move Selection Right.
17. In the HTML Help Workshop window, Contents tab, select Topic 2.
18. Click Insert A Page.
19. If the HTML Help Workshop message box is displayed, click No.
20. In the Table of Contents Entry dialog box, General tab, click in the Entry Title text box
and enter Topic 3.
21. Click Add.
22. In the Path or URL dialog box, under HTML Titles, select Topic 3 and click OK.
23. Click OK.
24. In the HTML Help Workshop window, Contents tab, select Topic 2.
25. Click Move Selection Right.
26. In the HTML Help Workshop message box, click Yes.
27. In the HTML Help Workshop window, click File Save Project.
The following steps outline how to add index entries to the help project.
1. In the HTML Help Workshop window, click the Index tab.
2. In the Index Not Specified dialog box, choose Create A New Index File and click OK.
3. In the Save As dialog box, browse to the location of the help project file and click Save.
4. In the HTML Help Workshop window, Index tab, click Insert A Keyword.
Page 8
5. In the Table of Contents Entry dialog box, General tab, click in the Keyword text box and
enter Main.
6. Click Add.
7. In the Path or URL dialog box, under HTML Titles, select Topic 1 and click OK.
8. Click OK.
9. Click Insert A Keyword.
10. If the HTML Help Workshop message box is displayed, click No.
11. In the Table of Contents Entry dialog box, General tab, click in the Keyword text box and
enter Sub, Topic 1.
12. Click Add.
13. In the Path or URL dialog box, under HTML Titles, select Topic 2 and click OK.
14. Click OK.
15. Click Insert A Keyword.
16. In the Table of Contents Entry dialog box, General tab, click in the Keyword text box and
enter Sub, Topic 2.
17. Click Add.
18. In the Path or URL dialog box, under HTML Titles, select Topic 3 and click OK.
19. Click OK.
20. In the HTML Help Workshop window, click File Save Project.
The following steps outline how to compile and view the help project.
1. In the HTML Help Workshop window, click File Compile.
2. In the Create A Compiled File dialog box, click Compile.
3. In Windows Explorer or File Explorer, browse to the location of the compiled CHM file.
4. Double-click the compiled CHM file.
5. Click through the items on the Contents and Index tabs.
Page 9
Most AutoLISP programs these days are not sold, but rather are used by end users within the
company they were originally developed or migrated with users when they switched companies.
Since most AutoLISP programs are not sold, they are written originally to work in a single
version of an AutoCAD-based product. For example, a program written for the English
language version of AutoCAD might not work correctly in the French language version of
AutoCAD. This isn’t done intentionally, but rather it wasn’t something most in-house developers
worried much about. The failure of the program doesn’t even address the issue of localized
prompt and error messages along with documentation.
The following are items could affect the deployment of your custom programs when supporting
multiple languages:
Use of the COMMAND function; commands and options need to use global syntax
Definition of custom commands with the DEFUN function
Macros assigned to user interface elements in a partially loaded CUI/CUIx file
Prompt strings, keywords, and error messages
Dialog boxes implemented using DCL
Documentation used to support the custom programs
Page 10
Commande: (getcname "LIGNE")
"_LINE"
Notice the _ (underscore) character that is returned in front of the _LINE value, the underscore
is used to let the AutoCAD program know you want to use a global command name instead of
the local command name. What is interesting about the GETCNAME function is that you can
pass the function a global command name and get the local command name back.
;; AutoCAD 2017 – English
Command: (getcname "_LINE")
"LINE"
Page 11
Commande: (command "_LINE" "0,0" "5,5" "5,0" "_C")
_LINE
Spécifiez le premier point: 0,0
Spécifiez le point suivant ou [annUler]: 5,5
Spécifiez le point suivant ou [annUler]: 5,0
Spécifiez le point suivant ou [Clore/annUler]: _C
Page 12
)
; Local command name for French
(defun c:Evaluer ( / )
(alert "Commande a commencé.")
)
; The user can enter
; EVALUATE or _EVALUATE
; EVALUER or _EVALUER
Note: Defining a command with a _ (underscore) might seem like a logical approach to
supporting global command names, but it doesn’t actually work that way. Command names
can’t start with an underscore, so the following approach is NOT valid:
Page 13
The AutoLISP function passed to the VLAX-ADD-CMD function can begin with the c: prefix, but
it is recommended to not define your functions with the prefix for those you plan on registering
as commands with the VLAX-ADD-CMD function. Defining a function with the c: prefix
registers the function as a local command in the language version, which isn’t always the
desired outcome.
For example, in the French language version, if you register an AutoLISP function named
C:EVALUATE with the VLAX-ADD-CMD function, the end user can directly type EVALUATE
and EVALUER at the Command prompt. The ideal situation would be to only have EVALUATE
accessible as a global command name by prefixing a _ (underscore) in front of the name.
Note: While you typically don’t need to worry about unregistering a command, it is possible to
reverse the process of the VLAX-ADD-CMD function. The VLAX-REMOVE-CMD function
unregisters the global and local command names for an AutoLISP function that was registered
using the VLAX-ADD-CMD function. The VLAX-REMOVE-CMD function expects a global
command name.
The following example unregisters the global and local command names associated with the
global command name EVALUATE:
;; Undefine/unregister a global and local command
(vlax-remove-cmd "evaluate")
Page 14
Students or professors from a local college or university who are studying or
teaching a foreign language. Those individuals might be willing to review the content
that was translated using an online service and make the necessary corrections, or
even manually perform the translations for a combination of pay and/or work
experience.
External company that specializes in the language translation.
Page 15
The product key of the current AutoCAD-based product can be obtained with the VLAX-
PRODUCT-KEY function. The last characters of the string returned by VLAX-PRODUCT-KEY
can be used to identify the language version of the product. For example, the value “409”
indicates the English version of the product is being used, while a value of “40C” indicates the
French version.
Note: The LOCALE system variable is related to language support, but at the operating system
level. You can use the LOCALE system variable to identify the locale info of the operating
system, is AutoCAD installed on an English or French version of Windows. The value assigned
to the LOCALE system variable is a three character string.
The following examples show the value returned by the VLAX-PRODUCT-KEY function in the
English and French versions of AutoCAD:
;; AutoCAD 2017 – English
Command: (vlax-product-key)
"Software\\Autodesk\\AutoCAD\\R21.0\\ACAD-0001:409"
Page 16
Access and display text strings based on language
As I previously mentioned, there are several different approaches to storing and displaying text
strings based on the language version of AutoCAD being used. The following is just one
approach which utilizes lists to store and organize translated strings.
The custom function named returnLocalizedString returns a translated text string
based on the current language version of the product; English or French. Each of the translated
strings that can be returned are stored in a list of dotted pairs. The function expects two strings,
program name and resource ID.
programName – Used to access strings stored in the function for a specific
command or utility. The program name is used as a way to organize the strings for
multiple applications.
resourceID – Used to get a specific string from the list.
The definition of the returnLocalizedString function is as follows:
;; Helper function that returns a resource string
;; based on language code
;; Usage: (returnLocalizedString "SAMPLE" 3)
(defun returnLocalizedString (programName resourceID /
languageCode)
Page 17
Command: (returnLocalizedString "sample" 3)
"White"
Page 18
to reliably create custom scripts and action macros, and use the commands you expose in
macros for custom user interface elements. From a programming stand point-of-view, you only
need to worry about handling the return of the global keyword names and not both global and
local keyword names.
The following shows the previous example statements used in a function named
PromptForKeyword:
;; Returns the three letter language code from the product key
(defun returnLanguageCode ( / )
(strcase
(substr (vlax-product-key)
(- (strlen (vlax-product-key)) 2)
)
)
)
Page 19
((= (returnLanguageCode) "40C")
(vlax-add-cmd "PromptForKeyword" 'PromptForKeyword
"InvitePourMotcle")
)
)
; English example - works
(command "_promptforkeyword" "B")
; French example - fails
(command "_promptforkeyword" "B")
; French example - works
(command "_promptforkeyword" "_B")
Note: The examples in this section can be found in the 3 - initget.lsp file that is part of the
dataset associated with this session.
Page 20
sharing such as Box, DropBox, and Google can be good alternatives to share files
with remote employees.
Creating an installer that handles the copying of files to a computer; this method is
often used when deploying programs to external companies, and can be the most
effective way to deploy programs. There are many different programs on the market
to create an installer, most have a cost associated with them. I have personally used
InstallShield (http://www.flexerasoftware.com/producer/products/software-
installation/installshield-software-installer/) which starts at $699 for Express and up
for the higher-end products, and Setup projects available in Visual Studio
Professional and higher.
Tip: The MS-DOS XCOPY command and RoboCopy utility can make it easy to synchronize
files on a local drive with those stored on a remote/network drive. RoboCopy can be download
as part of the Windows Server 2003 Resource Kit (http://www.microsoft.com/en-
us/download/details.aspx?id=17657) along with its companion utility Robocopy GUI at
https://technet.microsoft.com/en-us/library/2006.11.utilityspotlight.aspx.
After the program and resource files have been deployed to a local or network drive, the
program files can then be loaded into an AutoCAD-based product. The following outlines the
methods that can be used to load a program into an AutoCAD-based product:
Manually with the APPLOAD command (Load/Unload Application dialog box);
requires users to load the custom program files each time they are needed.
Automatically using the Startup Suite of the APPLOAD command; requires users to
add each custom program file to the Startup Suite, but only needs to be done once.
Automatically using the acad.lsp or acaddoc.lsp program files; the files must be
created and placed in a support file search path and trusted location, but the problem
with this approach is that an end user might already have these files on their
computer loading other AutoLISP programs.
Automatically using a CUI/CUIx file; add the LSP files to be loaded under the LSP
Files node of a loaded CUI/CUIx file. This is done by using the Customize User
Interface (CUI) Editor.
Automatically using a MNL file with the same name as a custom CUIx file that is
loaded as either a full customization file or a partial customization file. The MNL file
must have the same name as the CUI/CUIx file; for example, mytools.cuix and
mytools.mnl.
Automatically using a plug-in bundle; a plug-in bundle can be used to configure the
AutoCAD drawing environment and load AutoLISP programs when a drawing is
opened or created. Along with loading program files with a plug-in bundle, it is
possible to partially load a CUIx file as well.
Note: You can centralize the loading of multiple AutoLISP programs by defining a single
AutoLISP program file that end users load, this single program file the loads all other AutoLISP
files with the use of the LOAD function or loads the files on-demand when a command in that file
is used. The AutoLISP AUTOLOAD function is used to load an AutoLISP program file on-
demand when a command is used the first time. In addition to the AUTOLOAD function, a plug-
in bundle can also be used to automatically load an AutoLISP program file when a command is
used the first time.
Page 21
While having end users manually load program files can make deployment tasks easier for you,
it can be very problematic for them and lead to a support nightmare for you if something goes
wrong. No matter if you have your end users manually load the program files or if the files are
automatically loaded, you need to consider the following questions:
How will the end user specify the necessary support file search paths and trusted
locations to load and use your custom program and resource files? See “Specify
Support File Search Paths” and “Trust Executable Locations” for more information.
Should the source code contained in your custom program files be protected? See
“Compile and Protect AutoLISP Files” for more information.
Should the custom program files be digitally signed? See “Digitally Signing
AutoLISP Program Files” for more information.
Plug-in bundles make it fairly easy to deploy AutoLISP programs as you just need to distribute a
folder structure and the files contained in them. The folder structure organizes and contains all
the program and resource files needed, along with the information required to configure the
AutoCAD drawing environment. You can learn more about plug-in bundles under the “Build
Plug-in Bundles for AutoLISP Programs” section later in this handout.
Page 22
4. In the Browse for Folder dialog box, browse to and select the folder which contains
your custom programs and resource files.
5. Click OK to append the selected folder.
6. Optionally, add any additional folders that might be needed.
7. Click OK to save the changes and exit the Options dialog box.
Page 23
;; Append the new folder
(vla-put-SupportPath acPrefFilesObj
(strcat curACADPaths ";" folderName))
)
)
)
Note: The examples in this section can be found in the 5 - support paths.lsp file that is part of
the dataset associated with this session.
Page 24
In addition to the locations that are inherited or automatically trusted, you can specify other
trusted locations that might be on your local or network drive. Any locations that you manually
add should be read-only, otherwise it defeats the purpose of using trusted locations as a
security feature since the files could be manipulated by an external program to load and execute
malware within the AutoCAD program. You can specify additional trusted locations by using
one of these methods:
Options dialog box, Files tab; user profile can then be exported and imported on
other workstations
TRUSTEDPATHS system variable
AutoCAD installation deployment
Note: Custom programs must also be listed in a folder identified as a Support File Search Path
in order for the AutoCAD program to locate the files that can be loaded.
While trusted locations are optional, it is recommended to ensure your applications work
correctly under this environment and participate in this ecosystem to help reduce the risk in
which users might be exposed to malware. Even though the trusted locations feature can be
disabled or softened with the SECURELOAD system variable, it is recommended to never turn
the feature off; especially if you are releasing custom programs to external companies.
If a custom program or user attempts to load a custom program file from outside of a trusted
location, a task dialog box is displayed and it warns the user that the file doesn’t come from a
trusted source. The name of the custom program file and its location from which it is being
loaded is displayed to help the user determine whether it is safe.
Page 25
The message displayed does vary slightly based on the type of file being loaded and whether it
has been digitally signed.
Note: While it is possible to disable the use of trusted locations, it is recommended not to. As a
programmer, you should make sure your programs work correctly with SECURELOAD enabled
or disabled.
Trust subfolders
By default, the subfolders in a trusted location are not trusted. To trust the subfolders under a
trusted location, you must append the text \.. to the end of the location. When you append the
text \.. to a trusted location, the location is no longer trusted but the subfolders are trusted.
For example:
C:\My Programs\LSPs – Applications in the LSPs folder are trusted, but not those in
the subfolders
C:\My Programs\LSPs\.. – Applications in the subfolders of the LSPs folder are
trusted, but not those in the LSPs folder
Page 26
5. Click OK.
6. If the Trusted File Search Path – Security Concern message box is displayed, click
Continue.
This dialog box warns that the location is not read-only, it is recommended to
mark the location as read-only.
7. Optionally, add any additional folders that might need to be trusted.
8. Click OK.
Page 27
Note: The examples in this section can be found in the 6 - trusted locations.lsp file that is part of
the dataset associated with this session.
Page 28
Compile AutoLISP source files with Visual LISP
The following explains how to compile an AutoLISP program file into a FAS and VLX file:
1. In AutoCAD, on the ribbon, click Manage tab Applications panel Visual LISP Editor.
2. In the Visual LISP Editor, click File menu Make Application New Application Wizard.
3. In the Application Wizard, on the Wizard Mode page, select Simple and click Next.
Select Expert if you want to include DCL, TXT, and other resource files for your custom
programs in the compiled application.
4. On the Application Directory page, click Browse.
5. In the Browse for Folder dialog box, browse to and select the folder in which the FAS
and VLX files should be output when the AutoLISP source file is compiled.
6. Click in the Application Name text box and type the name of the application you want to
build. Typically, it is the same name as the AutoLISP source file to be compiled.
7. Click Next.
Page 29
8. On the LISP Files to Include page, click Add.
9. In the Add Lisp Source Files dialog box, browse to and select the AutoLISP source file to
compile. Click Open.
Page 30
8 Digitally Sign AutoLISP Program Files
Digital signatures are blocks of encrypted information that are often applied to program files by a
software vendor (also referred to as a publisher) to inform an end user whether a program file
has been modified after it was released. While a digital signature lets a user know if a program
file has been modified after it was signed, it doesn’t indicate whether the program file is safe to
load. When loading a program file, you should make sure the file was signed by a reputable
software vendor and that the digital signature is valid.
Note: Support for digitally signed program files is limited to AutoCAD 2016-based products and
later, and the Windows platform. Digital signatures are placed in comment blocks, so loading a
digitally signed program file in an AutoCAD 2015-based product or earlier shouldn’t cause any
problems.
While digital signatures are optional, it is recommended to digitally sign your custom programs
files if and when possible. As previously mentioned, it doesn’t ensure that the file is safe, but it
will help users identify whether a program file has been compromised by malware or someone
else that has access to your workstation.
Files that have been previously digitally signed can be identified in Windows Explorer or File
Explorer by a small badge displayed on the file icon.
The following types of program files can be digitally signed and loaded into an AutoCAD-based
product:
ARX, CRX, DBX
DLL, EXE
FAS, LSP, MNL, VLX
HDI
Page 31
Note: The digital certificates by IdenTrust were previously managed by GeoTrust and Symantec
(https://www.identrust.com/symantec/smime/index.html).
Digital certificates are not free, the cost varies based on the CA and the type of certificate you
need. If you are a software developer, you might want to obtain a Code Signing Certificate
which can be $300+ versus a Personal Authentication Certificate (PACs) that is around $20.
It is possible to make a digital certificate using the MakeCert.exe tool that is part of the Windows
SDK. The MakeCert.exe tool can be obtained from Microsoft's website at
http://msdn.microsoft.com/en-us/library/bfsktky3(v=vs.110).aspx. For the actual steps on
creating a digital certificate, search for the topic “To Make a Digital Certificate” in the AutoCAD
Online Help system (http://bit.ly/2e7IFCr). While you can make a digital certificate on your local
machine for testing purposes, you will still want to obtain a digital certificate from a CA before
distributing any signed application files. The CA holds a copy of the digital certificate so the
user can validate the signature attached to a program file.
Page 32
9. If the file being signed was previously signed, click Replace The Existing Signature to
overwrite the previous signature, or click Skip This File to not digitally sign the file.
10. In the Signing Complete message box, click OK to continue.
11. In the Attach Digital Signatures dialog box, click Close to exit the dialog box.
Note: If you need to digitally sign a Managed .NET DLL or ObjectARX application file, see the
topic “To Digitally Sign a Binary (ObjectARX or Managed .NET) File” in the AutoCAD Online
Help system (http://bit.ly/2ds1wcd).
4. When done reviewing the information associated with the digital signature, click OK
or Cancel.
Page 33
post them to the AutoCAD Exchange store. A plug-in bundle is a folder structure with an XML
manifest file that describes the organization of the files and their roles in the plug-in bundle to an
AutoCAD-based product. The name of the root folder for a plug-in bundle must end with
.bundle, and the XML manifest file for the plug-in bundle must have the name
PackageContents.xml and be located in the root folder.
Along with specifying the files that make up a plug-in bundle, the PackageContents.xml file can
also define:
Information about a plug-in bundle; name, description, version, author and more
Supported products and versions; OS, AutoCAD product platform, minimum and
maximum product release
Component entries (files) of the application; name, description, type, load reason and
per document
Commands; global and local names, help topics, and commands to execute at
startup
The most basic reason to create a plug-in bundle is to load one or more custom program files
when a drawing file is created or opened in the AutoCAD drawing environment, and to partially
load a customization file that contains user interface (UI) elements related to the custom
programs that the plug-in bundle loads. In addition to being able to indicate which custom
program and customization files should be loaded into an AutoCAD-based product, a plug-in
bundle can also set and modify:
Support file search paths
Tool palette paths
Registry key values
System and environment variable values
Plug-in bundles help to solve the issue of needing to manually modify settings in the AutoCAD
drawing environment to load custom programs. Most deployments of LSP files include
modifying the Startup Suite of the Load/Unload Applications dialog box or adding AutoLISP load
function statements to either the acad.lsp or acaddoc.lsp files along with specifying where the
support files for the custom programs exist.
Specifics about the XML syntax and elements that make up a PackageContents.xml file can be
found in the AutoCAD Help system by searching on the text “packagecontents.xml format
reference” (http://bit.ly/2ed6195).
Page 34
SeriesMax – Maximum AutoCAD-based release that is supported; 19.0 and later
including minor revision numbers (19.1, 19.2, …)
Platform – Controls which AutoCAD-based products the plug-in bundle supports;
“AutoCAD*” indicates AutoCAD and all AutoCAD-based vertical products are
supported
The following RuntimeRequirements element example indicates that the components in the
plug-in bundle are supported on Windows 32- and 64-bit, but not Mac OS and only supported
for AutoCAD 2015 and AutoCAD 2016.
<RuntimeRequirements
OS="Win32|Win64"
SeriesMin="R19.0"
Platform="AutoCAD*"
SupportPath="./ENU/Resources"
SupportPathFra="./FRA/Resources"
/>
Note: If no SeriesMax attribute is provided, the maximum release is every release after the
minimum release.
For information on all the allowable values by attribute, see the “RuntimeRequirements Element
Reference” (http://bit.ly/2eiuECO) topic in the AutoCAD Online Help system.
Page 35
Version="1.0"
ModuleName="./ENU/au2016.lsp"
ModuleNameFra="./FRA/au2016.lsp" >
</ComponentEntry>
Reminder: Locale suffixes are case-sensitive, FRA is NOT the same as Fra.
For a full list of supported locale suffixes, see the “Supported Locale Codes Reference”
(http://bit.ly/2ejamsP) topic in the AutoCAD Online Help system.
Along with specifying localized general properties and modules in a plug-in bundle with the
ApplicationPackage and ComponentEntry elements, it is possible to associate a help topic to a
local or global command based on language version. The following example shows how to use
the Commands and Command elements to associate a help and/or a specific help topic to the
global command names TAGBUBBLE, P3, and TB. A command can be registered with the
VLAX-ADD-CMD or DEFUN function. The topics in this example are part of the AU2016.chm
file assigned to the HelpFile attribute of the ApplicationPackage element. If you want more
control over which help file is associated to a command, you will want to use the SETFUNHELP
function in the AutoLISP program files in which the commands are defined.
<ComponentEntry Description="Additional examples"
AppName="AU2016AdditionalExamples"
Version="1.0"
ModuleName="./ENU/au2016ex.lsp"
ModuleNameFra="./FRA/au2016ex.lsp" >
<Commands GroupName="AU2016_SAMPLE">
<Command Global="TagBubble"
HelpTopic="Topic2"
Description="Creates a tag bubble"
DescriptionFra="Crée une bulle de balise" />
<Command Global="P3"
HelpTopic="Topic3" />
<Command Global="TB" />
</Commands>
</ComponentEntry>
If you assign a HTM/HTML file to the HelpFile attribute of the ApplicationPackage element, you
have some extra work to do if you want to display a different help topic for each command. The
URL opened when the user presses F1 contains the path to the HTM/HTML file assigned to the
HelpFile attribute and a parameter named contextId. The contextId parameter is follow4ed by
the value assigned to the HelpTopic attribute of the command. The following is an example of
the URL that is opened:
file:///C:/ProgramData/Autodesk/ApplicationPlugins/SD20507.bundle/
FRA/Help/index.html?contextId=Topic2.htm
The following is an example of an index.html file that does a basic parse of the URL for a
context Id and performs a redirect to the designated topic when a context Id is provided:
<!DOCTYPE html>
<html>
<head>
<title>HELP</title>
Page 36
<script type="text/javascript">
var URL = window.location.href;
var base = URL.split("?")[0];
var contextID = URL.split("=")[1];
if (contextID) {
window.location = base.replace("index.html", contextID);
}
</script>
</head>
<body>
<p>*REPLACE* - This main file shows how to do a redirect to a
specific topic when a valid context ID is provided.</p>
</body>
</html>
Here is an example of a plug-in bundle that utilizes HTM/HTML files instead of a CHM file for
help documentation:
<?xml version="1.0" encoding="utf-8"?>
<ApplicationPackage
SchemaVersion="1.0"
AppVersion="1.0"
Name="AU2016 SD20507"
Description="AU2016 Example for session SD20507."
DescriptionFRA="AU2016 exemple de session SD20507."
Author="Lee Ambrosius"
Icon="./Resources/AU2016_samp.png"
HelpFile="./ENU/Help/index.html"
HelpFileFra="./FRA/Help/index.html"
ProductCode="{45F619FE-E286-4C4E-8134-B50E8DFC23E3}"
>
<CompanyDetails
Name="HyperPics, LLC"
Url="http://www.hyperpics.com"
/>
Page 37
<ComponentEntry Description="Additional examples"
AppName="AU2016AdditionalExamples"
Version="1.0"
ModuleName="./ENU/au2016ex.lsp"
ModuleNameFra="./FRA/au2016ex.lsp" >
<Commands GroupName="AU2016_SAMPLE">
<Command Global="TagBubble"
HelpTopic="Topic2.htm"
Description="Creates a tag bubble"
DescriptionFra="Crée une bulle de balise" />
<Command Global="P3"
HelpTopic="Topic3.htm" />
<Command Global="TB" />
</Commands>
</ComponentEntry>
</Components>
</ApplicationPackage>
<CompanyDetails
Name="HyperPics, LLC"
Url="http://www.hyperpics.com"
/>
Page 38
AppName="AU2016Examples"
Version="1.0"
ModuleName="./au2016.lsp">
</ComponentEntry>
</Components>
</ApplicationPackage>
Note: The ProductCode value must be unique for each bundle that AutoCAD loads. You can
generate a GUID value by using the Online GUID Generator website
(http://www.guidgenerator.com/).
Page 39
Windows 10: Click the Windows Start button All Apps Accessories File
Explorer.
2. In Windows Explorer or File Explorer, navigate to the dataset folder for this session.
3. Click New Folder.
Page 40
6. Switch back to AutoCAD.
After about 5-10 seconds, you might see a balloon notification appear that your
bundle has been loaded; it doesn’t remain displayed on-screen for long though.
While the bundle has been loaded, the actual LSP files in the bundle aren’t
loaded.
This dialog box is displayed to let you know that the file hasn’t been digitally
signed.
10. At the Command prompt, type C2 and press Enter. Specify a point in the drawing
area.
11. Type DLI and press Enter. Specify two points to create the linear dimension.
12. Type ZX and press Enter to zoom to the extents of the drawing.
In these steps, you learn how to update the PackageContents.xml file for the SD20507.bundle.
1. In Windows Explorer or File Explorer, in the SD20507.bundle folder under
%ProgramData%\Autodesk\ApplicationPlugins, right-click the PackageContents.xml
file and choose Open With Notepad.
2. In Notepad, scroll down to the Components element and add the text in bold:
<Components Description="Windows and Mac OS operating
systems">
Page 41
<RuntimeRequirements
OS="Win32|Win64|Mac"
SeriesMin="R19.0"
Platform="AutoCAD*"
SupportPath="./"
/>
<ComponentEntry Description="Your custom file"
AppName="AU2016Examples"
Version="1.0"
ModuleName="./au2016.lsp">
</ComponentEntry>
<ComponentEntry Description="Additional examples"
AppName="AU2016AdditionalExamples"
Version="1.0"
ModuleName="./au2016ex.lsp">
</ComponentEntry>
</Components>
</ApplicationPackage>
3. In Notepad, on the menu bar, click File menu Save.
4. Close and restart AutoCAD; any changes to the open drawing can be discarded.
5. In AutoCAD, create a new drawing.
6. Click Load Once for each of the Security – Unsigned Executable File dialog boxes that
are displayed.
7. At the Command prompt, type TB and press Enter.
The title block t-blk should be inserted into the current space; if not, make sure the
location of the drawing file and dataset have been added to the Support File Search
Path. The folder of the dataset should be added as directed by the SupportPath
attribute in the plug-in bundle under the RuntimeRequirements element.
8. Type ZX and press Enter.
9. Type ZP and press Enter.
The previous view is restored.
10. Type TAGBUBBLE and press Enter. Type C and press Enter for the circle bubble and
then press Enter to accept the default text height of 3. Specify the center of the circle
and the end of the leader line.
Page 42
Consider implementing these techniques in the custom programs you develop:
Debugging and error logging
Function tracing
Catching and handling errors
Grouping changes with undo markers, so changes can be rolled back
The following sections expand on the previously mentioned troubleshooting and debugging
techniques, but for more information on debugging AutoLISP programs see my session
“DV1543 - Going on a Bug Hunt: Debugging and Handling Errors in AutoLISP®”
(http://au.autodesk.com/au-online/classes-on-demand/class-catalog/2013/autocad/dv1543) from
AU 2013.
Page 43
The following demonstrates how these functions can be used to help debug a program. The
code can be found in the 10 - debug - basic.lsp that is part of the files for this session.
; Load COM environment
(vl-load-com)
(princ acadObj)
(terpri)
(princ acadObj)
(terpri)
(prompt "Determine current space")
(terpri)
(princ spaceObj)
(terpri)
(prompt "Start object definition")
(terpri)
(princ cenPoint)
(terpri)
(princ circObj)
(terpri)
Page 44
(princ)
)
Note: The ERRNO system variable can be helpful in identifying the most recent error that
occurred when executing your custom program.
The following is based on a similar set of custom functions that I wrote a number of years ago
as an alternative to using just the PRINC function for debugging my custom programs. By using
a set of custom functions, it allowed me to echo values to the Command prompt, suppress the
echoing at release, or even allow me to run a program in a debug state without the user
knowing as it logs information out to a file. Then as part of the error handler, I could display the
information on-screen or even have it post the log file to a network location that I could
automatically pick up and review.
Note: The code shown can be found in the 10 - debug - custom.lsp file that is part of the data
set for this session.
; Global debugging variables
; *GLOBAL-DEBUG-LOGFILE* - Logfile name and location
; *GLOBAL-DEBUG-LOGGING* - Log enabled
; *GLOBAL-DEBUG-ENABLED* - Enable debugging (T or nil)
Page 45
)
(princ)
)
Function tracing
The AutoLISP functions TRACE and UNTRACE enable and disable the trace flag for a specified
function. When a trace is set for a function, you are notified at the Command prompt or in the
Visual LISP Editor Trace window when the function is used, along with the value that the
function was passed and the return/result of the function. This can be helpful in identifying why
a function might be failing.
The syntax for the TRACE and UNTRACE functions are:
(trace function)
(untrace function)
The following demonstrates the use of the TRACE and UNTRACE functions.
Note: The code shown can be found in the 10 - trace and untrace.lsp file that is part of the
data set for this session.
(defun OddOrEven (cnt / )
(if (= (rem cnt 2) 1)
"ODD"
Page 46
"EVEN"
)
)
(trace OddOrEven)
(defun c:TraceUntrace ( / )
(setq cnt 10)
Catch errors
For many, myself included for years, catching errors is commonly done using a general error
handler, but a general error handler is kind of like using a sledgehammer for something that
might only need a small nudge. When Visual LISP was first introduced back in AutoCAD 2000,
it came with a new and more elegant way of handling errors right inside of your main function
without utilizing a generic error handling function. The functions that Visual LISP introduced for
catching errors were:
Page 47
VL-CATCH-ALL-APPLY – Returns the results of a function or an error object that
contains information about the error caused within the function.
Syntax: (vl-catch-all-apply ‘function list)
VL-CATCH-ALL-ERROR-MESSAGE – Returns a text string based on an error object
returned by the VL-CATCH-ALL-APPLY function.
Syntax: (vl-catch-all-error-message err-object)
VL-CATCH-ALL-ERROR-P – Identifies if an error object is returned by the VL-CATCH-
ALL-APPLY function.
Syntax: (vl-catch-all-error-p symbol/expression)
The following example demonstrates the use of the VL-CATCH-ALL-APPLY, VL-CATCH-ALL-
ERROR-MESSAGE, and VL-CATCH-ALL-ERROR-P functions.
Note: The code shown can be found in the 10 - catch error.lsp file that is part of the data set
for this session.
; Example shows how to work with the Description property of a
Layer.
(defun c:layerDescription-WithCatch ( / acDoc acLayer acLayers
strLayerName
strLayerDesc)
; Check to see if the Visual LISP ActiveX
; functions have been loaded
(if (/= (type vlax-get-property) 'SUBR)(vl-load-com))
Page 48
; Change the Description for the Layer
(vlax-put-property
(vla-item acLayers strLayerName) 'Description
strLayerDesc)
)
(progn
(prompt (strcat "\nerror: "
(vl-catch-all-error-message err)))
(setq strLayerName "")
)
)
)
(princ)
)
Page 49
; Custom error handler for utility function
; Utilizes the command-s function.
(defun err_sub (msg)
(if (/= msg "Function cancelled")
(prompt (strcat "\nError: " msg
"\nUtilVar1: " *gVar1*
"\nUtilVar2: " *gVar2*)
)
)
Page 50
)
Page 51
Note: The code shown can be found in the 10 - VLX-exit-with.lsp and 10 - VLX-exit-with.prv
files that is part of the data set for this session.
(vl-doc-export 'func1)
(defun func1 (val)
;; Custom error handler with exit text
(defun *error* (msg)
(vl-exit-with-error "Oh no!")
)
(vl-doc-export 'func2)
(defun func2 (val)
Page 52
(command "._undo" "_group")
(command "._line" (list 0 0) (list 5 5) (list 0 5) "")
(command "._circle" (getvar "lastpoint") 1)
(command "._undo" "_e")
(princ)
)
Page 53
(command "._undo" "_be")
(command "._line" (list 0 0) (list 5 5) (list 0 5) "")
Page 54
find classes at a local technical college/university or an Autodesk Authorized Training
Center (ATC) that can help you extend your skill set.
Internet – There are tutorials on the Internet that can be helpful to learn many of the
customization and programming options supported in the AutoCAD program. Use
your favorite search engine, such as Google or Bing and search on the topic of
interest.
Blogs – There are several AutoCAD bloggers on the Internet that post articles and
best practices for AutoLISP and other programming languages that can be used to
extend AutoCAD. The Autodesk sponsored blogs can be found at:
http://www.autodesk.com/blogs, while my personal blog can be found at
http://hyperpics.blogs.com/.
Books – There are many general and specialized books that cover AutoCAD
customization and programming. To find a book, use amazon.com or
barnesandnoble.com to locate a book online or visit your local Barnes and Noble
store. My latest book, AutoCAD Platform Customization: User Interface, AutoLISP,
VBA, and Beyond, covers all of the customization options mentioned in this session
and many more.
Page 55