Tailoring Cad Manual
Tailoring Cad Manual
u p f r o n t . e z i n e p u b l i s h i n g , l t d .
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
On CD in Acrobat PDF format: US$24.95 (incl. shipping). Allow 1-2 weeks to arrive.
By email in PkZIP/Acrobat PDF format: US$19.95. Allow for a 5MB download.
Print copy: US$29.95 (incl. shipping). Allow 4-6 weeks to arrive.
The CD and print copy are normally delivered by mail, with shipping cost included.
Delivery by FedEx for CD or print copy: add US$18 - CDN$25 - £10.
"Tailoring AutoCAD"
34486 Donlyn Avenue
Abbotsford BC
V2S 4W7 Canada
PayPal
• To the account of [email protected] at www.paypal.com. You can copy and paste the following URL into
your browser: https://www.paypal.com/affil/pal=ralphg%40xyzpress.com.
PayPal accepts funds in US, Euro, Yen, and Canadian currencies.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1: introduction to customizing . . .1
The Many Ways of Customization . . .3
Which Customization? . . .4
Shortcut Tips . . .4
Placing Arcs . . .4
Placing Text . . .4
Replacing Text . . .4
Update for AutoCAD 2000 . . .4
Which Font? . . .5
Plot Optimization . . .5
Template Drawings . . .5
Fast Custom Drawing Sheets . . .5
Collapsing Multilines . . .6
Changing Layers . . .6
Quick Trim . . .6
Aerial View . . .6
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
/c Switch . . .12
/p Switch . . .12
/r Switch . . .12
/s Switch . . .13
/t Switch . . .13
/v Switch . . .13
Colors . . .14
UCS Icon . . .15
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
5: linetypes . . .55
Commands Affecting Linetypes . . .55
Text . . .61
Text Style . . .61
Text Scale Factor . . .61
Text Rotation Angle . . .61
Text Orientation . . .61
Text Offset Distance . . .62
Embedding a Shape . . .62
3D Linetypes . . .62
A Parallel Linetype . . .63
Alternatives to the Parallel Linetype . . .65
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Toolbars, Accelerator Keys, Image Tiles, Tablet Overlays, and the Screen Menu . . .87
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
. . .99
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Script . . .115
RScript . . .115
Resume . . .115
Delay . . .115
Special Characters . . .115
(space) . . .115
; (semicolon) . . .116
* (asterisk) . . .116
Backspace . . .116
Esc . . .116
$(func)?? . . .121
$(func,??) . . .121
$(++) . . .121
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
[ . . .123
$(if, . . .123
$(getvar,dimaso) . . .123
,!. . . .123
) . . .123
] . . .124
'_dimaso . . .124
$M= . . .124
$(-,1, . . .124
$(getvar,dimaso) . . .124
) . . .124
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
i f, like me, you’re a messy sketcher, then you appreciate how computer software makes your work neater. For
too many drafters, that’s all AutoCAD amounts to: a neater drafting machine.
The real power behind CAD (computer-aided design), however, is its ability to be customized to the way you
work. Customize is jargon for letting CAD do some of the drafting for you. This ranges from placing a linetype
specific to your discipline, to generating a 3D staircase to fit between two floors, and more.
The benefit? You get your work done is less time, or, if you are a free-lancer, you get more work done in the
same time.
The drawback to customizing is that it takes bits of time. First, you need to take a bit of time to learn how to
customize AutoCAD — that’s what this book is all about. Then, you need a bit more time to create the customization.
Time isn’t something most professionals have a lot of. I sometimes find myself doing a repetitive editing function
under the false belief that it takes longer to write (and debug) a macro than it would automating the task. So, I have
this rule-of-thumb:
Write a macro when the same action is repeated more than three times.
There lies the responsibility of Autodesk to make automation easier for the end-user. Still, the time you invest in
automation makes you a more productive AutoCAD user, even in the short run.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Which Customization? . . .4
Shortcut Tips . . .4
Placing Arcs . . .4
Placing Text . . .4
Replacing Text . . .4
Update for AutoCAD 2000 . . .4
Which Font? . . .5
Plot Optimization . . .5
Template Drawings . . .5
Fast Custom Drawing Sheets . . .5
Collapsing Multilines . . .6
Changing Layers . . .6
Quick Trim . . .6
Aerial View . . .6
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
ADI Autodesk Device Interface and plotting formats (replaced by HDI in AutoCAD 2000).
ADS AutoCAD Development System (no longer available as of AutoCAD 2000).
ARX AutoCAD Runtime Extension (also known as ObjectARx) for C++ programming.
ASI AutoCAD SQL (structured query language) Interface for database programming.
DCL Dialog Control Language for customizable dialog boxes.
DDE Dynamic Data Exchange for linking with other software.
DIESEL Direct Interpretively Evaluated String Expression Language (see Chapter 10).
DWG DraWinG; create custom symbols and user-defined objects.
DWT DraWing Template; preset drawing elements (see Chapter 2).
DXB Drawing Interchange Binary.
DXF Drawing Interchange Format.
DXFIX Drawing translation (no longer available as of AutoCAD 2000).
HLP, AHP Customizable help (no longer available as of AutoCAD 2000).
INI Toolbar macros and INItialization files (no longer available as of AutoCAD 2000).
LIN Customizable LINetypes (see Chapter 6).
LSP AutoLISP (see Chapter 11).
MNU Customizable menu and tablet, popdown, cursor, and icon menus (see Chapter 5).
OLE Object linking and embedding with other software.
PAT Customizable hatch PATterns (see Chapter 7).
PGP ProGram Parameter files.
RPF Raster Pattern Files.
SCR Script files (see Chapter 9).
SHP,SHX SHaPes and customizable text fonts (see Chapter 8).
SLD, SLB SLiDes and Slide LiBraries.
VBA Visual Basic for Applications.
VLISP Visual LISP.
Plus a host of miscellaneous support and data files that can be edited:
... and more. You find many of these files in AutoCAD’s \support folder.
Some customizations are designed for end-users, such as toolbar macros, menus, and AutoLISP routines, all of
which we look at in this book. Others are meant for professional programmers, like ASI and ObjectARx, which
we ignore. In between the two levels, there are other customization possibilities, such as hatch patterns and DIE-
SEL programming, that some enthusiastic users enjoy tinkering with. We look at these as well.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Shortcut Tips
Sometimes working more efficiently doesn’t involve customizing, but having a greater understanding of AutoCAD’s
details. To get you started on the road to greater productivity, here are some time-saving tips that don’t involve
customizing:
Placing Arcs
AutoCAD provides you with eleven different ways to draw an arc. Sometimes, placing an arc becomes an exercise
in frustration, particularly when an angle is involved. The easier alternative is to draw a circle, then use the Trim
or Break commands to convert the circle to an arc.
Placing Text
When you need to place bits of text all around the drawing, use the DT
DTeext command. This versatile command sets
text in the drawing wherever you place the cursor. Caution: When you are finished placing text, do not press Esc
(or Ctrl+C in older versions of AutoCAD) because you will loose all entered text. Instead, press Enter twice to
terminate the DT
DTeext command.
Replacing Text
When you need to add similar text in a number of drawings, it is easier to place the same block of text in each
drawing. Then use the DdEdit command to change wording of the text. Editing text is easier than placing new
text, since all parameters have already been set, such as text style, heights, justification, and so on.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Plot Optimization
(R14 and earlier.) The Plot command’s dialog box lets you select from seven levels of plot optimization. While any
is faster than level 0 (no optimization), don’t assume that a higher number always results in a faster plot. In
particular, levels 5 and 6 (eliminating overlapping vectors) really slow down a pen plotter. For monochrome
plotters, the plot slows down when you go beyond level 1 (endpoint swap).
Template Drawings
(R13 and later.) To help you get started faster on new drawings, AutoCAD includes template drawings with system
variables preset for the related standard. (Prior to R14, template drawings were known as prototype drawings.)
Some of the .dwt template drawings found in AutoCAD’s \template folder are:
In older versions of AutoCAD, the templates are found in \common\support or \support folders:
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Changing Layers
Quicker than the Layer commands, simply click on the down arrow next to the layer name on the toolbar. That
action displays a list box of layer names in the drawing. Click on the name of the layer you want to switch to.
For keyboard-ists, use the CLayer command, which bypasses all of the Layer command’s options.
Quick Trim
To precisely trim back a pair of intersecting lines, use the Fillet command with radius set to zero.
Aerial View
(Undocumented in Release 13 for DOS.) The AV command, which displays an Aerial View window, just like in the
Windows version. The Aerial View window lets you zoom and pan at near-instant speed.
Feedback
I welcome your feedback for correcting and improving the text. Send your email to [email protected] .
Visit the Tailoring AutoCAD e-book Web site at www.upfrontezine.com/tailor.
For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
a utoCAD allows you to change the way it looks and works. The first few of these chapters concentrate on
changing the look of AutoCAD; later chapters on changing the way it works.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
/c Switch . . .12
/p Switch . . .12
/r Switch . . .12
/s Switch . . .13
/t Switch . . .13
/v Switch . . .13
Colors . . .14
UCS Icon . . .15
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
It was common knowledge in the days of the DOS operating system that there were additional options for starting
AutoCAD. With Windows hiding much of what goes on behind its graphical user interface, command-line switches
are no longer in common use. Command-line switches are useful for changing the way AutoCAD operates. The
switches tell AutoCAD what to do when it starts:
Switch Comment
TIP Command-line switches override settings in the Options dialog box and the values
set by environment variables.
1. On the desktop, right-click the AutoCAD icon. Notice the shortcut menu.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
In the Target text box, notice that the command-line text reads something like the following:
"C:\CAD\AutoCAD 2002\acad.exe"
The path (C:\CAD\AutoCAD 2002\) may be slightly different for your system; that does not matter. The
quotation marks are necessary when the command line contains spaces.
4. Edit the text in the Target box. For example, to change the path to the \support and \dwgs folders, you would
enter the following (I’ve shown the changes in boldface, and the switch in cyan):
"c:\cad\autocad 2002\acad.exe /s c:\support;c:\dwgs"
/s
/s), and that a semicolon ( ; ) is needed when the switch
Notice that a space is required after the switch (/s
specifies more than one path.
Here is another example: the following command-line starts AutoCAD with a script file called script.scr:
"c:\cad\autocad 2002\acad.exe /b c:\autocad 2002\support\script.scr"
5. When done editing the target, click OK to close the dialog box.
6. Anytime you complete a customization, you must test that it works. Double-click the icon, and AutoCAD
should start as you instructed with the switch. If it doesn’t work correctly, the most likely reason is that you
made a spelling mistake. Repeat the steps listed above until it does work correctly.
TIP You can have several shortcut icons on your computer’s desktop, each with a
different set of command-line parameters. To make copies of icons, drag an icon while
holding down the Ctrl key. To rename the icon, right-click and select Rename.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The /b switch specifies the name of a .scr script file to run immediately after AutoCAD starts. See Chapter 9 to
learn how to write a script file. Example usage:
"c:\cad\autocad 2002\acad.exe /b c:\autocad 2002\script.scr"
/c Switch
The /c switch specifies the path to a .cfg hardware configuration file. The switch can point to a specific .cfg file or to
a folder. If a folder, then the filename in the folder must be acad2002.cfg (or equivalent for the release of AutoCAD
you are using). Example usage:
"c:\cad\autocad 2002\acad.exe /c c:\autocad 2002\support\myconfig.scr"
Usually, AutoCAD is started without the /c switch; instead, it uses the AcadCfgW and AcadCfg environment
variables to search for a .cfg file. If these variables are not set, AutoCAD searches the folder in which acad.exe is
located. If the acad2002.cfg file does not exist, AutoCAD creates one using default values. See /r switch.
/nologo Switch
The /nologo switch starts AutoCAD without its logo. Example usage:
"c:\cad\autocad 2002\acad.exe /nologo"
Some people find the logo irritating because it covers up other windows for a few seconds. In AutoCAD 2002, the
logo looks like this.
/p Switch
The /p switch specifies a named profile to use with AutoCAD. Profiles are created with the Options | Profiles
Profiles
dialog box, and are discussed later in this chapter. Example usage:
"c:\cad\autocad 2002\acad.exe" /p "my profile"
/r Switch
The /r switch restores the acad2002.cfg configuration file to its default values. The existing configuration file is
renamed acad2002.bak. This switch is useful when AutoCAD’s hardware configuration gets mucked up. Ex-
ample usage:
"c:\cad\autocad 2002\acad.exe /r"
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The /s switch points to the folder(s) holding support files, such as menu, font, and linetype files. You can specify
as many as 15 support folders. Separate each folder name with a semicolon ( ; ). Example usage:
"c:\cad\autocad 2002\acad.exe /s c:\autocad 2002\support\;c:\alisp"
Usually, AutoCAD starts without the /s switch; instead, it reads the folder(s) specified by the Options | F iles
Files
dialog box. AutoCAD also consults the path specified by the Path environmental variables in the AutoExec.Bat file.
/t Switch
The /t switch specifies the drawing file to use as a template on which to base new drawings. When a template is not
specified, AutoCAD uses the acad.dwg file as its template. Example usage:
"c:\cad\autocad 2002\acad.exe /t c:\autocad 2002\template\Architectural Title Block.dwg"
/v Switch
The /v switch specifies a named view to display when AutoCAD opens. When a view is not specified, AutoCAD
opens the drawing with the view last saved. Example usage:
"c:\cad\autocad 2002\acad.exe /v titleblock"
TIP The /s and /t switches are useful for customizing AutoCAD to the needs of
different clients.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Colors
A change in AutoCAD you may want to make right away is the background color of the drawing area: from black
to white. Black was the traditional color in the days when CAD ran on the DOS operating systems; some users
continue to prefer black because colors look more vibrant against it. To change the colors of the AutoCAD win-
dow, follow these steps:
3. In the Display tab, click the Colors button. Notice that the Color Options dialog box has two parts: on the
left for the model tab, and on the right for all layout tabs.
• Model T ab Background sets the background color of the drawing area in model space.
Tab
• Model T ab P
Tab ointer sets the color of the crosshair cursor (pointer) in model space.
Pointer
• Layout T abs Background (P
Tabs aper) sets the background color of the drawing area in all layouts.
(Paper)
• Layout T abs P
Tabs ointer sets the color of the crosshair cursor (but not the pointer cursor) in model space.
Pointer
• AutoT racking V
utoTracking ector Color sets the color of tracking vectors, the temporary construction lines that appear
Vector
while drawing, showing geometric relationships.
• Command Line Background sets the background color of the ‘Command:’ prompt area.
• Command Line T Teext sets the color of text in the ‘Command:’ prompt area.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The color and size of the UCS (user-defined coordinate system) icon is changed with the UCSicon command’s
Properties option. From the menu bar, select View | Display | UCS Icon | P roperties
Properties
roperties, or enter the command at
the prompt, as follows:
Command: ucsicon
Enter an option [ON/OFF/All/Noorigin/ORigin/Properties] <ON>: p
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP The UCS icon is meant to aid your view orientation during 3D design. If your
drafting is primarily 2D, there is no need to display the icon. Turn it off witih the UCSicon
command’s OFF option.
Keyboard Shortcuts
You can create keyboard shortcuts for executing commands. For example, you can assign commands to function
keys. See Chapter 3 for details.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
3. To use a profile, select its name from under the list of Available profiles
profiles, and then click Set Cur rent
Current
rent.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP Use the Profiles feature to save and switch between different AutoCAD settings.
Specifies the path to the folders in which AutoCAD searches for support files. AutoCAD also searches the path(s)
defined by the Path environment variable in the autoexec.bat file executed when Windows starts up.
Specifies the path to folders in which AutoCAD searches for device drivers. Device drivers are programs that
interface between AutoCAD and hardware, including the graphics board, mouse, digitizing tablet, plotters, and
printers.
Specifies project names, which contain search paths for externally-reference drawings; also stored in system variable
ProjectName
rojectName.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Specifies the names and paths for menu and help files, as well as the default URL (uniform resource locator, a.k.a.
Web address). The URL is used by the Browse command.
Also specifies the path to the .cfg configuration file, which stores information about the hardware used with
AutoCAD. (Note that this value cannot be changed here; it can only be changed by the /c command-line switch.)
Also, the list of client license servers (as stored in system variable AcadSer ver
cadServer
ver; also read-only).
Specifies the name of .plt temporary plot files used with R14 (or earlier) plotting scripts. The name of the applica-
tion to use for external plot spooling in this format:
spooler.bat %s
Specifies the path for printer support files, print spool files, and .pc3 printer configuration files, .pmp printer
description files, and .stb and .ctb named and color-dependent plot style tables.
Specifies the path for ObjectARX application files; separate multiple paths with a semicolon. Path must be writ-
ten, curiously enough, in URL format, such as:
file://C:\CAD\AutoCAD 2002\Sample
Specifies the path for storing automatic backup files (stored in system variable SaveFileP
SaveFilePath
ilePath
ath).
Specifies the path to database source files, used by the database-related commands in AutoCAD. Caution: The
change you make to this setting takes effect only after you close and restart AutoCAD.
Specifies the path to the .log log file created by the LogfileOn command (stored in system variable LogfilePath
ogfilePath
ath).
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Specifies the path to the folder in which AutoCAD stores its temporary files, which are deleted when AutoCAD is
exited properly (stored in system variable TempP refix
empPrefix
refix). If AutoCAD crashes, these temporary files are often left
behind, and can be safely erased.
Specifies the path for temporally storing externally-referenced files (stored in system variable XL oadP
XLoadP ath
oadPath
ath).
Specifies the path in which texture maps are stored for rendering.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
AutoSnap Settings
For AutoSnap, you have the option of changing:
• Toggle (turn on and off) the display of the marker, magnet, tootip, and aperture box.
• Color of the marker.
• Size of the AutoSnap marker, and of the aperture box.
Grips Settings
For grips, you have the option of changing:
• Size of the pickbox and the grip size.
• Color of unselected and selected grips.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
t he best-known way to run commands in Windows programs is from their menus and toolbars. But power
users know that the keyboard is the fastest method for entering commands. Once you memorize them, shortcuts
— such as Ctrl+C, Alt- Tab, Ctrl+V that copy to the Clipboard, switch to another application, and then paste —
Alt-T
let you work at top speed. AutoCAD has two facilities for creating your own shortcut keystrokes:
• The Options dialog box’s Keyboard tab assigns function keys and Ctrl Shif
Shiftt/Alt
Ctrl/Shif Alt
Alt-key combinations to any
command.
• The acad.pgp file lets you define aliases, which are one- and two-letter command mnemonics, such as L for
the Line command, and AA for the Area command.
This chapter includes tutorials for employing both facilities in your drafting work.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
• Function kkeys
eys are those keys marked with the F prefix, such as F1 and F2 F2.
• Control kkeys
eys operate by holding down the Ctrl key, and then pressing a function, number, or alphabet key,
such as CTRL+F2 and CTRL+B CTRL+B.
• Shif ted function kkeys
Shifted eys operate by holding down the ShifShiftt key, and then pressing a function key.
• Control + Shif
Shiftt kkeys
eys operate by holding down both the Ctrl and Shif Shiftt keys, and then pressing a function,
number, or alphabet key.
• Control + Alternate kkeys eys operate by holding down both the Ctrl and Alt keys, and then pressing a number
or alphabet key.
• Control + Alternate + Shif Shiftt kkeys
eys operate by holding down the Ctrl and Alt and Shif Shiftt keys, and then
pressing a number or alphabet key.
Out-of-the-box, AutoCAD defines a number of shortcut keys, as shown below. You can, of course, add and
change definitions, ultimately assigning commands to as many as 188 key combinations. (Don’t worry, you won’t
run out of commands to assign: AutoCAD has over 300 commands!)
Only commands can be assigned, not macros (multiple commands), nor the options of commands. For ex-
ample, you can assign the Zoom command, but not the Zoom W indow command-and-option.
Window
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. From the Categories list, select the Edit Menu command category.
5. Click Assign
Assign. Notice that Ctrl+Shif t+F appears in Cur
Ctrl+Shift+F rent K
Current eys list.
Keys
7. Test the keystroke shortcut by holding down the Ctrl and Shif
Shiftt keys, and then pressing F. AutoCAD should
execute the Find command by displaying the F ind and R
Find eplace dialog box.
Replace
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Alias Format
The format for defining a command alias is simple:
alias, *fullCommandName
Notice that the alias is followed by a comma, a space, an asterisk, and then the complete command name, such as:
L, *LINE
Alias Rules
Autodesk makes the following suggestions for creating command aliases:
• An alias should reduce a command by at least two characters.
• Commands with a control key equivalent, status bar button, or function key do not require an alias. Ex-
amples include the New command (already assigned to Ctrl+N Ctrl+N), Snap (already on the status line), and
Help (already assigned to function key F1 F1).
• Try to assign the first character of the command. If it is already taken by another command, assign the first
two characters, and so on. For example, C is assigned to the Circle command, so CO is assigned to the Copy
command.
• For consistency, add suffixes for related aliases. For example, H is assigned to the Hatch command, so
assign HE for HatchEdit
HatchEdit.
• Remember to use the hyphen for command-line commands. For example, -LA for the -Layer command.
The following 247 commands are assigned to aliases by Autodesk in the acad.pgp file. You may, of course, change
any of these that you wish: -AR, *-ARRAY C
ARO, *DBCONNECT
3 ASE, *DBCONNECT C, *CIRCLE
ASQ, *DBCONNECT -CH, *CHANGE
3A, *3DARRAY CH, *PROPERTIES
ATE, *ATTEDIT
3DO, *3DORBIT CHA, *CHAMFER
-ATE, *-ATTEDIT
3F, *3DFACE CO, *COPY
ATT, *ATTDEF
3P, *3DPOLY COL, *COLOR
-ATT, *-ATTDEF
ATTE, *-ATTEDIT COLOUR, *COLOR
A
AV, *DSVIEWER CP, *COPY
A, *ARC
B D
AA, *AREA
AAD, *DBCONNECT D, *DIMSTYLE
B, *BLOCK
ADC, *ADCENTER DAL, *DIMALIGNED
-B, *-BLOCK
AEX, *DBCONNECT DAN, *DIMANGULAR
BH, *BHATCH
AL, *ALIGN DBA, *DIMBASELINE
BO, *BOUNDARY
ALI, *DBCONNECT DBC, *DBCONNECT
-BO, *-BOUNDARY
AP, *APPLOAD DCE, *DIMCENTER
BR, *BREAK
AR, *ARRAY
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Using a text editor, such as Notepad, open the acad.pgp file, which is found in AutoCAD’s \support folder.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
6. Switch back to AutoCAD, and then start the Reinit command, as follows:
Command: reinit
Notice the Re-initialization dialog box. This reloads the .pgp file into AutoCAD so that the new alias
becomes active.
8. Test your change by entering “lin” at the ‘Command:’ prompt. AutoCAD should start the DimLinear
command:
Command: lin
DIMLINEAR
Specify first extension line origin or <select object>:
Notice that AutoCAD reports the full name of the command in uppercase letters, as in DIMLINEAR.
Feedback
I welcome your feedback for correcting and improving the text. Send your email to [email protected] .
Visit the Tailoring AutoCAD e-book Web site at www.upfrontezine.com/tailor.
For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
t he easiest part of AutoCAD to customize, in my opinion, are the toolbars, which were first added to AutoCAD
with the Windows version of Release 11. (Yes, there was a version of R11 for Windows, called the “AutoCAD
Windows Extension,” or AWE for short, which was meant by Autodesk to be more of an experiment than a
working release.) With Release 13, Autodesk significantly changed how toolbars operate, which is why this chap-
ter includes instructions for customizing toolbars for AutoCAD before and after Release 13.
Toolbar buttons give you single-click access to almost any command or group of commands. Instead of hunt-
ing through AutoCAD’s maze of menus (is the Hatch command under Draw or Constr uct
Construct
uct?) or trying to recall
the exact syntax of a typed command (was that Viewpoint or Vpoint)Vpoint), toolbars let you collect your most-used
commands in convenient strips.
Toolbars buttons operate by executing one or more commands and options, called macros. Figuring in the time
it takes to write and debug the macro, my rule-of-thumb is to write a macro any time the same action is repeated
more than three times.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Rearranging Toolbars
When you start a fresh copy of AutoCAD, it has four toolbars that are docked along the edges of the drawing area.
“Docked” means the toolbars are attached to the edges of the drawing area. When you move or change the size of
the AutoCAD window, the toolbars move along.
Toolbars don’t have to be docked. They can also float. When toolbars float, they are independent of the AutoCAD
window. Move or resize the AutoCAD window, and floating toolbars remain where they are. If you have a dual-
monitor setup, it can be useful to have toolbars, the text window, the Properties window, and so on, on the second
monitor. That maximizes the first monitor for the drawing area.
Dragging Toolbars
Look closely at the end of each toolbar, and notice the double-line (shown enlarged in the figure below). These are
called drag handles. By dragging the toolbar by its handle, you can move the toolbar around AutoCAD.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Drag it away from the edge of the drawing area. Notice the thin, gray, rectangular outline, called the dock
indicator, shown in the figure above. If you were to release the mouse button at this point, the toolbar would
jump back to its docked position.
2. Drag the toolbar further, and notice that the rectangular outline changes to a thicker line. This is called the
float indicator.
3. When you let go of the mouse button now, the toolbar floats.
4. With the toolbar floating, you can move the toolbar by dragging it by its title bar.
5. Additionally, you can resize the toolbar by grabbing at any of its edges. Notice the two-headed cursor; it
indicates that you can resize the toolbar, making it more square or more rectangular.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP Although not a toolbar, the command-prompt area can also be resized and be
made to float.
To resize, grab the dividing line between the prompt area and the drawing area,
and drag up or down. The number of prompt lines changes from the default setting of 3.
To float, drag the prompt area at its lower right corner, as shown below. If necessary, hold
down the Ctrl key to prevent docking.
Once floating, you can move the prompt window by its title bar, and resize it by its edges
— just like a toolbar.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Right-click any toolbar. Notice the shortcut menu that lists the names of all the toolbars. The check mark
means the toolbar is turned on.
2. To turn on a toolbar, select its name from the shortcut menu. Notice that the toolbar appears, and the menu
disappears. To turn on other toolbars, repeat steps 1 and 2.
3. To turn off a toolbar, repeat steps 1 and 2, but select a toolbar name with a check mark. When a toolbar is
floating, you turn it off by clicking the x in the upper right corner.
TIP To turn on (or off) all toolbars at once, use the undocumented -Toolbar com-
mand, as follows:
Command: -toolbar
Enter toolbar name or [ALL]: all
Enter an option [Show/Hide]: s
This command also turns on and off individual toolbars, which can be of use in a macro or
AutoLISP routine.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. In the Toolbars tab, click New to create a new toolbar. Notice the New Toolbar dialog box.
Toolbar
3. In the New Toolbar dialog box, enter a name for your toolbar, such as “My Toolbar.”
Toolbar
Click OK
OK.
It’s easy to miss, but AutoCAD creates a new, empty toolbar. It’s just a tiny thing, and you may have to hunt
around the screen to find it.
4. Now it’s time to populate the empty toolbar with buttons. In the Customize dialog box, select the Com-
mands tab. Notice that AutoCAD’s commands are presented in two ways: categorized by function (F File
ile,
Edit
Edit, and so on), and alphabetical (scroll down to find All Commands
Commands).
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
6. To remove a button from the toolbar, simply drag it out of the toolbar. AutoCAD asks, “Are you sure you
want to delete the button from the toolbar?” Answer in the affirmative, Yes.
TIP While the Customize dialog box is open, all toolbars are customizable — not just
the one you created. This means you can add and remove buttons from the other
toolbars, such as Draw, Standard, and so on.
7. When done, click Close to dismiss the Customize dialog box. Your new toolbar acts just like the any other
toolbar in AutoCAD.
There is no need to “save” the new toolbar; it is saved automatically by AutoCAD, and will appear the next time
you start AutoCAD.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The buttons on toolbars are 16 pixels in size. In some cases, that may be too small if your eyesight isn’t as strong
as that of user-interface designers. You can make the buttons 50% larger, as follows:
1. Open the Customize dialog box, and select the Toolbars tab.
3. If you like the size, click Close to dismiss the dialog box.
If you don’t, uncheck the Large buttons option, and close the dialog box.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
You may have noticed that some command-buttons lack icons, as shown below. AutoCAD has a built-in icon
editor that lets you modify existing icons and create new ones.
1. Bring back the Customize dialog box by right-clicking the toolbar and selecting Customize
Customize. (The only
purpose for this dialog box is to enter toolbar-customization mode; we don’t actually use the dialog box in
this tutorial.)
• The four tools along the top are for drawing freehand, lines, ellipses (and circles), and erasing (changes
colors back to neutral gray). There is, unfortunately, no floodfill tool.
• The small square on the left shows you a preview of the icon in real-size.
• The colored squares on the right are the 16 standard Windows colors for drawing icons. You are limited to
16 colors to ensure the icons look correct with any depth of color display.
• The large gray square in the center is where you draw the icon.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Bring back the Customize dialog box by right-clicking the toolbar and selecting Customize
Customize.
2. Select a button on any toolbar. Notice that the Customize dialog box switches to the Button Properties tab.
Properties
The Button Properties tab has several areas that correspond to AutoCAD’s user interface:
Properties
• Name is the text displayed by the button’s tooltip. This is a brief description of the button’s function.
• Description is the text displayed on the status line. This is a longer description of the button’s function.
• Macro associated with this button is the collection of commands executed by clicking the button. The figure
above shows quite a complex macro; most macros consist simply of the command’s name, such as:
^C^C_open
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Simple Macros
^C is a control character. It imitates pressing Esc on the keyboard, which cancels the command currently in
progress. The carat ( ^ ) alerts AutoCAD that this is a control character, and not a command. What does
C have to do with the Esc key? In versions of AutoCAD older than Release 13, you pressed Ctrl+C to
cancel a command; the C was short for “cancel.”
(Going back even further in history, Ctrl+C comes from ASCII code 003, which meant ETX —
end-transmission — in the days of telegraphs and teletypes. More than a hundred years later, these ASCII
codes are still used today, because early computers used teletype terminals to communicate with humans, and
some things never change. This leads to some clashes: ever since Release 13, Ctrl+C means “copy to
Clipboard” but continues to mean “cancel” in macros only, for compatibility reasons.
^C^C Most macros start with two ^C because some AutoCAD commands are two levels deep. I
recommend three of ’em — ^C^C^C — because some commands, like PEdit PEdit, are three levels deep.
When the command is transparent (starts with the ' apostrophe), then you don’t prefix the macro with
the Cancel character.
_ The underscore is an AutoCAD convention internationalizing the command. Prefixing command and
option names with the underscore ensures the English-language version of the command always works,
whether used with German, Japanese, or Spanish versions of AutoCAD.
open is the command name. In macros, you type AutoCAD commands and their options exactly the way you
would type them on the keyboard at the ‘Command:’ prompt. That means you can, for instance, use aliases
instead of the full command name; this is discouraged, however, because aliases can be changed, leading to a
non-operational macro.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Advanced Macros
You may string together more than one command in a toolbar macro. In addition, you can include Diesel expres-
sions and AutoLISP routines (see chapters 10 and 11 for details). For example, Autodesk wrote the following
macro for the RefSet button:
$M=$(if,$(eq,$(getvar,refeditname),""), ^C^C^P(ai_refedit_alert); ^P,$(if,$(and,$(=,$(getvar,
tilemode),0),$(=,$(getvar,cvport),1)),^C^C_refset;,^C^C_refset _add;))^Z
Yikes! Ugly, isn’t it? I’ve parsed the code in colors to make so that you can see the structure:
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. When AutoCAD appears, there are three rows above the drawing area. From top to bottom, these are (1) the
title bar; (2) the menu bar; and (3) the toolbar. The toolbar replaces the status line of DOS-based
AutoCAD. From left to right, it displays:
The remaining toolbar buttons are the focus of this chapter. Many have been pre-programmed by Autodesk
to perform specific functions, but you may change the meaning of any of them. These older releases of
AutoCAD support a maximum of 26 buttons on the toolbar. The number of buttons visible depends,
however, on your monitor’s resolution, the size of the AutoCAD window, and the size of the button them-
selves. The figure above displays 17 buttons.
3. Move the cursor over any toolbar button, and then press the mouse’s left button. For example, when you
click on the first button (looks like a six-pane window), AutoCAD moves the position of the toolbox. Each
time you click, AutoCAD executes the Toolbo oolboxx command, which moves the toolbox from docked to one
side, to floating, to invisible.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. Move the cursor up to the toolbar, then over any of the square buttons to the right of the coordinate display
(see figure on previous page).
4. The right-click action brings up a dialog box named Toolbar Button Customization
Customization. This single dialog box
controls every aspect of the toolbar (well, almost: later, I’ll show you how to bypass the dialog box). Take a
look at the dialog box in detail:
Title Bar
At the top, the dialog box’s title bar lists the button number being customized. The figure shows looking at the
dialog box for Button 1.
AutoCAD LT Command
At the bottom of the dialog box is the macro attached to the toolbar button. When you click the toolbar button,
AutoCAD executes the macro string typed here:
\3\3_TOOLBOX
The macro consists of three control characters, and one AutoCAD command. They have the following meaning:
\3 This is called a control character. It imitates pressing Ctrl C on the keyboard, which cancels the command
Ctrl+C
currently in progress. The number “3” comes from C being the third letter of the alphabet. The backslash (
\ ) alerts AutoCAD that this is a control character, and not a command.
\3\3 Most macros start with two \3 since many AutoCAD commands are two levels deep. I recommend
starting macros with \3\3\3 because some commands, like PEditPEdit, are three levels deep.
If the command is transparent (starts with the ' apostrophe), then you don’t prefix the macro with the
Cancel character.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TOOLB
TOOLBO OX Finally, we arrive at the command name! In macros, you type AutoCAD commands and their
options exactly the way you would type them on the keyboard at the ‘Command:’ prompt.
(Space) It is barely visible in the figure, but there is a space after TOOLB
TOOLBOOX. The space is the equivalent of
pressing the Enter or Spacebar key. AutoCAD automatically adds the space because every command is
executed by pressing the Enter key. To suppress the automatic space, add a semicolon ( ; ).
Image - Character
You have the choice of labelling the toolbar button with an “image” or a “character.” The image is one of 81 icons
that you can select from the Select Image list (and previewed in the center of the dialog box). The character is
simply a letter of the alphabet from A through Z. If you don’t select an icon, AutoCAD uses the first character of
the macro. In this example, that would be the \ backslash.
Clicking the Ne xt and Previous buttons is a convenient way to edit the macros associated with the next (or
Next
previous) buttons on the toolbar.
The Delete button erases the macro from the button. You can leave the button blank or type in a new macro.
The Cancel button cancels any changes you made to the button, and dismisses the dialog box.
Clicking the OK button saves the changes to file acad.ini (aclt.ini if you are working with AutoCAD LT), and
then dismisses the dialog box.
TIP How to add a pause to toolbar macro, thanks to Richard L. Woodcock. The
backslash ( \ ) forces the macro to pause for user input in example macro:
^C^C-layer;m;\c;\;L;\;s;\;
The macro initiates the -Layer command (command-line version), selects the Make
option, pauses for user input for the layer name to be assigned, selects the Color option,
pauses for user input for the color name or number to be assigned, selects the Ltype
option, pauses for user input for the linetype name to be assigned, selects the Set option,
pauses for user input for the name of the layer to be set current, and completes the
command.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The figure shows the first part of aclt.ini from AutoCAD LT. Each .ini file looks slightly different, depending on
the settings in effect. The file is often divided into sections. Section titles are in square brackets, such as [AutoCAD
LT General]. Toolbar definitions look like this example:
ToolBar1=\3\3_TOOLBOX ^88^
Let’s pick apart this mishmash, bit by bit, to see what it means. When AutoCAD starts, it reads the .ini file.
Whatever is behind the equals sign in Toolbar1= is stuck onto the first toolbar button. (T
Toolbar1= means this is
the first toolbar button. The second toolbar button is defined by Toolbar2=
oolbar2=, and so on.)
From the previous section, we know that \3\3 are two Cancels in row like pressing Ctrl C twice. That ensures
Ctrl+C
that any command in progress is cancelled before executing the macro.
The _TOOLB
_TOOLBO OX is the command that toggles the display of the toolbox. Recall that the underscore ( _ )
internationalizes any English-language AutoCAD command. The command can be typed in UPPERCASE or
lowercase — it doesn’t matter.
There is a space after the command, which AutoCAD automatically appends to the macro: this acts like
pressing the Enter key at the end of a command.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Here, button #9 starts with an apostrophe ( ' ), which makes transparent the DdLModes command (display layer
dialog box). By clicking this button during another command, you can display the Layer Control dialog box. The
icon image is the 56th one.
ToolBar13=
This 13th button is undefined since there is nothing behind the equal ( = ) sign. When you click the 13th button,
nothing happens. As well, the button itself is blank.
You’ve seen toolbar macros from two approaches. In the previous section, you saw how to write macros with the
Toolbar Customization dialog box within AutoCAD. In this section, you saw how to change macros via the
Acad.Ini (or AcLt.Ini) file with the Notepad text editor.
Which approach is better? The dialog box is better when creating one or two macros on-the-fly. Accessing the
.ini file directly is better when customizing all 26 toolbar buttons at once or with a program external to AutoCAD.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. Enter ToolBarSize to specify the parameter in aclt.ini that determines the size of the toolbar icons. It’s not
well known, but you can change the size of the icons displayed by AutoCAD LT.
3. After you enter the name of the variable, such as toolbarsize, LT prompts you for the new value:
Value <16>: 24
If the variable exists, LT returns the value in angle brackets, such as <16>
<16>. By default, the value of
ToolBarSize is 16, measured in pixels. You can reduce the value down to 6 to display more buttons but very
tiny icons. Or you can increase the value up to 32 to display very large but fewer buttons.
Note that the new icon size do not come into effect until AutoCAD starts again.
Another trick is to directly customize buttons of the toolbar. The process works using SetEnv like this:
Command: setenv
Variable name: toolbar13
Value: ^C^C_bmake^9^
When you want to change the macro, SetEnv helpfully displays the current setting, as follows:
Command: setenv
Variable name: toolbar13
Value <^C^C_bmake^9^>: ^C^C_block^9^
Despite the SetEnv command’s unique availability in LT, I have found it has numerous drawbacks, which Autodesk
failed to address in LT Release 2:
• SetEnv cannot cope with spaces. The first space you type ends the command, and returns you to the
‘Command:’ prompt.
• SetEnv cannot access .ini items beyond in the first section, [AutoCAD LT General]. It cannot access .ini
items in later sections, such as [AutoCAD LT ToolBox].
• SetEnv cannot check the syntax. When you type an incorrect variable name, such as ToolBat39=junk,
SetEnv faithfully records it at the end of the [AutoCAD LT General] section.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
0,0 Inserts the block at the origin (0,0). Notice that macros can start in the middle of a command.
110 Specifies the x- and y-scales of 1.0 and a rotation angle of 0 degrees. Since these are the default values,
I could have written the macro with spaces, but spaces make macros harder to read and debug.
zoom e Performs a zoom extents so that I see the entire drawing.
plot Starts the Plot command.
A single mouse click executes all three commands (representing 22 keystrokes or six menu picks) faster than I
could ever hope to type at the keyboard, or select them from the menus.
I would have liked to have continued the macro to automate the rest of the plot, but AutoCAD cannot do that
in dialog boxes. I could have reverted to the command-line version of the -Plot command, but I needed to do a
windowed plot by picking two points on the screen.
Here is another macro. This one places a D-size (24" x 36") drawing border some 0.1 units wide using the PLine
command:
\3\3_pline 0,0 width 0.1 0.1 36,0 36,24 0,24 close _zoom e
If you run up against the 79- (or 255-) character limits, you can conserve characters with aliases. By employing
aliases, the above macro is shortened by 15 characters to:
\3\3 _L 0,0 w 0.1 0.1 36,0 36,24 0,24 c _z e
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
t o customize the menu bar, you work with AutoCAD’s .mnu (menu) files. In a curious twist, the .mnu file
controls far more than just the contents of the menu bar. It also defines all toolbars, “accelerator” keys (keyboard
shortcuts), image tiles (an old form of dialog box), tablet overlays (used with digitizing tablets), and the rarely
seen screen menu.
In this chapter, you learn how to customize the menu bar only. Because, as it turns out, AutoCAD provides a
much easier customizing environment for toolbars and accelerator keys (see chapters 4 and 3, respectively). As for
the image tiles, tablet overlays, and screen menu, you’ll find the answer to why I ignore them on the last page of
this chapter.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Toolbars, Accelerator Keys, Image Tiles, Tablet Overlays, and the Screen Menu . . .75
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The Menu Groups tab loads and unloads partial menus; the Menu Bar tab determines the display order of menu
titles. Notice the correlation of items under Menu Bar (at the far right) with the menu bar displayed by AutoCAD:
The Menu Groups list shows the menu groups loaded into your AutoCAD session. The figure above lists:
• ACAD is the standard menu provided with AutoCAD.
• ACCOV is a promotional menu for CAD Overlay; shows up as the Image item on the menu bar.
• BL UEBEAM is a third-party menu item.
BLUEBEAM
To remove a menu group, select it and click the Unload button. You can always reload the menu group with the
Browse button.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP To load an entire menu system at once, use the Menu command. It prompts you
to select an .mnu, .mnc or .mns file.
AutoCAD uses a number of files for its menu system, some of which you can access, while others are hands-off
because they are generated by AutoCAD:
User Accessible
MNU Primary menu file.
MNL Contains the AutoLISP functions used by the menu.
Hands Off
MNC Compiled menu file defines the menu’s functions and appearance.
MNR Menu resource file contains the menu’s bitmaps.
MNS Source menu file generated by AutoCAD.
MNT Menu resource file generated when the .mnr file is unavailable.
You write new menus with a text editor, such as Notepad, and then save the file with the .mnu extension. When you
load the menu into AutoCAD, AutoCAD compiles the file. A compiled menu loads and displays faster.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
A Single-Command Menu
Menus are written with a text editor, such as Notepad.
This is pretty much the minimum needed for placing a command on AutoCAD’s menu bar. The characters
shown in boldface are macro syntax (required parts of the menu so that AutoCAD understands what’s going on).
The regular text is your stuff, which you are free to change.
Let’s take a look at what those lines of text mean. The following figure illustrates the connection between the
menu file and AutoCAD’s menu bar:
In the figure above, the text shown in black appears on the menu bar, while the text in periwinkle color is hidden
from view. Getting into the details, here’s what it means:
***MENUGROUP=MyFirstMenu
The ***MenuGroup tag identifies the menu by name. This helps distinguish your menu from others
written by Autodesk and third-party developers. You can give it any name you like; we’ll use
“MyFirstMenu.”
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The ***POP section label specifies that the macros following the title (as noted next) should be placed on
the menu bar. Contrary to Autodesk documentation, you don’t need a number behind ***POP, unless you
create more than one pop-down menu.
When you leave out ***POP, the macros won’t show up — anywhere. (In older releases of
AutoCAD, the macros would show up on the screen menu.) If you want the macro to operate elsewhere, use
a different section label, such as ***BUTTONS1 for mouse buttons.
ID_mnuTailoring [Tailoring]
This gives a name to the menu title — the word that appears on the menu bar. The “Tailoring” text follow-
ing ID_mnu identifies the menu item, while the text in the square brackets — in this case, the word
[Tailoring] — appears on the menu bar.
[Rectangle]rectang;
And now, finally, the command! (Again, the [Rectangle] text in square brackets appears in the menu.) This
macro executes the Rectang command. The semi-colon ( ; ) terminates the macro, just like pressing Enter at
the keyboard.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
(The warning is needless because your menu was not previously loaded; it can’t be overwritten.)
Click Yes
es. In the command prompt area, AutoCAD reports, “Menu loaded successfully. MENUGROUP:
MyFirstMenu.”
4. Your new menu is loaded into AutoCAD, but it has not yet been “applied.” If you were to click Close
Close, it
would not appear anywhere. Here’s how to make it appear:
• In the Menu Customization dialog box, click the Menu Bar tab.
• In the Menu Group droplist, select MyF irstMenu
irstMenu. Notice that Tailoring appears under the Menu list.
MyFirstMenu
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
• Click Close
Close.
Congratulations! You’ve written your first custom menu file. Before continuing with more customization, I’ll list
some of the macro conventions, including section labels, metacharacters, and shortcut aliases.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Character Meaning
Menu Controls
$ Loads menu sections.
=* Returns to top-level menu.
$I= Displays an image menu.
$M=$( Starts a DIESEL macro.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Command Prefixes
’ Indicates transparent command.
_ Translates AutoCAD commands and options as English.
*^C^C Repeats the macro until you press the Esc key.
^C^C^C Cancels the current command before starting macro.
[ ] Provides a label for the macro.
Command Postfixes
; Equivalent to pressing Enter or the spacebar; you can also use ^M.
space Equivalent to pressing the spacebar; can be used within macros to
separate commands from options, but ; is preferred.
\ Wait for input from user (cannot be used in the ***Accelerators section).
+ Macro continues on the next line (when the last character).
Labels
[--] Separator line between items on pull-down and shortcut menus.
[->label] Start of a submenu.
[<-label] End of the submenu or parent menu.
[<-<-label] End of the submenu and the parent menu.
~ Unavailable menu item (grayed out).
!. Prefixes menu item with the check mark.
& Menu accelerator key character; can also use / .
\t Right justifies text following.
Ctrl Characters
^B Toggles snap mode on and off (equivalent to pressing Ctrl+B).
^C Cancels command (equivalent to Esc).
^D Changes coordinate display.
^E Changes the isometric plane.
^G Toggles display of the grid.
^H Equivalent to pressing Backspace.
^I Equivalent to pressing Tab.
^O Toggles ortho mode on and off.
^P Toggles MenuEcho system variable on and off.
^Q Records user input and AutoCAD prompts to a log file.
^T Toggles tablet between command and point modes.
^V Changes the focus to the next viewport (equivalent to Ctrl+R).
^Z Suppresses the space at the end of a menu item.
TIP To include comments in the mnu file, prefix the text with two slashes ( // ), such
as:
//This menu was written by moi.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Alias Comment
GRIPS Defines hot grip shortcut menu: right-click a hot (red) grip.
CMDEFAULT Defines default shortcut menu (right-click blank area in the drawing).
CMEDIT Defines Edit shortcut menu (right-click an object).
OBJECT(S)_obj Defines shortcut menu specific to the object (obj = DXF name).
CMCOMMAND Defines Command shortcut menu (right-click while a command is active).
COMMAND_cmd Defines shortcut menu specific to a command (cmd = any AutoCAD command).
TIPS A pop-down menu can contain up to 999 items, and a shortcut menu can have as
many as 499 items.
Shortcut menus do not display a title, but a dummy title must still be provided.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
You can re-use the code by filling in your own text for that in cyan italics. For example, here is how to use the code
listed above to create a new menu item that turns on the log file:
***MENUGROUP=MySecondMenu
***POP
ID_mnuLogFile [Log File]
[Turn on log file recording]logfileon;
TIP Make sure there is a blank line following the last line in the .mnu file.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The l is short for “last.” Add it to mymacro.mnu and load it into AutoCAD.
When you select Erase Last from the menu, AutoCAD selects the last-drawn object visible on the screen —
but does not erase it! Recall that when you use the Erase command, you need to press Enter twice:
Command: erase
Select objects: l (Press Enter.)
1 found Select objects: (Press Enter.)
TIP Menu macros cannot control dialog boxes. To access options in commands that
normally use a dialog box, use the command-line version. In most cases, you prefix the
command with a dash, such as:
[Array]-array;
Specify first corner point none X,y-coordinates of the rectangle’s first corner.
Chamfer C Distance for corner chamfers.
Elevation E Height of the rectangle above the x,y-plane.
Fillet F Radius of corner fillets.
Thickness T Thickness of the rectangle in the z-direction.
Width W Linewidth of all four segments.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Make sure you use "straight quotes" and not “curly quotes,” also known as typesetter’s quotes. AutoCAD does
not understand curly quotes.
When a menu item calls a dialog box, the convention is to include the ellipsis ( ... ) as a
suffix, like this:
[Open...]^C^C_open;
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Notice that the AutoLISP code is handled differently. The three ^C appear before the parentheses, while the
underscore appears inside the parentheses in front of the command name.
Most menus have keyboard shortcuts that let you access menus from the keyboard. To do so, you hold down the
Alt key, and then press the underlined letter on the menu. For example, to access the File menu’s Save command,
you press Alt+F+S because the F and the S are underlined.
For AutoCAD menus, you use the ampersand ( & ) to specify the keyboard shortcut (and underlined) charac-
ters. I’ve added & in four places below (shown in boldface
boldface):
***MENUGROUP=MyFirstMenu
***POP
ID_mnuTailoring [T&ailoring]
[&Rectangle]^C^C^C(command "_rectang" "0,0" "8.5,11")
[&Turn on log file recording]^C^C^C_logfileon;
[Erase &Last]^C^C^C_erase l;;
You can prefix any character you wish with the &, but keep in mind these two rules:
Rule 1: The underlined character should be logical, when possible. In the example above, I placed the & in front
of the “R” in &Rectangle
&Rectangle
ectangle.
Rule 2: Do not duplicate underlined characters. In the example above, I placed the & in front of the “a” in
T&ailoring. That’s because the letter T is already taken by the Tools item in AutoCAD’s menu. If both had the T
T&ailoring
underlined, you would only ever get to the first word.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
A horizontal line is often used in menus to separate similar groups of commands. To add such a line, simply
include the [--] metacharacter, as shown below twice:
***MENUGROUP=MyFirstMenu
***POP
ID_mnuT&ailoring [Tailoring]
[&Rectangle]^C^C^C(command "_rectang" "0,0" "8.5,11")
[--]
[&Turn on log file recording]^C^C^C_logfileon;
[--]
[Erase &Last]^C^C^C_erase l;;
Adding a submenu is as easy as adding the [->label] metacharacter. Modify the menu, as shown by the boldface
below:
***MENUGROUP=MyFirstMenu
***POP
ID_mnuT&ailoring [Tailoring]
[&Rectangle]^C^C^C(command "_rectang" "0,0" "8.5,11")
[--]
[&Turn on log file recording]^C^C^C_logfileon;
[->Erase]
[Erase &Last]^C^C^C_erase l;;
When you have additional parent menu items beyond the submenu, you indicate the end of the submenu with the
[<-label]] metacharacter:
[<-
[<-Erase All]^C^C_erase _a;
It’s optional, but you can also indicate the end of both a submenu and its parent with the [<- ...] metacharacter:
[<-label...]
[<-Erase All...]^C^C_erase _a;
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
When you assign a shortcut to a command, such as Ctrl+S for saving the drawing, you can include it in the menu
as right-justified text. The \t metacharacter separates it from the menu label by pushing the text following to the
right side of the menu. Here is what \t looks like in a macro (shown boldface):
[&Save\tCtrl+S]^C^C_qsave
Grayed-out Item: ~
When a menu item is grayed-out, this means it is not available. See, for example, “Partial Load” in the figure
above. To make the text gray, use the tilde metacharacter: [~label]. To use it effectively, however, is not trivial
because it requires the use of Diesel code (see chapter 10). You only want the menu item grayed-out when it is not
available; when it is available, you want it in regular black text.
Fortunately, you can simply reuse existing Diesel code, substituting in values for your specific need. Here is
the code for toggling the gray text in the Partial L oad command (replaceable text is in boldface
Load boldface):
[$(if,$(eq,$(getvar,fullopen),0),,~)Partia&l Load]^C^C_partiaload
What this means is that the PartiaL oad command is available only when FullOpen is 0 (which indicates that the
artiaLoad
drawing was partially loaded).
Adding a Checkmark: !.
Adding a checkmark prefix is, unfortunately, just as complex as graying out text. The checkmark appears only
when an option is turned on; it should not appear when off. Once again, it helps to copy existing Diesel code that
performs the checking (user-replaceable text shown in boldface
boldface):
[$(if,$(eq,$(getvar,tabmode),0),!.)O&ff]^C^C_tablet _off
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP Search the acad.mnu file for examples of how to use metacharacters and macros
in AutoCAD’s menus.
This macro executes the Arc command with the Center and Angle options. It waits twice for the user to input a
value before continuing on. AutoCAD accepts just one user input per \ metacharacter; you can have more than
one \ in a row, if required by the command.
The exception to the single-selection rule is the Select command, which waits until the user presses Enter to
finish selecting one or more objects. You then use the Previous option to obtain the selection set. Here is sample
code that changes selected objects back to the Continuous linetype:
[Change linetype]^C^C_select \change;p;;properties;lt;continuous;;
Notice there is no semi-colon ( ; ) after select \ because the user has to press Enter to signal the end of object
selection.
AutoCAD provides the Single option to force the Select command (and any other command that prompts for
object selection) to limit itself to one of two kinds of selections: a single object, or a windowed selection. It gets
used like this:
[Change single linetype]^C^C_change;single;;properties;lt;continuous;;
Conversely, you can write macros that let the user select values from the menu, such as the following set of angles:
[30 Degrees]30a^H
[60 Degrees]60a^H
[90 Degrees]90a^H
The ^H is needed at the end of the macro to prevent the automatic Enter that AutoCAD otherwise adds. The
“a” is a dummy character that AutoCAD backspaces over.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIP Macros are limited to 1,040 characters. Text beyond the 1,040th character is
ignored by AutoCAD. Autodesk suggests writing an AutoLISP routine instead.
Repeating a Command
Some commands repeat automatically, such as Donut Donut; others, such as Circle
Circle, do not. When you want a command
to repeat itself, you prefix it with Multiple at the command prompt.
In menu macros, however, you use the asterisk ( * ) prefix, like this:
[Multiple &Point]*^C^C_point
which repeatedly execute the Point command — until you press Esc
Esc.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Toolbar Customization
Toolbars are far easier to define using the Tools | Customize | Toolbars command than tediously coding them in
Toolbars
the .mnu file. Here are some of the macro codes you’d have to learn to construct a custom toolbar:
***TOOLBARS
**TOOLS
TAG1 [Toolbar (“tbarname”, orient, visible, xval, yval, rows)]
TAG2 [Button (“btnname”, id_small, id_large)]macro
TAG3 [Flyout (“flyname”, id_small, id_large, icon, alias)]macro
TAG4 [Control (element)]
[--]
Instead, see chapter 4 to learn how to customize toolbars visually, and let AutoCAD generate the macro
codes on your behalf!
Image Tiles
Image tiles create a type of dialog box so rarely used by AutoCAD that it appears in just one undocumented
command: Draw | Surfaces | 3D Surfaces Surfaces. In any case, you cannot complete construction of the image tile
because it requires .sld files, and the slidelib.exe utility program for integrating them has been broken for ten years.
Tablet Menus
Tablet overlay menus are rarely used anymore, ever since the mouse became overwhelmingly popular. In any case,
writing the macros in the .mnu file for a typical 625-cell overlay is incredibly tedious that even in the early days of
AutoCAD that third-parties wrote utility programs to automate the process.
Screen Menu
The screen menu was the original “point and click” interface for AutoCAD, but nobody uses it anymore. Indeed,
it is turned off by default, so most people aren’t even aware of its existence.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Until Release 13, AutoCAD linetypes were strictly one-dimensional. They consisted of lines, gaps, and dots
placed together in a variety of patterns. Since Release 13 (and LT Release 3), Autodesk extended linetypes so that
we could include 2D shapes and text to create railroad tracks and — HW — hot water lines.
The 1D linetypes are called “simple linetypes,” while 2D linetypes are called “complex linetypes.” AutoCAD
stores its simple linetypes in the acad.lin file found in the \support folder (aclt.lin in AutoCAD LT). The complex
linetypes are stored in file ltypeshp.lin. The text for the complex linestyles is stored in ltypeshp.shx.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Text . . .83
Text Style . . .83
Text Scale Factor . . .83
Text Rotation Angle . . .83
Text Orientation . . .83
Text Offset Distance . . .84
Embedding a Shape . . .84
3D Linetypes . . .84
A Parallel Linetype . . .85
Alternatives to the Parallel Linetype . . .87
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Then there’s the trick when it comes to polylines. To understand the problem, consider how AutoCAD generates
a linetype. AutoCAD attempts to apply the linetype as nicely as it can, based on the length of the object and the
linetype scale factor. Essentially, AutoCAD starts at one end of the object, and then works its way to the other end.
Finally, AutoCAD centers the linetype pattern so that it looks nice and even at both ends. You never get the
linetype abruptly ending midway through.
Consider, then, the polyline. While it looks like one long connected line-arc-spline, it contains many vertices,
even if you cannot see them. AutoCAD faithfully restarts the linetype pattern each time it encounters a vertex.
When the vertices are close together, AutoCAD never gets around to re-starting the pattern, resulting in a solid or
continuous line. This drives some people nuts, like cartographers who use polylines for drawing contours.
As of Release 13 (and LT R3), the problem has been fixed with the PlineGen system variable. When set to 0
(the default), AutoCAD works as before, generating the linetype from vertex to vertex. When changed to 1,
however, AutoCAD generates the linetype from one end of the polyline to the other end — ah, instant relief!
Customizing Linetypes
AutoCAD provides two methods for creating new linetypes: (1) at the command prompt; and (2) with a text
editor. Let's look at the first one first. Follow these steps to create a new linetype on-the-fly:
1. Start AutoCAD, and then enter the -Linetype Create command, as follows:
Command: -linetype
Current line type: "ByLayer"
Enter an option [?/Create/Load/Set]: c
2. Give a name to the linetype. This takes three steps: (1) The first step is the name itself, which can be as long
as 31 characters. Let’s name the pattern “Dit-dah” (after the Morse code pattern for the letter A — the only
Morse code I know, and the nickname of an aunt):
Enter name of linetype to create: dit-dah
AutoCAD stores your new linetype in a .lin file, for later reuse.
3. At this point, AutoCAD pops up the Create or Append Linetype dialog box. That lets you decide where to
place the custom linetype:
• In a new .lin file.
• Or have AutoCAD append the linetype description to the acad.lin.
I find it easiest to keep all linetypes in one file, so I recommend accepting acad.lin — or acadIso.lin if you
tend to work with the ISO (international standard) linetypes.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
If two linetypes have the same name, AutoCAD would only ever read the first one it comes across. If you
accidently (or otherwise) enter a linetype name that already exists — such as “Dashed” — AutoCAD warns:
DASHED already exists in this file. Current definition is... Overwrite? <N>
5. Next, describe the linetype with any words you like up to 47 characters long.
Descriptive text: . __ . __ . __ . __
A good descriptive text would be the pattern you plan to create, using dots, underlines, and spaces.
6. Finally! You get to define the linetype pattern. The code is a simple:
• Use a positive number to indicate a dash
dash. For example, 0.25 means a dash 0.25 units long.
• Use a negative number for a gap gap. For example, -0.1 is a gap 0.1 units long.
• And use a zero to draw a dotdot. A 0 is a single dot.
You can’t use the same code twice in a row. It just doesn’t make sense to have two gaps or two lines in a row,
does it? Instead, code that gap or line twice as long. There are two more codes to know about:
• The comma is needed to separate the codes. For example: .25,-.1,0,-.1
• The letter A forces the linetype to align between two endpoints. That’s what causes the linetypes start
and stop with a dash, adjusted to fit. (The A could also stand for “actually” because, actually, I don’t have a
choice when I create a linetype on-the-fly.) AutoCAD forces on you the A:
Enter pattern (on next line): A,
7. Press Enter to end linetype definition and you’re done. Well, not quite. You still need to test the pattern.
Which is exactly what we’ll do in the next section.
Summing up, you can write a new linetype definition within AutoCAD using the -Linetype Create command, as
follows (your responses are shown in boldface
boldface):
Command: -linetype
?/Create/Load/Set: c
Name of linetype to create: dit-dah
Wait, checking if linetype already defined ....
Descriptive text: . __ . __ . __ . __
Enter pattern (on next line):
A, .25,-.1,0,-.1
Command:
By the way, new linetypes are added to the end of the acad.lin file.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Use the -Linetype L oad command to load the pattern into drawing, as follows:
Load
Command: -linetype
?/Create/Load/Set: L
Linetype(s) to load: dit-dah
2. Up pops the Select Linetype File dialog box. Select acad.lin, and then click Open
File Open. AutoCAD confirms:
Linetype DIT-DAH loaded.
4. Here you can type either the name of a loaded linetype (such as “dit-dah”) or enter “?” to see which line-
types are already loaded. For fun, type ? , and AutoCAD tells you:
BYLAYER, BYBLOCK, or one of these loaded linetypes:
Name Description
------------------ -------------------------------
CONTINUOUS Solid line
DIT-DAH . __ . __ . __
5. This time, get serious and set the current linetype to “dit-dah”:
?/Create/Load/Set: s
New entity linetype (or ?) <BYLAYER>: dit-dah
?/Create/Load/Set: (Press Enter.)
6. Now, draw a line and appreciate the linetype it is drawn with. Your debugging session is over.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
3. When you scroll down to the end of the file, you see the Dit-Dah pattern, if you defined as per the earlier
tutorial.
4. You can modify an existing linetype, or add a new linetype. The process is exactly the same as when you did
it within AutoCAD, with two exceptions: (1) AutoCAD isn’t there to prompt you; and (2) You don’t need to
use the A prefix.
Line1: Header
* (asterisk) indicates the start of a new linetype definition. DIT-DAH Name of the linetype.
, (comma) separates the name from the description.
. __ . __ describes the linetype (to a maximum of 47 characters), which is displayed by the Linetype ? com-
mand.
Line 2: Data
A is the optional alignment flag, which forces AutoCAD to start and end the linetype with a line.
.25 is the length of a dash when LtScale = 1.0; every linetype data line must begin with a dash.
-.1 is the length of a gap when LtScale = 1.0; every linetype data line follows the initial dash with a gap.
0 is a dot.
You can use a semicolon ( ; ) to prefix any line as a comment line. Anything after the semicolon is ignored by
AutoCAD.
5. Save the .lin file with the same name (acad.lin) or a new name, then test it within AutoCAD.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Much of this should look familiar to you, with the exception of the stuff between the square brackets shown in
boldface
boldface. It’s the square brackets that allow the embedding of text in linetypes. Here’s what it means:
Text
"HW" prints the letters HW between the dashes.
Text Style
ST AND
STAND
ANDARDARD is the name of the text style to apply the text. This is optional; when missing, AutoCAD uses the
current text style, stored in system variable TextStyle
xtStyle.
Text Orientation
A=0.0 rotates the text relative to the x-axis (the “A” is short for absolute); this ensures the text is always oriented in
the same direction, no matter the direction of the line. By the way, the rotation is always performed within the text
baseline and capital height. That’s so that the text isn’t rotated way off near the orbit of Pluto.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Y=-0.05 shifts the text in the y-direction from the linetype definition vertex. In both cases, the units are in
linetype scale factor, which is stored in system variable LtScale
LtScale.
Summing up, you can create a text-based linetype with a single parameter, such as ["HW"] or you can exercise
fine control over the font, size, rotation, and position with six parameters.
Only problem is that Autodesk didn’t include a “linetype editor” to visually tweak the parameters until they
look right (MicroStation, for example, has a built-in linetype editor). Instead, it’s a tedious back and forth be-
tween editing the ltypeshp.lin file, then loading it into AutoCAD, and testing the linetype.
Embedding a Shape
But embedding text is not the last word in complex linetypes. Not at all. The other thing you can embed is a shape
from an .shx file. AutoCAD old timers will remember a time — say, about 19 years ago — when shapes were the
preferred substitute for blocks. Shapes were faster and more compact, a serious consideration when an 8MHz
8086 CPU was considered a hot machine, and math chips were too pricey to afford. Why, I recall when regener-
ating the Nozzle.dwg took over four minutes, when a hidden-line removal took all weekend, when...
The use of shapes pretty much faded away as CPUs grew faster and as math chips became free. With the
invention of the complex linetype, Autodesk found a new use for the languishing shape: ltypeshp.shx. The file has
the five shapes used by the complex linetypes. To use a shape takes these parameters:
*BATTING,SSSSSSSSSSSSSSSSSSSSSSSS
A,.0001,[BAT,ltypeshp.shx,s=.1],-.4
BAT This is the name of shape; when AutoCAD cannot find the shape, the linetype is merely drawn without it.
BAT
ltypeshp.shx is the name of compiled shape file; you can add your own shapes to this file, but coding shapes is hard
work (see chapter 8). Here’s what the coding for this batting symbol looks like in the source code ltypeshp.shp file:
*134,10,BAT 025,10,2,-044,04B,10,2,044,025,0
s=.1 is the scale factor for the size of the shape, as above.
3D Linetypes
Just kidding. There is no such thing as a 3D linetype in AutoCAD. If there were, I guess it might look like a bottle
brush or the ribs on an electrical cord’s strain relief.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. With the Notepad text editor, I opened the ltypeshp.shp source code file for the shapes used by complex
linetypes. (The file is found in the \support folder.) I added a parallel line shape, as follows:
*135,11,DUAL
2,014,1,020,2,02C,1,028,2,014,0
This code draws a pair of parallel line segments, each two units long. The parallel lines are offset by one unit
from the centerline. The shape codes have the following meaning:
3. I compiled the .shp file into an .shx file with AutoCAD’s Compile command. Since I made no errors,
AutoCAD was pleased with me:
Command: compile
Compiling shape/font description file
Compilation successful.
Output file c:\acad\support\ltypeshp.shx contains 132 bytes
That defined the double-line shape. Now I needed to define the linetype.
4. I switched back to Notepad, and loaded the ltypeshp.lin file. I wrote a parallel linetype definition, as follows:
*PARALLEL_LINES,======
A,[DUAL,ltypeshp.shx,s=.1]
This code is supposed to draw a parallel linetype. The linetype codes have the following meaning:
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
ltypeshp.shx is the name of the .shx file containing the shape code.
5. I switched back to AutoCAD and used the -Linetype L oad command to load the newly-defined linetype.
Load
Command: -linetype
?/Create/Load/Set: load
Linetype(s) to load: parallel_lines
AutoCAD displays the Select Linetype File dialog box. I select ltypeshp.lin, and then click the Open button.
File
AutoCAD complains:
Bad definition of PARALLEL_LINES at line 11 of file ltypeshp.lin:
Shape or text may not be first spec.
That means that I cannot have a pure parallel line shape; instead, AutoCAD demands there be a dash (such as .1),
a gap (-.1), or a dot (0) resulting in a less-than-perfect parallel line — a parallel line with gaps. In fact, AutoCAD
requires a dash (or gap) before and after the .shx shape, otherwise AutoCAD complains:
There must be between 2 and 12 dash/dot specs.
So, it appears that the best I can come up with is a broken parallel line created by the following .lin code:
*PARALLEL_LINES,= = = = = =
A,.01,[DUAL,ltypeshp.shx,s=.1],-.01
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
For this reason, the best way to deal with the problem is to apply the Offset command to a splined polyline. As for
the MLine command, it can consist of straight lines only. If you are really desperate, you could follow these steps:
1. Use the Explode command to reduce the mline to parallel line segments.
2. Use the PEdit Join command to: (1) turn the line segments into polylines; and (2) join the polyline seg-
ments into a single polyline.
3. Now use PEdit Spline or PEdit Fit command to create a smoothly flowing polyline.
Fit
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
w hen Autodesk first introduced hatch patterns to AutoCAD (many years ago in v1.4), they consisted of
just three simple elements: dashes, gaps, and dots. To create a repeating pattern, the pattern definition is offset by
a distance and an angle. During the intervening decades, the only change made by Autodesk was the addition of
associativity to Release 13: as the boundary changes, the pattern updates itself automatically.
In this chapter, we look at how to create a custom hatch pattern, and how to edit existing patterns. Even though
AutoCAD comes with many patterns, your office drafting standard may require a specific pattern. Or, you may
want to edit one of AutoCAD’s patterns, such as Dots (which has a serious problem: pretty much all laser printers
cannot plot the dots because they’re too tiny; additionally, the dots don’t show up in some drawing translations).
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
AutoCAD treats both kinds of hatch pattern as a block; extended entity data allows the HatchEdit command to
change the parameters of the pattern, such as its scale, spacing, and pattern name. You can use the Explode
command to explode the block into its constituent lines. As an alternative, prefix the pattern name with an asterisk
( * ) and AutoCAD draws the patterns as individual lines and dots, not as a block.
AutoCAD has several system variables that report the most-recent setting of hatch pattern parameters:
HpName Specifies the name of the current hatch pattern (default = ANSI31).
HpScale Specifies the current scale factor (default = 1.0).
HpAng Specifies the current angle of the hatch pattern in degrees (default = 0 degrees).
HpDouble Determines whether the hatch is applied a second time at 90 degrees.
HpSpace Specifies the spacing between hatch pattern lines (default = 1.0 units).
SnapAng Specifies the rotation angle of the hatch pattern in degrees (default = 0 degrees).
SnapBase Specifies the x,y-coordinates of the origin for the hatch pattern (default = 0,0).
The last two system variables let you control where the hatch pattern begins. Normally, the pattern assumes an
origin of (0,0) and an angle of 0 degrees. But if you need to precisely control the placement of the pattern, change
the values of SnapAng and SnapBase as required.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Hatch Command
Your options for creating a hatch patterns on-the-fly are really limited. Here’s how to do this with the Hatch
command:
1. Start AutoCAD.
TIP The hatch angle is measured from the setting of system variable SnapAng (0
degrees, by default, which is in the direction of the positive x-axis). When SnapAng is
set to something other than 0, the angle you specify here is added to the value stored in
SnapAng.
6. Third, decide if you want the pattern double-hatched. That means a second pattern is applied at 90 degrees to
the first pattern.
Double hatch area? [Yes/No] <N>: y
AutoCAD draws the pattern, but — as I mentioned earlier — your custom hatch pattern isn’t saved to the .pat file.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. From the menu bar, select Draw | Hatch (or, at the keyboard enter the BHatch command).
Boundaryy Hatch dialog box appears, select User Defined from the Pattern T
2. When the Boundar ype area.
Type
4. Click the PickP oints button and select the area you want hatched. AutoCAD automatically creates a bound-
ickPoints
ary, unlike the Hatch command.
5. Click Apply
Apply, and AutoCAD applies the hatch pattern.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. Open the acad.pat file from the \support folder for your version of AutoCAD.
3. Take a look at the seemingly-incomprehensible series of numbers and punctuation contained by this file. I’ve
reproduced the first dozen lines here; it’s my job to make them comprehensible to you:
;; ;; Ver. 12.0 - AutoCAD Hatch Pattern File ;;
*ANGLE, Angle steel
0, 0,0, 0,.275, .2,-.075 90, 0,0, 0,.275, .2,-.075
*ANSI31, ANSI Iron, Brick, Stone masonry
45, 0,0, 0,.125
*ANSI32, ANSI Steel
45, 0,0, 0,.375 45, .176776695,0, 0,.375
Angle is the angle at which this line of hatch pattern data is displayed. The “0” means the hatch line is drawn
horizontally; a “90” means the line is drawn vertically, and so on.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Y-origin means that the first line of the hatch pattern passes through this y-coordinate.
X-offset is the distance between line segments, aka the gap distance. You use this parameter only to specify the
offset for vertical or diagonal lines (To specify the distance between dashes, use the dash1 parameter.) In most
hatch patterns, x- offset has a value of 0.0. Even though this parameter is rarely used, it is not optional.
x-offset
Y-offset is the vertical distance between repeating lines; this parameter is used by every hatch pattern.
Dash1 defines the dashes in the hatch pattern line (the code is the same as for linetypes):
• A positive number, such as 0.25, is the length of the dash.
• A 0 draws a dot.
• A negative number, such as -0.25, draws a gap.
TIP The dot drawn by the hatch pattern is actually a zero-length line. This creates a
problem when it comes time to plot, since dots in a hatch pattern are not printed by some
plotters, especially laser printers. Instead of code 0, you should use a very short line
segment, such as 0.01.
When you are finished editing a pattern or creating a new one, save the .pat file with the same name or a new name.
Note that if you use a filename other than acad.pat, the filename must match the pattern name, otherwise
AutoCAD cannot find it. For example, you have created a new hatch pattern called “Earth” and you want it
separate from the acad.pat file. The filename must be earth.pat. Even though earth.pat can contain other hatch
pattern definitions (say, Forest, Meadow, and Lake), AutoCAD will never find them. The Forest pattern must be
added to acad.pat or by itself in forest.pat.
Each line of code applies to a single pattern segment; the two lines of data (above) represent a hatch pattern with
two lines.
Hatch pattern lines are drawn infinitely long. What this means is that AutoCAD draws the line as long as neces-
sary, as long as it reaches a boundary. AutoCAD will not draw the hatch pattern unless it does find a boundary.
At the very least, each line of pattern code must include the angle
angle, x- and y- origin
origin, and the x- and y-
y-origin offset
y-offset
offset. This
draws a continuous line.
The dash1 parameter(s) is optional but when used draws a line with the dash-gap-dot pattern.
There is no limit to the number of data lines for a hatch pattern definition. Very complex patterns can take dozens
and dozens of lines of code. But be careful: a complex hatch pattern takes a long time to draw. For this reason,
place hatch patterns on their own layer in a drawing, then freeze that layer. Thaw the layer when you need to see
the pattern or plot the drawing.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
For whatever reason, AutoCAD does not make it easy to change the origin of the hatch pattern, which is important
for accurate placement of the patterns or lining the pattern up with another pattern. To change the x,y-origin of a
hatch pattern upon placing it in the drawing, use system variable SnapBase
SnapBase. The effect of SnapBase on the hatch
pattern origin is additive: if the hatch pattern specifies that the lines start at 0.1,0.11 and SnapBase is 5,5, then
AutoCAD starts the hatch at 5.1,5.1.
If you are uncomfortable using system variables, then the Snap command provides the same opportunity via
the Rotate option:
Command: snap
Snap spacing or ON/OFF/Aspect/Rotate/Style: rotate
Base point <0,0>: 5,5
Rotation angle <0>: 20
The DSettings command (the old DdRModes command) lets you set these values via a dialog box: Snap Angle,
X Base, and Y Base.
You cannot specify a weight (or linewidth) for a hatch pattern line. The workaround is to define two or more very
closely spaced lines, such as:
*Thick_Line, Closely spaced lines
0, 0,0, 0,.25 0, 0,.01, 0,.25 0, 0,.02, 0,.25
You cannot specify arcs, circles, and other round elements in a hatch pattern file. Everything consists of straight
lines and dots. To simulate circular elements, use a series of very short dashes.
To draw dash and gap segments at an angle, use the sine of the angle in degrees, like this:
0 0
30 0.433
45 0.707
60 0.866
90 1.0
It’s a lot easier for someone else (or you, six months from now) to read your hatch pattern code if you use tabs and
spaces to format the code into nice columns, like this:
*AR-SAND, Random dot pattern
;angle x,-yorigin x,y-offset dash codes (dot, gap, dot, gap, dot, gap)
37.5, 0,0, 1.123,1.567, 0, -1.52, 0, -1.7, 0, -1.625
7.5, 0,0, 2.123,2.567, 0, -.82, 0, -1.37, 0, -.525
-32.5, -1.23,0, 2.6234,1.678, 0, -.5, 0, -1.8, 0, -2.35
-42.5, -1.23,0, 1.6234,2.678, 0, -.25, 0, -1.18, 0, -1.35
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
To illustrate the problem, I have added a dummy test hatch pattern (called “Dummy”) to the acad.pat file, using a
text editor such as Notepad. When I started the BHatch command, the “Dummy” pattern name appears, but the
graphical display area is blank. The problem here is how to make the pattern appear in the preview area.
There are two stages to solving the problem: (1) create a slide file from the hatch pattern; and (2) integrate the
slide file into the acad.slb file.
As the reader noted, instructions for creating a graphical preview of hatch patterns are: (1) well-hidden in the
AutoCAD documentation; and (2) not at all obvious. The only statement I could find in the hatch documentation
reads, “To see an image tile of any pattern, the pattern must have a slide with a matching name stored in acad.slb.”
Here’s how I created an “icon” from a hatch pattern:
TIP The SlideLib.Exe utility included with AutoCAD may contain a bug that prevents it
from appending .sld slide files to an existing .slb slide library file. A work-around is
described later in this chapter.
2. AutoCAD requires that the icon image have an aspect ratio of 3:2. Autodesk recommends that I use a paper
space viewport, because that restricts the MSlide command to taking a “snapshot” of the viewport, not the
entire drawing screen. For those two reasons, I typed the following commands to set up the window:
Command: tilemode 0
Command: mview 0,0 3,2
Command: zoom e
Command: rectang 0,0 3,2
The Tilemode 0 command turns off tilemode (to allow paper space viewports). The MV iew 0,0 3,2 com-
MView
mand creates a viewport with the 3:2 aspect ratio. The Zoom E command makes the viewport fill the
drawing screen to maximum size. And the Rectang 0,0 3,2 command draws a boundary for the hatch
pattern.
If at all possible, I use a scale of 1.0; this lets me see the hatch pattern’s size relative to other hatch patterns.
I only use a larger or smaller scale if I cannot see a representative sample of the pattern. When I scroll
the list of hatch patterns in the Boundar
Boundaryy Hatch dialogue box, I see some hatch patterns icons with an
asterisk ( * ) in the upper-left corner, such as pattern AR-B816. This indicates a hatch icon drawn at a scale
other than 1.0. You may want to adopt the same standard for yourself.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The MSlide command displays the Create Slide File dialog box. Type the same name as the hatch pattern,
File
such as dummy.sld. Then click the OK button.
6. (Optional) When my hatch pattern disappears with the dialog box, I use the Redraw command to bring it
back:
Command: redraw
7. (Optional) When I have more than one hatch pattern of which to make slides, I switch back to paper space
before employing the HatchEdit command:
Command: pspace
Command: hatchedit
I make changes to the pattern, and then switch back to model space and retake the slide:
Command: mspace
Command: mslide
When this gets tedious, I create a script file or toolbar macro to automate the process. The script file looks
like this:
PSpace HatchEdit Last MSpace MSlide Redraw
Now that I have created one (or more) slide files, it’s time to add them to the Aacad.slb (or aclt.slb in LT) master
slide library file.
The program that collects individual .sld (slide) files into an .slb library file is called SlideLib.Exe. If you are
running AutoCAD under Windows, you’ll be in for a rude shock here: you must switch to DOS to use SlideLib SlideLib;
Autodesk hasn’t gotten around to “Window-izing” this utility program.
Next shock: you cannot run SlideLib from the Windows File Manager because the program expects param-
eters on the command line — something only a DOS power user could love.
TIP If you have more than one .slb slide file, you need to create a list of names in yet
another file. Here’s what’s involved:
1. Start a text editor, such as Notepad.
2. Type the names of the .sld files, one per line:
dummy.sld
3. Save the file by any name ending with .txt, such as Sld-List.Txt. Make sure you
save the file in the same folder as where you saved the .sld files.
4. Exit the text editor.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
3. STOP! A bug in some versions of SlideLib causes it to replace the entire .slb file with your single .sld file,
instead of adding the slide. For this reason, copy the acad.slb (or aclt.slb) file to another folder.
4. Run the SlideLib program. There a couple of different ways to do this, depending on the version of
AutoCAD. (Notice that the name of the AutoCAD LT’s master slide library file is called aclt.slb):
C:\autocad\> slidelib acad < dummy.sld
These hieroglyphics mean that you want the SlideLib program to take the dummy.sld slide file and add it
( < ) to the acad.slb slide library file.
And if you have that list of slide files, you would type:
C:\autocad\> slidelib acad < sld-list.txt
5. The only indication SlideLib gives you whether it was successful is this data:
SLIDELIB 1.2 (3/8/89) (C) Copyright 1987-89 Autodesk, Inc. All Rights Reserved
7. Check that SlideLib did it job by starting the BHatch command in AutoCAD.
After learning the process, the reader responded: “Whew, I didn’t think it would be this involved. I have roughly
58 patterns I would like to do this with. I guess I’ve been hoping for some kind of shortcut to load all of these at
one time.”
There are some third-party applications that apparently are able to automate the process of adding hatch
patterns to the acad.slb file. You may want to search the Web for these.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
a utoCAD uses .shp and .shx files in three areas: shapes, fonts, complex linetypes, and GDT symbols. You
can create your own .shp files, which is the subject of this chapter.
Shapes were popular in the early days of AutoCAD, when computers were slow (every zoom and pan forced a
drawing regeneration, which could take minutes), and memory was scarce and expensive (1MB of RAM cost
$10,000). Shapes are like blocks, but take up a fraction of the memory; unlike blocks, however, shapes have to be
hand-coded using an arcane method described in this chapter. Shapes are loaded with the Load command, and
then placed in the drawing with the Shape command. The first time a .shp file is loaded, AutoCAD compiles it into
a .shx file automatically for faster execution and as a limited form of security.
Fonts were originally coded as shapes for the same reason: text was one of the slowest parts of the drawing
display (hence the QTQTeext command), and the shape definition allowed for efficient text. The drawback to shapes,
however, is that they are not well-suited to defining the complex curves that fonts require, nor can they fill the
font’s outline. Over the last decade, as computer became faster, Autodesk switched first to promoting PostScript
fonts (.psf), and then more recently TrueType fonts (.ttf). AutoCAD still supports .shx fonts; to use a .psf font, you
must first use the Compile command to change it to an .shx file. Fonts are loaded with the Style command, and
placed with the Text and MTMTeext commands.
Comple
Complexx linetypes is one area where shapes are still in use. The squiggles and text found in complex linetypes
are defined by shapes in the ltypeshp.shp file, found in the \autocad\support folder. Complex linetypes are loaded and
placed with the LType command. See chapter 6.
GDT symbols (geometric dimensioning and tolerancing) is the other area where shapes are still used. The
symbols are defined by shapes in the gdt.shp file found in the \autocad\support folder. The symbols are placed with
the Tolerance command.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
AutoCAD no longer includes any sample shape files; it does, however, include the source .shp files for the
ltypeshp.shx and gdt.shx files in \autocad\support folder.)
• .shx
shx are compiled shape files. AutoCAD compiles .shp files automatically into .shx format. Normally, you
cannot edit .shx files, unless you have access to a shape decompiler program written by third parties. (A
search in Google for “shx decompilers” comes up with several products.)
TIP When AutoCAD is installed on your computer, it places its .ttf fonts in the
\windows\fonts folder and its .shx fonts in the \autocad\fonts folder. All other .shx and
.shp files are found in the \autocad\support folder.
Header Fields
The general format of a shape definition a header lines, followed by one or more definition lines:
*shapeNumber,totalBytes,shapeName
byte1,byte2,byte3,...,0
The asterisk signals to AutoCAD that the next shape definition is starting.
shapeNumber
Each shape requires a unique number by which it is identified. For shapes, the numbers are usually sequential,
starting with 1; for fonts, the number is the equivalent ASCII code, such as 65 for the letter A.
TIP AutoCAD reserves shapeNumbers 256, 257, and 258 for the degree, plus-or-
minus, and diameter symbols. In Unicode fonts, these are numbered U+00B0, U+00B1
and U+2205 in the Latin Extended-A subset.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
After defining the shape, you have to add up the number of bytes that describe the shape, including the termina-
tor, 0. (Makes no sense to me.) There is a limit of 2,000 bytes per shape definition. Unicode shape numbers
count as two bytes each.
shapeName
Shape names must be in all uppercase. Because names with lowercase characters are ignored, you can use them
for in-line comments.
Definition Lines
The header line is followed by one or more lines that define the shape or font. This is the nitty-gritty part of shape
files, and you will now see why shapes are rarely used anymore.
byten
The shape is defined by “bytes,” called that because each code is a single byte (the common computer measure-
ment) in size. Bytes define vector lengths and directions, and instruction codes. The codes are all numbers, and
can be in decimal (base 10) or hexadecimal (base 16) format.
Definition lines are a maximum of 128 characters long (including commas), and a maximum of 2,000 bytes
overall (not including commas). The last definition line ends with a 0.
TIP When the first character of a byte is a 0, this means that the two characters
following are in hexadecimal, such as 00C (12, in decimal).
Vector Codes
Vector codes describe how the shape is drawn. They define movement (pen up) and drawing (pen down). Vector
codes are limited to 16 directions, as shown by the figure:
Notice that the lengths are not radial: the diagonal vectors (such as 2 and E) are 1.414 (square root of 2) times
longer than the orthogonal vectors (such as 4 and 0).
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Thus, 02C would draw a line 2 units long in the -y direction (downward). By now, you can see that you need to
understand hexadecimal notation.
Instruction Codes
In addition to describing direction and length, shapes codes provide drawing instructions. Code numbers can be
in decimal (dec) or hexadecimal (hex) . Notice that some codes rely on additional codes following. And, note that
drawing is limited to lines, arcs, and gaps.
Code 0 must mark the end of every shape definition. It appears at the end of the last line.
00C,(2,0,-127),0
Code 1 starts drawing mode (“pen” is down). By default, every shape definition starts with draw mode turned on.
Code 2 starts move mode (“pen” is up). In the sample below, the pen is raised before moving to a new location.
8,(36,63),2,8,(-36,-63),1,0
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Code 3 specifies the relative size of each vector. Each shape starts off at the height of one of the orthogonal
vectors, such as 4. To make the shape smaller, use code 3 followed by a byte specifying the scale factor, 1 through
255. For example, the following code draws the shape half as large:
3,2
TIP Within a shape definition, the scale factor is cumulative. Using the same scale code
twice multiplies the effect. For example, 3,2 followed by another 3,2 makes part of the
shape four times smaller.
At the end of the shape definition, return the scale to unity so that other shapes
are not affected.
To make the shape larger, use code 4 followed by a byte specifying the scale factor, 1 through 255. For example,
the following code draws the shape twice as large:
4,2
Note that you can use the 3 and 4 codes within a shape definition to make parts of the shape smaller and larger.
Code 5 saves the current x,y-coordinate to the stack memory. You then use code 6 to recall (pop) the coordinates
for later use. The stack memory is limited to four coordinates. By the end of the shape definition, you must recall
all coordinates that you saved; i.e., there must be an equal number of code 5s and 6s, as shown below:
2,14,8,(-8,-25),14,5,8,(6,24),1,01A,016,012,01E,02C,02B,01A,2,
8,(8,5),1,01A,016,012,01E,02C,02B,01A,2,8,(4,-19),14,6,
14,8,(8,-9),0
A stack is a specific type of memory called FILO memory, short for “first in, last out.” When two numbers are
stored in the stack memory, the last number stored is the first one out. Think of an elevator, where the first person
in is usually the last one out.
Code 6 recalls the most-recently saved coordinates from the stack memory.
7/007: Subshape
Code 7 calls a subshape, which is simply another shape. Shapes can be used within other shapes, which helps
reduce the tedium of coding shapes. Code 7 is followed by reference to another shape number, between 1 to 255.
(Recall that all shapes within a .shp file are identified by number.) For example:
7,2
calls shape 2 as a subshape. Unicode fonts use code 7 followed by a Unicode shape number between 1 to 65535.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Codes 8 and 9 overcome the restriction that the vector codes (limited to just 16 directions) place on the drawing.
Code 8 defines a distance using two bytes that range from -128 to 127:
8,xDistance,yDistance
In the first example, 8,(-21,-50) draws 21 units down (-x), and 50 units left (-y).
Whereas code 8 specifies a single coordinate, code 9 specifies a series of coordinates, terminated by (0,0). For
example:
9,(1,2),(-3,4),(5,-6),(0,0)
Code 10 defines an octant arc, which is an arc whose angle is limited to multiples of 45 degrees, as shown by the
figure.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Code11 is more useful because it draws arcs that are not limited to ending and starting at octant angles. Its
specification requires, however, five bytes:
11,startOffset,endOffset,highRadius,radius,- 0 startingOctant octantSpan
TIP Here is how Autodesk suggests finding the value of startOffset and endOffset:
1. Determine the offsets by calculating the difference in degrees between the
starting octant's boundary (which is always a multiple of 45 degrees) and the start of the
arc.
2. Multiply the difference by 256.
3. Divide the result by 45.
Code 12 draws a single-segment arc by applying a bulge factor to the displacement vector.
0C,xDisplacement,yDisplacement,bulge
The xDisplacement and yDisplacement specify the starting x,y-coordinates of the arc.
The bulge specifies the curvature of the arc. All three values range from -127 to 127.
Here is how Autodesk says the bulge is calculated: “If the line segment specified by the displacement has length
D, and the perpendicular distance from the midpoint of that segment has height H, the magnitude of the bulge
is ((2 * H / D) * 127).”
A semicircle (180 degrees) would have a bulge value of 127 (drawn counterclockwise) or -127 (drawn clock-
wise), while line would have a value of 0. For an arc of greater than 180 degrees, use two arcs in a row.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Code 13 draws a polyarc, an arc with two or more parts. It is terminated by (0,0).
13,(0,2,127),(0,2,-127),(0,0)
TIP To draw a straight line between two arcs, it is more efficient to use a zero-bulge
arc, than to switch between arcs and lines.
Code 14 is for fonts only, and only fonts that are designed to be placed horizontally and vertically. When the
orientation is vertical, the code following is processed; if horizontal, the code is skipped.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Script Files
Script files have an extension of .scr. Script files are in plain ASCII. For that reason, don’t use a word processor,
such as WordPad, OpenOffice, or Word. Instead, use Notepad to write scripts.
Sometimes, when I feel like a DOS power user, I write scripts at the DOS prompt:
C:\> copy con filename.scr
;This is the script file
line 1,1 2,2
circle 2,2 1,1
When I’m done, I press F6 or Ctrl Z to tell DOS that I’ve finish editing, and to close the file.
Ctrl+Z
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Script . . .115
RScript . . .115
Resume . . .115
Delay . . .115
Special Characters . . .115
(space) . . .115
; (semicolon) . . .116
* (asterisk) . . .116
Backspace . . .116
Esc . . .116
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
• Some commands have different names, such as (dialog box version in brackets): -Layer (Layer
Layer or
DdLModes in AutoCADs older than 2000), ChP rop DdChP
ChProp (DdChP rop
DdChProp
rop), and FileOpen Open
(Open
Open). Generally, in
older versions of AutoCAD, all commands that start with Dd have a non-dialog box version available with a
different name; in newer versions of AutoCAD, the hyphen ( - ) prefix indicates the command-line version
of the command.
Sometimes it’s a command and other times it’s a system variable. For example, the DSettings
DdRModes in older AutoCADs) dialog box controls about a dozen system variables. If a script needs to
(DdRModes
change a layer, use the -Layer command — or better yet — the CLayer system variable, as follows:
; Change layer:
clayer layername
• Some commands need system variable FileDia turned off (set to 0). This forces any command that displays
the Open F ile or Save F
File ile dialog boxes — such as DxfIn
File Script, and VSlide — to prompt for the filename
DxfIn, Script
at the command line. Thus, a script file would include the following lines to turn off dialog boxes:
; Turn off dialog boxes:
filedia 0
; Load slide file:
vslide filename
When FileDia is turned off, use the ~ (tilde) as a filename prefix to force the display of the dialog box. For
example:
Command: script
Script file: ~ (AutoCAD displays Select Script File dialog box.)
• Prior to AutoCAD 2000, the Plot command has its own system variable to turn off its dialog box: when
CmdDia = 0, it showed prompts at the command line, like this:
Command: plot
What to plot -- Display, Extents, Limits, View, or Window <D>:
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
An alternative to controlling the plot process is to pre configure a bunch of .pcp files. These hold “plot
configuration Parameters,” and can be accessed via a pair of system variables:
Plotter lets me select a plotter configuration.
PlotId tells me the name of the current plotter configuration.
• Some commands use the - (hyphen) as a prefix to force the command line version. To use these in a script
file, prefix the hyphen, as follows:
; Start the multiline edit command:
-mledit
Instead of the Multiline Edit Tools dialog box, AutoCAD displays the following prompt:
Tools
Mline editing option AV/DV/CC/OC/MC/CT/OT/MT/CJ/CS/CA/WA:
I leave it as an exercise to the reader to figure out the meaning of those 12 options!
• Some commands have no command-line version. The list primarily consists of commands related to OLE
and rendering: OleLinks
OleLinks, Render
ender, Lights
Lights, Scene
Scene, and so on. There is no way to control these commands
from a script file.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Script
The Script command performs double-duty: (1) it loads a script file; and (2) immediately begins running it:
Command: script
Enter script file name <C:\AutoCAD\Drawing1.scr>: filename
Remember to turn off (set to 0) the FileDia system variable, so that prompts appear at the command line, instead
of the dialog box.
RScript
Short for “repeat script,” this command re-runs whatever script is currently loaded in AutoCAD. A great way to
creating an infinite loop. There are no options:
Command: rscript
Story Time: When AutoCAD first introduced AutoLISP in version 2.17, it was a rudimentary form of LISP that
Autodesk called “Expressions and Variables.” It was so weak that it lacked conditional expressions, such as if-
then, while, and repeat. In fact, Autodesk CEO John Walker said there was no way to create a loop in Expressions
and Variables. Third-party programmers proved him wrong by using the RScript command to repeat AutoLISP
functions.
Resume
This command resumes a paused script file. Pause a script file by pressing the Backspace key. Again, no options:
Command: resume
Delay
To create a pause in a script file without human intervention, use the Delay command along with a number. The
number specifies the pause in milliseconds, where 1,000 milliseconds equal one second. The minimum delay is 1
millisecond; the maximum is 32767 milliseconds, which is just under 33 seconds.
While you could use Delay at the ‘Command:’ prompt, that makes little sense; instead, Delay is used in a
script file to wait while a slide file is displayed or to slow down the script file enough for humans to watch the
process, like this:
; Pause script for ten seconds:
delay 10000
Special Characters
In addition to these four script-specific commands, there are some special characters and keys.
(space)
The most important special characters are invisible: both the space and the carriage return (or end-of-line) repre-
sent you pressing the spacebar and Enter key. In fact, both are interchangeable. But the tricky part is that they are
invisible.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
How many spaces are there between attedit and the coordinates 1,2 1,2? I’ll wait while you count them ... For this
reason, it is better to place one script item per line, like this:
; Edit the attributes one at a time:
attedit
1,2
Now it’s easier to count those four spaces, since there is one per blank line.
; (semicolon)
You probably have already noticed that the semicolon lets you insert comments in a script file. AutoCAD ignores
anything following the semicolon.
' (apostrophe)
Scripts can be run transparently during a command. Simply prefix the Script command to run a script while
another command is active, like this:
Command: line
Specify first point: 'script
>>Script file: filename
The double angle bracket >> is AutoCAD’s way of reminding you that it has two commands on the go. In fact,
all four of AutoCAD’s script-specific commands are transparent, even 'Delay
'Delay. That lets you create a delay during
the operation of a command — as if I needed an excuse to run AutoCAD slower!
* (asterisk)
There is one special case where the asterisk gets used. When you prefix the VSlide command with the *, AutoCAD
pre-loads it to provide faster slide viewing performance:
*vslide
Backspace
Esc
...stops a script file dead in its tracks; use the RScript command to start it up again from the beginning (In Release
12, LT R2, and earlier, press Ctrl+C
Ctrl+C, instead, to stop the script).
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
f or a dozen years, the status line of AutoCAD remained unchanged. Right though to Release 11, the status line
displayed O (ortho is on), S (snap is on), T (tablet is on), the x,y-coordinates, and the layer name. Newer additions
included P (paper space is on) and a square indicating the current color.
For all that AutoCAD does, those seven indicators are not enough. Users wanted more information, even
fundamentally basic information, such as the missing z-coordinate. The official Autodesk response was along the
lines of, We wouldn’t be able to add more without missing out on what some other user wants, so it’s best we do
nothing. Sometimes, however, the display driver allowed users to customize the status line to a limited extent.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
[ . . .123
$(if, . . .123
$(getvar,dimaso) . . .123
,!. . . .123
) . . .123
/vAssociative Dimensions . . .124
] . . .124
'_dimaso . . .124
$M= . . .124
$(-,1, . . .124
$(getvar,dimaso) . . .124
) . . .124
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
No doubt, the purpose of the $-sign is to alert the AutoCAD command processor that a Diesel expression is on the
way, just as the ( symbol alerts AutoCAD that an AutoLISP expression is coming up.
The opening and closing parentheses signal the beginning and end of the function. This allows Diesel func-
tions to be nested, where the result of one function is evaluated by another function. Also, the parentheses allow
Diesel to work on more than one variable at a time. The closing parenthesis alerts Diesel that there aren’t any more
variables.
Diesel works with 28 functions names (there were just 15 in AutoCAD LT Release 1 and 2; 27 in AutoCAD
LT for Windows 95). All Diesel functions take at least one variable; some take as many as nine variables.
A comma always separates the function name and the variable(s). Diesel tolerates no spaces.
Math Functions
+ Addition
- Subtraction
* Multiplication
/ Division
Logical Functions
= Equal
< Less than
> Greater than
!= Not equal
<= Less than or equal
>= Greater than or equal
and Logical bitwise AND
eq Determines if all items are equal1
if If-then
or Logical bitwise OR
xor Logical bitwise XOR
Conversion Functions
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
System Functions
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Enter the ModeMacro system variable at the ‘Command:’ prompt, and type something:
Command: modemacro
New value for MODEMACRO, or . for none <"">: Tailoring AutoCAD
Depending on where the status line is in your copy of AutoCAD, the words “Tailoring AutoCAD” should
appear near to (or in place of) the coordinate display:
2. To restore the status line, type the ModeMacro system variable with a "" (null string), as follows:
Command: modemacro
New value for MODEMACRO, or . for none <"Tailoring AutoCAD">: ""
3. To display the value of a system variable on the status line, use the $(getvar function. This function gets the
value of a system variable, and displays it on the status line. Use the function to display the current elevation
by calling the Elevation system variable, as follows:
Command: modemacro
New value for MODEMACRO, or . for none <"">: $(getvar,elevation)
$?
This error message means you left off the right parenthesis; for example: $(+,1,2
Or, you forgot the left quotation mark; for example: $(eq,"T
$(eq,"Too
$(func)??
You typed the wrong name of the function; for example, $(stringlenth, ... )
$(func,??)
You provided the wrong number of arguments the function; for example, $(if)
$(++)
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
When on, AutoCAD displays a step-by-step evaluation of the Diesel macro in the Text window. Here’s how it
works for this Diesel macro, which converts the value of the fillet radius to metric: $(*,2.54, $(getvar,filletrad))
$(getvar,filletrad))
Command: macrotrace
New value for MACROTRACE <0>: 1
Command: modemacro
New value for MODEMACRO, or . for none <"">: $(*,2.54,$(getvar,filletrad))
Eval: $(*, 2.54, $(getvar,filletrad))
Eval: $(GETVAR, filletrad)
===> 0.5
===> 1.27
A bug in MacroT race causes it to reevaluate the most recent Diesel expression over and over again. Each time I
MacroTrace
type something at the ‘Command:’ prompt (such as the Line command), MacroT race re-displays its evaluation.
MacroTrace
MacroTrace
It does not, however, interfere except visually. For this reason, turn off MacroTrace when you no longer need it, as
follows:
Command: macrotrace
New value for MACROTRACE <1>: 0
Tip #1: Each argument must be separated by a comma; there must be no spaces within the expression.
Tip #2: The maximum length of a Diesel macro is approximately 460 characters; the maximum display on the
status line is roughly 32 characters.
Tip #3: Use the ModeMacro system variable to output the Diesel macro to the status line; ModeMacro outputs
directly to the status line, until it reaches a $(
$(, then it begins evaluating the macro.
Tip #4: To prevent evaluation of a Diesel macro, use quoted strings : "$(+,1)"
"$(+,1)"; to display quotation marks on the
status line, use double quotations: ""Test""
""Test""
Tip #5: Use the MacroTrace system variable to debug the macro.
MacroTrace
Tip #6: Use AutoLISP’s (strcat) function to string together a Diesel macro within AutoLISP.
Tip #7: Use the $M= construct to use Diesel expressions in a menu macro.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
(When you type this in, make sure you type it as one long line of text; don’t break the line, or the macro won’t
work!)
Before we step through the menu macro, bit by bit, keep this in mind: A menu macros have two parts: (1) the
label, which is inside the square brackets (shown in cyan); and (2) the macro code, which follows the square
brackets (shown in black).
The opening square bracket is the start of a macro label. That’s the word(s) you see on pull-down menus. In this
case, you would see Associative Dimensions
Dimensions, with or without the check mark.
$(if,
Here starts the if Diesel expression, which tests the following expression. If the expression is true, then apply the
next expression. “True” in Diesel means the expression has a value of 1; “false” means the value is zero.
$(getvar,dimaso)
This is an embedded Diesel expression that gets the value of system variable DimAso
DimAso. This system variable has
two possible values, which has four different meanings, depending on who is accessing the value:
,!.
Recall that the comma separates expressions and values in a Diesel statement. No spaces are allowed! The pair of
characters !. (called a metacharacter) are interpreted by AutoCAD’s menu system to mean “display a check mark.”
I hope you can see how the check mark is displayed by the above bit of Diesel code: the if statement uses the
!. metacharacter to display the check mark whenever the value of DimAso is true. When DimAso is false (equals
0), the Diesel if statement prevents the !. metacharacter from being activated.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The / metacharacter is how AutoCAD displays the underlined character in pull-down menus. In this case, the v in
Associativve is underlined. Recall that the underlined character is the keyboard shortcut: you don’t need
the word Associati
to pick Associative Dimensions with the mouse; you can press the letter v if you are so inclined.
The closing square parenthesis ends the label section of the menu macro. What follows is the actual menu macro:
'_dimaso
This is the only part of the menu macro that looks recognizable to me. It’s the DimAso system variable. Recall that
all system variables can be typed at the ‘Command:’ prompt like a command; the SetV ar command is optional.
SetVar
DimAso is prefixed by the ' (apostrophe) to make it a command transparent; and it is further prefixed by the _
(underscore) to internationalize the command name.
$M=
The $M= combination of characters is a special code to alert AutoCAD that a Diesel function is coming. Why
here, and not earlier inside the label? I dunno. My guess is that AutoCAD treats the stuff inside the label section
— [inside the square brackets] — as plain text input. Text in the macro area (following the square brackets) is
treated as code, and the $M= could have something to do with storing data on the stack. (The stack is a simple
form of memory known as FILO — first in, last out — used by AutoCAD’s menu programming system to
remember jumps between menus.)
$(-,1,
This is the Diesel function that subtracts. In this case, it is subtracting from 1, the value following (shown below).
$(getvar,dimaso)
Embedded inside the subtract function is Diesel’s GetV ar function again. This time, however, after the value of
GetVar
DimAso is gotten, it is subtracted from 1, then stored back into DimAso
DimAso. That makes me want to ask, “Where the
heck is all that going on?” It’s true that there is no equivalent $(setvar function in Diesel; the change in the value
of DimAso happens sort of automatically. The effect of the code is to toggles the value of the DimAso variable, as
follows:
1 (default) 1-(DimAso) 0
0 1-(DimAso) 1
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
For example, here is the code reused for toggling the display of the grid:
[$(if,$(getvar,gridmode),!.)/GGrid Markings]'_gridmode $m=$(- ,1,$(getvar,gridmode))
The macro is one long line; don’t split it into two lines in your menu file!
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The FilletRad system variable stores the current setting for the filleting radius.
The M= should be familiar from the earlier discussion of using Diesel inside of menu macros.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
w hile toolbar and menu macros are easy to create, they limit your ability to control AutoCAD. In this
chapter, we look at the most powerful way for a non-programmer to customize AutoCAD.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Copyright Information
This book is covered by copyright. As the owner of the copyright, upFront.eZine Publishing, Ltd. does not give you
permission to make electronic or print copies. You may not claim authorship or ownership of the text or figures
herein.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
1. Start AutoCAD, any version from v2.18 through to today’s most recent version. (LT users can read along,
just in case AutoLISP ever shows up again!) There is no need to open a drawing.
2. When the ‘Command:’ prompt appears, type the boldface text, shown below, on the keyboard:
Command: (+ 9 7) (Press Enter.)
16
Command:
AutoCAD instantly replies with the answer, 16. However, getting to that answer through (+ 9 7) may seem
convoluted to you. That’s because AutoLISP uses prefix notation: the operator, +, appears before the operands,
9 and 7. Think of it in terms of “add 9 and 7.” This is similar to how AutoCAD itself works: type in the
command name first (such as Circle
Circle), and then enter the coordinates of the circle.
3. Parentheses surround every AutoLISP statement. Indeed, LISP is sometimes said to be short for “lost in
stupid parentheses.” Every opening parenthesis, (, requires a closing parenthesis, ). I’ll tell you right now
that balancing parentheses is the most frustrating aspect to AutoLISP. Here’s what happens when you leave
out the closing parentheses:
Command: (+ 9 7 (Press Enter.)
1>
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
5. The parentheses serve a second purpose by alerting AutoCAD that you are using AutoLISP. When you start
to enter the same AutoLISP function ‘+ 7 9’ without parentheses, AutoCAD reacts unfavorably to each
space character you type:
Command: + (Press Spacebar.)
Unknown command "+". Type ? for list of commands.
Command: 9 (Press Spacebar.)
Unknown command "+". Type ? for list of commands.
Command: 7 (Press Spacebar.)
Unknown command "+". Type ? for list of commands.
Command:
6. As you probably suspect, AutoLISP provides all the basic arithmetic functions: addition, subtraction,
multiplication, and division. Try each of the other three, first subtraction:
Command: (- 9 7)
2
Command:
Oops, that’s not correct! Dividing 9 by 7 is 1.28571, not 1. What happened? Up until now, you have been working
with integer numbers (also known as whole numbers). For that reason, AutoLISP has been returning the result as
an integer number, although this was not apparent until you performed a division.
To work with real numbers, add a decimal suffix. This converts integers to real numbers and forces AutoLISP
to perform real- number division, as follows:
Command: (/ 9.0 7.0)
1.28571
Command:
Note how the parentheses aid in separating the nesting of the terms.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. Instead of typing the value for the diameter, enter the AutoLISP equation, as follows:
Diameter: (/ 9.0 7)
Command:
AutoCAD draws a circle with a diameter of 1.28571 inches. You can use an appropriate AutoLISP function
anytime AutoCAD expects user input.
3. Now go on to the -Ar ray command, and draw the other six circles, as follows:
Array
Command: -array
Select objects: L
1 found Select objects: (Press Enter.)
Rectangular or Polar array (R/P): (Press Enter.)
Number of rows (---) <1>: (Press Enter.)
Number of columns (|||) <1>: 7
Distance between columns (|||): (/ 9.0 7.0)
Once again, you use AutoLISP to specify the array spacing, which happens to equal the circle diameter.
1. To do this, you employ the most common AutoLISP function known as SetQ SetQ. This curiously named
function is short for SET eQual to. To save the result of a calculation, use the SetQ function together with a
variable, as follows:
Command: (setq x (/ 9.0 7))
1.28571
Command:
From algebra class, you probably recall equations like ‘x = 7 + 9’ and ‘x = 7 / 9’. The x is known as a
variable because it can have any value. In this case, x remembers the result of the (/ 9.0 7.0) calculation.
Notice the extra set of parentheses.
2. To prove to yourself that x contains the value of 1.28571, use AutoCAD’s ! (exclamation) prefix, as follows:
Command: !x
1.28571
Command:
The ! prefix (sometimes called “bang”) is useful for reminding yourself of the value contained by a variable,
in case you’ve forgotten or are wondering what happened during the calculation.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
4. Redo the Circle and -Ar ray commands, this time using variable Dia
Array Dia, as follows:
Command: circle
3P/2P/TTR/<Center point>: (Pick a point.)
Diameter/<Radius>: !dia
Command: -array
Select objects: L
1 found Select objects: (Press Enter.)
Rectangular or Polar array (R/P): (Press Enter.)
Number of rows (---) <1>: (Press Enter.)
Number of columns (|||) <1>: 7
Distance between columns (|||): !dia
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Math Functions
In addition to the four basic arithmetic functions you learned to use, AutoLISP has many of the mathematical
functions you might expect in a programming language. The list includes trigonometric, logarithmic, logical, and
bit manipulation functions; one type of function missing is matrix manipulation. For example, the Min function
returns the smallest (minimum) of a list of numbers:
Command: (min 7 3 5 11)
3
To remember the result of this function, use the SetQ function, as follows:
Command: (setq minnbr (min 7 3 5 11))
3
Now each time you want to refer to the minimum value of that series of numbers, you can refer to variable
Minnbr
Minnbr. Here’s an example of a trig function, sine:
Command: (sin minnbr)
0.14112
TIP You must provide the angle in radians (such as the Minnbr), not degrees. This is
an inconvenience, because if you are working with degrees, you must first convert the
degrees to radians. Fortunately, AutoLISP can do this for you, so long as you code it
correctly. Recall that there are 2*pi (approximately 6.3) radians in 360 degrees. For
example, to get the sine of 45 degrees, you have to indulge in some fancy footwork, first:
Command: (sin (* (/ 45 180.0) pi))
0.707107
Here I divided the degrees (45) by 180, then multiplied by pi. Remember from the last
tutorial that either the 45 or the 180 needs the decimal ( .0 ) to force division of real
numbers, rather than integers. By the way, PI is the only constant predefined by
AutoLISP and is equal to 3.1415926. That means you just type PI, instead of 3.1415926
each time you need the value of pi in a function. To see this for yourself, use the exclama-
tion mark at the command prompt:
Command !pi
3.14159
AutoLISP displays the results to six decimal places, even though it performs calculations
to 32-bit accuracy.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
TIPS Don’t use a comma: use a space to separate the values of the coordinates.
Note also that if you leave out the z-coordinate, AutoLISP assumes it equals
0.0000.
Other geometric functions of interest include the angle from 0 degrees (usually pointing east) to the line defined
by P1 and P2
P2:
Command: (angle p1 p2)
5.88611
The result is returned in radians. The intersection of two lines is determined by Inters
Inters:
Command: (inters pt1 pt2 pt3 pt4)
The x,y,z- coordinates that result from applying an object snap mode to a point. The object has to actually exist:
Command: line
From point: !p1
To point: !p2
To point: (Press Enter.)
where the "mid" refers to the midpoint object snap mode. Thus, in this function, you are finding the midpoint of
the line that starts at P1 (1.3, 5.7).
The other geometric functions are Textbo
xtboxx (find the rectangular outline of a line of text) and Polar
olar, returns a
3D point of a specified distance and angle.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Let's break this down to see how the function compares with our statement:
(if If
(> greater than
height floor-to-ceiling distance
96) 8 feet;
Then
(setq sets 14) use 14 steps.
Else
(setq steps 13) use 13 steps.
)
The StrL en (short for STRing LENgth) function tells you that “AutoCAD World” has 13 characters in it, count-
StrLen
ing the space. Notice how “AutoCAD World” is surrounded by quote marks. That tells AutoLISP you are work-
ing with a string, not a variable. If you type (strlen AutoCAD W
AutoCAD orld)
World)
orld), AutoLISP tries to find the length of the
strings held by variables Autocad and World. For example:
Command: (setq autocad "A software package")
"A software package"
Other string functions change all characters to upper or lower case, returns part of a string, finds a pattern in a
string, and join two strings together, as follows:
Command: (strcat autocad " used all over " world)
"A software package used all over The planet earth"
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Notice the similarity between the mode numbers and the values of system variable AUnits
Units. The coincidence is not
accident. When you don’t know ahead of time the current setting of units, you make use of this fact by specifying
the mode number as a variable, as follows:
Command: (angtof "45d37'11\"" (getvar "aunits"))
0.796214
In the Command function, you mimic what you type at the ‘Command:’ prompt like this:
Command: (command "circle" "2,2" "D" "1.5")
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
(Don’t worry about that ‘nil’ at the end; that’s just AutoLISP’s way to letting you know it is finished with its work.
Later in this chapter, you learn how to prevent nil from appearing.)
Let’s look at one of the more complex commands to use with the Command function, Text xt. When we use the
Text command, AutoCAD presents these prompts:
Command: text
Justify/Style: 5,10
Height <0.2000>: 1.5
Rotation angle <0>: (Press Enter.)
Text: Tailoring AutoCAD
When you don't include that final "", then you leave AutoCAD hanging with a ‘To point:’ prompt and your
AutoLISP routine fails.
By now it should be clear to you that you have to really know the prompt sequence of AutoCAD’s more than
300 commands to work effectively with the Command function. The easiest way to get a handle on those is to
purchase one of the “quick reference” books on the market, which list commands in alphabetical order, along with
the complete prompt sequence. And, as we see in a minute, check that the quick reference book has a listing of all
system variables, their default value, and the range of permissible values.
But the Command function has a failing. Earlier, I said, “Anything you type at the ‘Command:’ prompt is
available with the Command function.’ I place the emphasis on the word type. The Command function breaks
down completely when it comes to dialog boxes. That’s right: any command that uses a dialog box won’t work
with the Command function — nor, for that matter, with the toolbar macros we looked at a couple of chapters ago.
It is for this reason that AutoCAD includes command line versions of almost every (but not all) command.
While you could use the Command function to access system variables, AutoLISP has a pair of more direct
functions: GetV
GetVarar and SetVar
ar. GetV
SetVar ar gets the value of a system variable, while SetV
GetVar ar changes (sets) the value.
SetVar
For example, system variable SplF rame determines whether the frame of a spline polyline is displayed; by
SplFrame
default, the value of SplFrame is 0: the frame is not displayed, as confirmed by GetV
SplFrame ar
GetVar
ar:
Command: (getvar "splframe")
0
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
However, we have made a crass assumption here: that the initial value of SplF rame is 0. Zero is the default value
SplFrame
but not necessarily the value at the time that you run the AutoLISP routine. How do we know what the value of
SplF rame is before we change it? We'll answer that question later in this chapter. Stay tuned.
SplFrame
GetXXX Functions
It’s one thing to execute a command to draw a new object, such as the new circle and text we drew above with the
Command function. It is trickier working with objects that already exist, such as moving that circle and editing
the text. That’s where the a group of functions known collectively as Getxxx come into play. These get data from
the screen. Some of the more useful ones include:
Here’s how to use some of these with the Text command from above. Let’s redo the code so that AutoLISP
prompts us for everything first, then executes the Text command:
Command: (setq TxtStr (getstring T "What do you want to write? "))
What do you want to write? Tailoring AutoCAD "Tailoring AutoCAD"
Notice that extra "T"; that’s a workaround that lets GetString accept a string of text with spaces. When you leave
out the T, then GetString only accepts text up to the first space: you would end up with just “Tailoring” and no
“AutoCAD.” The SetQ function stores the phrase “Tailoring AutoCAD” in the variable TxtStr TxtStr.
Command: (setq TxtHt (getreal "How big do you want the letters? "))
How big do you want the letters? 2
2.0
Notice how GetReal converts the 2 (an integer) to a real number, 2.0.
GetReal
Command: (setq TxtAng (getangle "Tilt the text by how much? "))
Tilt the text by how much? 30
0.523599
Notice how GetAngle converts the 30 (a decimal degree) into radians, 0.523599.
Command: (setq TxtIns (getpoint "Where do you want the text to start? "))
Where do you want the text to start? (27.8068 4.9825 0.0)
Notice how GetPoint returns the x, y, and z values of the coordinate, even though z is zero. Finally, we execute the
GetPoint
Text command with the four variables:
Command: (command "text" TxtIns TxtHt TxtAng TxtStr)
text Justify/Style:
Height <1.5000>: 2.000000000000000
Rotation angle <0>: 0.523598775598299
Text: Tailoring AutoCAD
Command: nil
There! We've just customized the Text command to our liking. Not only did we change the prompts that the user
sees, but we change the order of the prompts.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
AutoCAD’s Select command can only deal with one selection set at a time; the AutoLISP SSxxx commands can
work with up to 128 different selection sets.
The Ent prefix is short for entity, the old name for AutoCAD objects. The “symbol table” refers to the part of the
drawing database that stores the names of layers, text styles, and other named objects in the drawing.
To create and manipulate objects, these AutoLISP functions work with a variant on the DXF format, known
as “dotted pairs.” For example, to work with a layer named RightOfWay, you employ the following format:
"2 . RightOfWay"
Once again, the quotation marks indicate the start and end of the data, while the dot in the middle separates the
two values: 2 is the DXF code for layer names, and RightOfW
RightOfWayay is the name of the layer. You can see that to work
with these object manipulating functions, you need a good grasp of the DXF format.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
The Id Command
AutoCAD has the Id command. When you pick a point on the screen, it tells you the 3D x,y,z- coordinates of the
point. Problem is, Id reports the value in the command prompt area, like this:
Command: id
Point:(Pick a point.)
X = 8.9227 Y = 6.5907 Z = 0.0000
Wouldn’t it be great if you could change Id to place the coordinates in the drawing, next to the pick point? That
would let you label x,y-coordinates and z-elevations easily all over a site plan. With AutoLISP, you can.
Part 1. Obtain the coordinates from the drawing, probably by picking a point.
Part 2. Place the coordinates as text in the drawing.
AutoLISP provides several ways to get the coordinates of a picked point. Browsing through the Customization
Guide, we find we could:
• Use the Id command with the Command function, as in (command "ID") "ID").
• Use the LastP oint system variable with the GetV
LastPoint ar function, as in (getvar "lastpoint")
GetVar "lastpoint").
• Use the GetP oint function, as in (getpoint "P
GetPoint ick a point: ")
"Pick
It would be a useful lesson to use each of the three and see what happens. By experimenting, you make mistakes,
then learn from the mistakes.
1. Start AutoCAD, load a drawing, and switch to the Text window with F2
F2. At the ‘Command:’ prompt, type:
Command: (command "ID")
You are executing an AutoCAD command from within an AutoLISP routine. The Command function lets
you use any AutoCAD command in AutoLISP. The AutoCAD command is in quotation marks "ID ID
ID"
because the command is a string (programmer talk for “text”). Just like before, AutoCAD prompts you for
the point.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
That’s great! You’ve typed in a tiny AutoLISP routine. Now, AutoCAD stores the x,y,z- coordinates of the
last-picked point in system variable LastPoint
LastPoint
oint.
3. Before we can place the coordinates as text in the drawing, we have to store the coordinates in a variable.
Recall from earlier tutorials that the SetQ function lets us store a value in a variable. Let’s make use of this
now. Type at the ‘Command:’ prompt:
Command: (setq xyz (getvar "LastPoint"))
(8.9227 6.5907 0.0000)
Xyz is the name of the variable we are using to store the x,y,z-coordinates. GetV
GetVarar is the name of the
LastP
AutoLISP that retrieves the value stored in a system variable. And "LastP oint
LastPoint
oint" is the name of the system
variable; once again, it is surrounded by quotation marks because it is a string.
After typing the AutoLISP function, AutoCAD returns the value it has stored in variable Xyz Xyz:
(8.9227 6.5907 0.0000). Note how the coordinates are surrounded by parenthesis. This is called a list and is
the list format that LISP is famous for (LISP is short for “list processing”). The spaces separate the
numbers, which are the x, y, and z-coordinates, respectively:
x = 8.9227
y = 6.5907
z = 0.0000
AutoCAD always stores these values in the order of x, y, and z. You will never find the z- coordinate first or
the x-coordinate last.
4. So, we’ve now solved the first problem in one manner. We obtained the coordinates off the drawing and
stored them in a variable. We did mention a third AutoLISP function we could use, GetP oint
GetPoint
oint. Programmers
prefer GetP oint because it is more efficient than the Id-LastP
GetPoint oint combo we used above. Type the following
Id-LastPoint
to see that it works exactly the same:
Command: (setq xyz (getpoint "Point: "))
Point: (Pick a point.)
(8.9227 6.5907 0.0000)
As before, we use the SetQ function to store the value of the coordinates in variable Xyz. The GetP oint
GetPoint
function waits for you to pick a point on the screen. The "Point: " is called a prompt and tells the user what
"Point:
the program is expecting the user to do. In this case, we mimicked the prompt of the ID command.
That’s right. No prompt. Just a silent AutoCAD waiting patiently for the right thing to happen ... and the
user puzzled at why nothing is happening. A lack of communication, you might say. That’s why prompts are
important.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
This is where I find a quick reference book handy that lists all the options of every AutoCAD command. Let’s see
if we can now construct the AutoLISP function for placing the coordinates as text:
200 is the height of the text. Change this number to something convenient for your drawings.
xyz — we’re lucky: the Text command accepts numbers stored in variables as text.
AutoCAD runs through the Text command, inserting the responses for its prompts, then placing the coordinates
as text. We’ve solved the second part of the problem.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
There we have it: a full-fledged AutoLISP program. Well, not quite. It’s a pain to retype those two lines each time
you want to label a point. In the next part of this chapter, we find out how to save the code to a .lsp file on disk. We’ll
also dress up the code, including suppressing that "nil" that gets output at the end of the routine.
3. Highlight the text: Press the mouse button and drag the cursor over the "X = 8.9227 Y = 6.5907 Z =
0.0000" coordinates.
4. Click the right mouse button. AutoCAD displays the cursor menu.
5. Select Copy from the cursor menu. AutoCAD copies the coordinate text to the Windows clipboard.
7. Press Ctrl+V
Ctrl+V. AutoCAD pastes the text into the drawing using the current text style.
AutoCAD always pastes stuff in the upper-left corner of the drawing screen. You can use the Move command to
shift the text into position.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
When you pick a point on the screen, the program labels the point with its x,y,z-coordinates. A quick reminder on
how to use it:
1. Type the AutoLISP code in at the ‘Command:’ prompt exactly as shown. All those spaces, parentheses, and
quote marks are important; upper and lower case characters are not important.
3. Notice that AutoCAD writes the x,y,z-coordinates at the point you picked. You may need to zoom window or
extents to see the text.
• It’s a pain to retype those two lines each time you want to label a point — we need to give the program a
name ...
• ... and we need to save it on disk so that we don’t need to retype the code with each new AutoCAD session...
• ... and if we use this AutoLISP program a lot, then we should have a way of having it load automatically.
• The x,y,z-coordinates are printed to eight decimal places, which, for most users, that’s way too many.
• You may want to control the layer that the text is placed on.
• You may want a specific text style.
• Certainly, you would like some control over the size and orientation of the text.
• Here’s an orthogonal idea: store the x,y,z-coordinates to a file on disk — just in case you ever want to reuse
the data.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
To give the program a name, I surround all of the code with the (defun) function, as follows:
(defun c:label ( / xyz)
(setq xyz (getpoint "Pick point: "))
(command "text" xyz 200 0 xyz)
)
(defun defines the name of the function. In AutoLISP, the terms function, program, and routine are used inter-
changeably.
c:label is the name of the function. I decided to call this program Label. I could give it any name that does not
conflict with the name of a built-in AutoLISP function or any other user-defined function. The c: prefix make
this AutoLISP routine appear like an AutoCAD command.
To run the Label program, all I need do is type “label” at the ‘Command:’ prompt, as follows:
Command: label
Pick point: (Pick a point.)
When the c: prefix is missing, then I run the program like an AutoLISP function with the parentheses, as follows:
Command: (label)
Pick point: (Pick a point.)
( / xyz ) declares the names of input and local variables; the slash separates the two. An input variable is for feeding
data to the AutoLISP routine; the names of input variables appear before the slash. A local variable is used only
within the program; the names of local variables appear after the slash. In my example program, xyz is the name of
the variable that is used strictly within the program. If variables are not declared local, they become global. The
value of a global variable is accessed by any AutoLISP function loaded into AutoCAD.
The benefit to declaring variables as local is that AutoCAD automatically frees up the memory used by the
variable when the AutoLISP program ends; the drawback is that the value is lost, making debugging harder. For
this reason, otherwise-local variables are kept global until the program is debugged.
) closing parenthesis balances the opening parenthesis at the beginning of the program. I indented the code in the
middle to make it stand out from the defun line and the closing parenthesis. This is standard among program-
mers; the indents make it easier to read code. You can use a pair of spaces or the tab key since AutoLISP doesn’t
care.
By saving the program to a file on disk, I avoid retyping the code with each new AutoCAD session. I do this, as
follows:
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
3. Save the file with the name label.lsp in AutoCAD’s folder named \support.
If AutoCAD cannot find the AutoLISP program, then I have to specify the path. Assuming I saved label.lsp in the
folder \acad13\win\support I would type:
Command: (load "\\acad13\\win\\support\\label")
AutoCAD provides a way to automatically load AutoLISP programs. When AutoCAD starts up, it looks for a file
called acad.lsp. AutoCAD automatically loads the names of AutoLISP programs listed in the file. To add label.lsp
is easy. Open the acad.lsp file with a text editor (if the file does not exist, then start a new file called acad.lsp and store
it in the \support folder). Add the name of the program:
(load "label.lsp")
Save the acad.lsp file. Start AutoCAD and it should automatically load label.
The x,y,z-coordinates are printed to eight decimal places — that’s too many. There are two solutions. One is to ask
the user the number of decimal places, as shown by the following code fragment:
Command: (setq uprec (getint "Label precision: "))
Label precision: 1
1
Or steal the value stored in system variable LUPrec — the precision specified by the user via the Units command
UPrec
— under the (not necessarily true) assumption that the user want consistent units. The code to do this is as
follows:
(setq uprec (getvar "LUPREC"))
That was the easy part. The tough part is applying the precision to the x,y,z-coordinates, which takes three steps:
(1) pick apart the coordinate triplet; (2) apply the precision factor; and (3) join the coordinates together again.
Here's how:
1. Open label.lsp in NotePad or any other text editor. Remove / xyz from the code. This makes the variable
“global,” so that I can check its value at AutoCAD’'s ‘Command:’ prompt. The code should look like this:
(defun c:label ( )
(setq xyz (getpoint "Pick point: "))
(command "text" xyz 200 0 xyz)
)
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
2. Run label.lsp, picking any point on the screen. If you don’t see the coordinates printed on the screen, use the
Zoom Extents command.
The exclamation mark forces AutoCAD to print the value of variable XYZ
XYZ, which holds the x,y,z- coordi-
nates. Your results will differ, depending on where you picked.
4. LISP has several functions for picking apart a list. Here I’ll use the car and cdr functions, and combinations
thereof. The car function extracts the first item (the x-coordinate) in the list. Try it now:
Command: (car xyz)
6.10049
6. In addition to car and cdrcdr, LISP allows me to combine the “a” and “d” in several ways to extract other items
in the list. To extract the y-coordinate, use cadr
cadr, as follows:
Command: (cadr xyz)
8.14595
8. I now have a way to extract the x-coordinate, the y-coordinate, and the z-coordinate from variable XYZ
XYZ. I’ll
store them in their own variables, as follows:
Command: (setq ptx (car xyz)
1> pty (cadr xyz)
I am using PtX to store the x-coordinate, PtY for the y-coordinate, and so on. In addition, I am using a
form of LISP shorthand that allows me apply the SetQ function to several variables. Recall the reason for
AutoCAD’s 1> prompt: it reminds me that a closing parenthesis is missing.
9. Now that the three coordinates are separated, I can finally reduce the number of decimal places. There are a
couple of ways to do this, but I’ll use the RtoS function because it does two things at once: (1) changes the
number of decimal places to any number between 0 and 8; and (2) converts the real number into a string.
Why? You'll see later. For now, here is the RtoS function at work:
Command: (rtos ptx 2 uprec)
"6.1"
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Mode Units
1 Scientific
2 Decimal
3 Engineering
4 Architectural
5 Fractional
UPrec Name of the variable holding the precision (the code for that is at the beginning of this
section). This varies, depending on the type of units. For example, a value of 2 for
decimal means “two decimal places”; a 2 for architectural means “quarter-inch.”
Assuming, then, that the precision in UPrec is 1, the RtoS function in the code fragment above reduces
UPrec
6.10049 to 6.1.
10.
0. I truncate and preserve the values of x, y, and z, as follows:
Command: (setq ptx (rtos ptx 2 uprec)
1> pty (rtos pty 2 uprec)
1> ptz (rtos ptz 2 uprec)
1> )
Notice that I can set a variable equal to itself: the first PtX holds the new value of the x-coordinate after
RtoS gets finished processing the second PtXPtX. Reusing a variable name like this helps conserve memory.
11. With the coordinates truncated, I now have to string (pardon the pun) them together with the StrCat
function, short for string concatenation. Try it now:
Command: (strcat ptx pty ptz)
"6.18.110.0"
12. Oops! Not quite the look I was hoping for. Since LISP can’t know when I want spaces, it doesn’t provide
any. I have to insert them. StrCat is one of the most useful LISP functions, since it lets me create a string
that contains text and variables, like this:
Command (setq xyz (strcat ptx ", " pty ", " ptz))
"6.1, 8.1, 10.0"
13. Back to the text editor. Add in the code I developed here, shown in boldface:
(defun c:label ( / xyz xyz1 uprec ptx pty ptz)
(setq uprec (getint "Label precision: "))
(setq xyz (getpoint "Pick point: "))
(setq ptx (car xyz)
pty (cadr xyz)
ptz (caddr xyz)
)
(setq ptx (rtos ptx 2 uprec)
pty (rtos pty 2 uprec)
ptz (rtos ptz 2 uprec)
)
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Notice that I made all the variables local. Notice, too, the change to variable Xyz in the last couple of lines: I
don’t want the text placed at the rounded-off coordinates, so I use Xyz1 as the variable holding the text
string.
14. Finally, I should add comments to my code to remind me what it does when I look at the code several
months from now. The semicolon ( ; ) indicates the start of a comment:
; Label.Lsp labels a picked point with its x,y,z-coordinates.
; by Ralph Grabowski, 25 February, 1996.
(defun c:label ( / xyz xyz1 uprec ptx pty ptz)
; Truncate values:
(setq ptx (rtos ptx 2 uprec)
pty (rtos pty 2 uprec)
ptz (rtos ptz 2 uprec)
)
; Place text:
(command "text" xyz 200 0 xyz1)
15. Save the file as label.lsp, and then load the AutoLISP routine into AutoCAD with:
Command: (load "label")
"C:LABEL"
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
AutoLISP has the open function for opening a file. This function lets you open a file for one of three purposes: (1)
read data from the file; (2) write data to the file; and (3) append data to the file. You have to choose one of these at
a time; AutoLISP cannot do all three at once.
In all three cases, AutoLISP takes care of creating the file if it does not already exist. Reading data is easy
enough to understand but what's the difference between “writing” and “appending” data?
• When I open a file to write
write, all existing data in that file is erased and the new data is added.
• When I open a file to append
append, the new data is added to the end of the existing data.
For our purpose, we want to keep adding data to the file, so choose append mode. The AutoLISP code looks like
this:
(setq FIL (open "xyzdata.txt" "a"))
Here you are setting something (setq) to a variable named FILFIL. What is it? In pretty much all programming
languages, we don’t deal with the filename directly but instead deal with a file descriptor. This is a name (some
sequence of letters and numbers) to which the operating system assigns the filename.
Now that you have the file descriptor stored in variable FIL
FIL, you work with FILFIL, not the filename, which I
have decided to call xyzdata.txt.
The final "a" tells AutoLISP we want to open xyzdata.txt for appending data. It is important that the "a" be
lowercase; this is the only occasion where AutoLISP is case-sensitive. The options for the open function are:
Option Meaning
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
To write the data to the file, use the write-line function. This function writes a line of data to the file. (A related
function, the write function, writes a single character to the file.) The code looks like this:
(write-line xyz1 fil)
You cannot, however, just write the raw data to the file because it would look like a lot of numbers with dots mixed
in:
8.15483.27520.0000
Most software is able to read data that has commas separating numbers, like this:
8.1548, 3.2752, 0.0000
That includes spreadsheets, database programs, and even some word processing software. I tell these programs
that when they read the data, they should consider the comma to be a separator, and not a comma. In that way, the
spreadsheet program places every number in its own cell. With each number in its own cell, I can manipulate the
data. For this reason, we need code that formats the data. Fortunately, we’ve already done that.
In the previous section, we used the StrCat function along with the cdr
cdr, cadr
cadr, and caddr functions to separate
the x, y, and z components of the coordinate triplet. So we can reuse the code, which looks like this:
(setq ptx (car xyz)
pty (cadr xyz)
ptz (caddr xyz)
)
(setq xyz1 (strcat ptx ", " pty ", " ptz))
Finally, for good housekeeping purposes, close the file. AutoCAD automatically closes the file for you if you
forget, but good programmers cleans up after themselves. Closing the file is as simple as:
(close fil)
Putting It Together
Add the code for opening, formatting, writing, and closing to the lable.lsp program:
(defun c:label ( / xyz xyz1 uprec ptx pty ptz)
(setq uprec (getint "Label precision: "))
(setq xyz (getpoint "Pick point: "))
(setq ptx (car xyz)
pty (cadr xyz)
ptz (caddr xyz)
)
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Using a text editor, such as Notepad, make those additions to your copy of lable.lsp. Load it into AutoCAD with
the Load function:
Command: (load "label")
As you pick points on the screen, the routine labels the picked points but also writes the 3D point data to file. After
a while, this is what the data file looks something like this:
8.1548, 3.2752, 0.0000
7.0856, 4.4883, 0.0000
6.4295, 5.6528, 0.0000
5.5303, 6.7688, 0.0000
5.4331, 8.3215, 0.0000
Let’s take a moment to go back and revisit our wish list. One wishlist item was to control the layer that text is
placed on. There are two ways to approach this wishlist item:
• The no-code method is to set the layer before starting the AutoLISP function.
• The AutoLISP code version is to ask the user for the name of the layer, then use the system variable
CLA YER to set it (much easier than using the Layer command), as follows:
CLAYER
(setq lname (getstring "Label layer: ")) (setvar "CLAYER" lname)
Add those two line before the line with the ‘Pick point’ prompt.
To specify the text style, there are the same two methods as with setting the layer name. The no-code method is to
simply set the text style before starting the routine. Otherwise, you can write AutoLISP code similar to the follow-
ing:
(setq tsname (getstring "Label text style: ")) (setvar "TEXTSTYLE" tsname)
Once again, add those two line before the line with the ‘Pick point’ prompt. By now, you might be noticing that
our program is starting to look big. That’s called “feature bloat” and explains why ten years ago AutoCAD used
to fit on a single 360KB floppy disk, but now takes up megabytes of disk space. More features, especially in the
area of user interface, makes software grow far beyond the size of its basic algorithm.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
You don’t need to type the .lsp extension. When AutoCAD cannot find the points.lsp, you’ll need to specify the
folder name by using either a forward slash or double backslashes — your choice:
Command: (load "\\autocad\\points")
After you’ve typed this a few times, you’ll find this gets tedious. To solve the problem, write a one-line AutoLISP
routine that reduces the keystrokes, like this:
Command: (defun c:x () (load "points"))
Now anytime you need to load the points.lsp routine, you just type x and press Enter
Enter, as follows:
Command: x
Under Windows, you can use the above shortcut method, or you can drag the .lsp file from the File Manager into
AutoCAD. Note that the code moves one way: from the text editor to AutoCAD; the code never moves from
AutoCAD back to the text editor.
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Notice how I assigned octal 042 to variable qumark. The backslash tells AutoLISP the numbers following are in
octal. Octal, by the way, is half of hexadecimal: 0 1 2 3 4 5 6 7 10 11 12 ... 16 17 20 ...
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○
Normally, I cannot use the quotation ( " ) character in a string. AutoLISP uses the quotation as its string delimiter
to mark the beginning and ending of the string. In the following line of code:
(prompt "The diameter is 2.54"")
AutoLISP sees the first quotation mark as the start of the string, the second quotation as the end of the string, and
the third quotation mark as an error. The solution is the \nnn metacharacter. This lets me insert any ASCII
character, including special characters, such as tab, escape, and quotation marks. The workaround here is to use
the ASCII code for the quotation mark, \042, like this:
(prompt "The diameter is 2.54\042")
Similarly, Vijay needs to use the \009 metacharacter to space the text in his dialog box. And, in fact, that worked:
“According to what you had told me, I used the same and it worked.”
○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○