AutoLISP: Wrapping AutoCAD Commands
February 21, 2025
Presented by: Jeremiah Farmer
Length: 1:00:24
Among the most powerful aspects of AutoLISP is its ability to call AutoCAD commands and even to process code while a command is active. This feature allows a developer to make custom wrappers for CAD commands that include abbreviated options, automated calculations, toggling of system variables, and more. Join Land F/X CEO Jeremiah Farmer as he shares his 30 years of experience in our fourth installment of exploring the hidden power of the programming language AutoLISP.
Attachment: LISP Files
Webinar Contents:
Note: The following catalog of content covered in this webinar is time stamped to allow you to follow along or skip to sections of the video that are relevant to your questions. You can also search for content on this page using the FIND command in your browser (CTRL + F in Windows, Command + F in Mac OS.)
- Intro/TOC
- What Is "Wrapping AutoCAD Commands"?
- Basic Wrapping
- Toggle Settings
- Tips
0:00 – 3:53: Intro/TOC
3:54 – 7:09: What Is "Wrapping AutoCAD Commands"?
- Many AutoCAD commands can have multiple/difficult command options.
- Recall that AutoCAD used to not require a mouse.
- AutoLISP can not only fire commands but can run code while a command is active.
- Allowing us to make custom commands that are easier to remember and use, process input before sending to the command, toggle system variables mid-command, etc.
- Make CAD yours!
7:10 – 15:42: Basic Wrapping
- Simply making a keyboard shortcut to a complex command.
- Using AUTOLISP to set variables and filenaming automatically.
- Always prefix commands and options with underscore (_) and period (.) to force English language support and default command.
15:43 – 37:56: Toggle Settings
- Use (Getpoint) and pre-process points.
- Toggle system variables while command is active.
Example: GETPLIST (23:14)
Example: XCOPY (29:39)
37:57 – end: Tips
- Account for command failing
- (getvar "CMDACTIVE")
- Compare (entlast) to previous
- Command line prompts can vary
- System variables EXPERT and DELOBJ
- Confirmations if block/file exists
- Points must be translated to UCS
- Be wary of OSNAPs, ORTHO, etc.
- Be mindful of pressing ESC
- Resetting variables, deleting objects
Command vs. Command-S vs. VLCMDF (46:33)
(command):
- Most flexible.
- Requires attention to validating parameters and checking if command failed.
- Not compatible with Zoom.
(command-s):
- Requires AutoCAD 2015+.
- Each call is its own subroutine.
- Can be called from error handler.
- Best when requiring a Zoom.
(vl-cmdf)
- Evaluates all arguments first.
- Nicely quiet. Jeremiah likes it for operations like SAVEAS and XREF.
Confirmation Box (52:36)
- Just a simple Yes/No confirmation box makes your command wrappers pop.
- All that is necessary is the OpenDCL Runtime: opendcl.com/download
Other dialog boxes (example: Scale by Reference) (55:43)