Tuesday, April 25, 2006

Kitchen LISP

Last week we looked at editing the ACAD.PGP to create command aliases. However, PGP defined command aliases are limited; they cannot call command options, prompt for user input, or make decisions. For instance, you couldn't define an alias for Zoom Previous in the ACAD.PGP. Using AutoLISP for command aliases is like the ACAD.PGP on steroids. LISP can pass options to a command, make decisions, and pause for user input.

Create your own LISP shortcut library file and add it to your Startup Suite using the APPLOAD command. You can create this file with Notepad, just make sure that Notepad's Save as type drop down is set to All files instead of Text Documents (*.txt), or Notepad will add a .TXT extension to your new file. You can also create/edit your user LISP file with AutoCAD's built-in LISP editor by typing VLISP at the command line.

LISP syntax can be baffling, but command aliases are relatively easy to master. To define ZP as the command alias for ZOOM Previous, the syntax would be:

(defun C:ZP () (command ".ZOOM" "P"))

In this example we define a function (defun) ZP, the C: prefix means that the function can be used as an AutoCAD command. The (command) function passes "ZOOM" and the "Previous" option to the AutoCAD command line. Now you can type ZP at the command line for ZOOM Previous. Define additional command aliases similarly. Pay attention to the location of opening and closing parenthesis and use quotes as shown.

More Examples:

; Type "ZE" to ZOOM Extents plus a bit more
(defun C:ZE ()

(command ".ZOOM" "E" ".ZOOM" "0.95x"))

; Type "LE" to LENGTHEN with the Dynamic option
(defun C:LE () (command ".LENGTHEN" "DY"))


; Type "STR" to STRETCH with the

; Crossing Polygon option
(defun C:STR () (command ".STRETCH" "CP"))


; Type "FD" to toggle ON/OFF the gray
; background display of Fields
; this bit of code shows more of the power
; of AutoLISP. Reading it backward, we use
; (getvar) to get the current value of the
; FIELDDISPLAY system variable, then we
; subtract 1 with function (1-), take the
; absolute value with (abs), and finally
; pass the result to (setvar) to set the
; new value.
(defun C:FD ()
(setvar "FIELDDISPLAY"
(abs (1- (getvar "FIELDDISPLAY")))))


Notice the explanatory comments in the code. AutoLISP ignores text following a semi-colon.

There's virtually no limit to the amount of customization you can include in your personal LISP file. For more information on LISP functions and syntax, see the Developer Help under Additional Resources of the AutoCAD Help menu.

Thursday, April 20, 2006

Keyboard Shortcuts

The ACAD.PGP (AutoCAD Program Parameters) loads with every AutoCAD session. This file defines keyboard aliases for AutoCAD commands and Shell commands. It typically loads from "C:\Documents and Settings\<username>\Application Data\Autodesk\AutoCAD 2006\R16.2\enu\Support\acad.pgp", where <username> is your login name.

What if you don't like the default keyboard aliases as shipped with AutoCAD? Say you want to change "C" to be COPY rather than CIRCLE. You can modify the PGP file with your favorite text editor, like Notepad, or you can use the Express Tool ALIASEDIT to modify the default aliases:

Pull down menu: Express > Tools > Command Alias Editor...
Command: ALIASEDIT

On the Command Aliases tab, scroll down to C (CIRCLE) and click the Edit button (figure 1.) Enter COPY, or scroll to the COPY command, and click OK (figure 2.) Save and let AutoCAD reload the ACAD.PGP when prompted. Now, entering C from the keyboard executes command COPY instead of CIRCLE.

Tuesday, April 11, 2006

WYSIWYG Mtext Editor

The AutoCAD 2006 Mtext Editor is finally a truly "what you see is what you get" editor. But, what else can it do? Answer: Indents, hanging indents, and with this comes bullets and numbering.

Use the ruler to place or modify your tabs and indents, similar to how you would do it in Word. Right-click in the editor to control the appearance of the bullets, numbers or letters.

So what are the drawbacks to the WYSIWYG editor? Well for one thing, it can be disconcerting to edit Mtext that is not at a zero rotation.

If you find it difficult to edit rotated text, you can revert to the old Mtext editor by setting the system variable MTEXTED to "Oldeditor." However, you then lose the ability to use the indents, bullets, and numbering. To regain this functionality, set MTEXTED back to "." (internal editor.)

Bonus: AutoCAD 2007 uses the system variable MTEXTFIXED=2 to edit too small, too large, or rotated text in a horizontal orientation at a reasonable size, giving us the best of both worlds.

Thursday, April 06, 2006

emoving the Pefix fom adial Dimensions

By default, AutoCAD prefixes Radius and Diameter dimensions with an "R" and a "Ø" symbol respectively. If you do not wish to include these symbols in your dimension string, use a null character as your prefix.

Pull down menu: Dimension > Dimstyle...
Command: DIMSTYLE

In the Dimension Style Manager, select the Dimstyle you wish to modify and click the Modify... button. In the Modify dialog go to the Primary Units tab and enter a Left Curly Brace "{" as the Prefix, and click OK. This prefixes all of your dimension text with nothing, including your Radius and Diameter dimensions whose default symbols are replaced with nothing.

If you know why a left curly brace works as a null character in dimension text, you're truly an AutoCAD aficionado. However, this is not necessarily a good thing. It won't even help you get dates.