AutoCAD - CADalog
Transcription
AutoCAD - CADalog
w o r l d w i d e. A u t o C A D b y r a l p h 2 g r a b o w s k i 0 0 4 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 . A l l r i g h t s r e s e r v e d t a i l o r i n g e b y z e , . g t n i n h o s r i f l p b u u p 2 0 0 3 C o p y r i g h t n t i l ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • d ○ i Copyright & Payment 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. To support the work of the author, make a payment of: By email in PkZIP/Acrobat PDF format: US$19.95. Allow for a multi-megabyte download. On CD in Acrobat PDF format: US$24.95 (incl. shipping). Allow 2-3 weeks to arrive. The CD is delivered by mail, with shipping cost included. Delivery by FedEx: add US$18 - CDN$25 - £10. Check or Money Order • US funds drawn on a bank with its address in the USA (US$19.95 - $24.95). • Canadian funds drawn on a bank with a Canadian address (CDN$27.95 - $34.95 incl. GST). • British funds drawn on a bank located in Great Britain (£12.99 - £15.99). Mail your payment to: "Tailoring AutoCAD 2004" 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, Canadian, and many other currencies. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ i i ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 table of contents t a i l o r i n g 1: introduction to customizing A u t o C A D ~1 The Many Ways of Customization ~ 3 Shortcut Tips ~ 4 Tip #1: Placing Arcs ~ 4 Tip #2: Placing Text ~ 4 Tip #3: Replacing Text ~ 4 Tip #4: Using PostScript Fonts ~ 4 Tip #5: Template Drawings ~ 4 Tip #6: Fast Custom Drawing Sheets ~ 5 Tip #7: Collapsing Multilines ~ 5 Tip #8: Changing Layers ~ 5 Tip #9: Quick Trim ~ 6 Tip #10: Get the Big Picture 2004 ~ 6 Tip #11: Install Express Tools 2004 ~ 7 Which Customization? ~ 9 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • ○ ○ iii 2: customizing the environment ~ 11 Starting AutoCAD ~ 13 Tutorial: Using Command-line Switches ~ 13 /b Switch ~ 15 /c Switch ~ 15 /nologo Switch ~ 15 /p Switch ~ 15 /r Switch ~ 16 /s Switch ~ 16 /t Switch ~ 16 /v Switch ~ 16 Changing Window and Layout Elements ~ 17 Tutorial: Changing Screen Colors ~ 17 UCS Icon ~ 19 Command Line Font & Transparency ~ 20 Keyboard Shortcuts ~ 21 Toolbars and Command Line ~ 21 Menus and Tablet ~ 21 Tutorial: Setting and Restoring Profiles ~ 21 Tutorial: Support File Paths ~ 22 Search Path Options ~ 25 Support File & Working Support File Search Paths ~ 25 Device Driver File Search Path ~ 25 Project Files Search Path ~ 25 Menu, Help, and Miscellaneous File Names ~ 26 Text Editor, Dictionary, and Font File Names ~ 26 Print File, Spooler, and Prolog Section Names ~ 26 Printer and Plot Support Files ~ 26 Automatic Save File Location ~ 27 Color Book Locations ~ 27 Data Sources Location ~ 27 Drawing Template Settings ~ 27 Tool Palettes File Location ~ 27 Log File Location ~ 27 Temporary Drawing File Location ~ 27 Temporary External Reference File Location ~ 27 Texture Maps Search Path ~ 27 i-drop Associated File Location ~ 27 ○ iv ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Setting Templates for New Drawings 2004 ~ 28 Tutorial: Specifying the Template File ~ 28 Tutorial: Creating Your Own Template File ~ 31 Tutorial: Importing Layers 2004 ~ 32 Drafting and Selection Preferences ~ 34 AutoSnap Settings ~ 34 Grips Settings ~ 34 3: command aliases ~ 35 Shortcut Keys ~ 37 Shortcuts New to AutoCAD 2004 ~ 37 AutoCAD’s Default Accelerator Keys ~ 38 Tutorial: Defining Shortcut Keys ~ 39 The .pgp File — Aliases ~ 40 Alias Format ~ 40 Alias Rules ~ 40 Aliases Defined by Autodesk ~ 40 Creating New Aliases ~ 43 Tutorial: Alias Creation by Dialog Box 2004 ~ 43 Tutorial: Alias Creation by Hand ~ 44 4: toolbar macros ~ 47 Customizing Toolbars ~ 49 Rearranging Toolbars ~ 49 Tutorial: Dragging Toolbars ~ 49 Tutorial: Toggling Toolbars ~ 52 Tutorial: Changing Toolbar Buttons ~ 53 Tutorial: Changing Button Size ~ 55 Tutorial: Drawing Icons ~ 56 Tutorial: Writing Toolbar Macros ~ 58 Simple Macros ~ 59 Advanced Macros ~ 60 Toolbar Macros Are No Panacea ~ 61 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • ○ ○ v 5: menu macros ~ 63 Loading (and Unloading) Menu Files ~ 65 Loading Menu Groups ~ 65 Loading Menu Bar Items ~ 66 Menu File Types ~ 66 Your First Menu ~ 67 Tutorial: A Single-Command Menu ~ 67 Section Labels ~ 71 Menu Metacharacters ~ 73 Shortcut Menu Aliases ~ 74 Your Second Menu ~ 75 Tutorial: Loading .mnu a Second Time ~ 75 Adding More Menu Macros ~ 76 Adding Options to Commands ~ 76 Using Coordinates in Macros ~ 77 Making Macros “Official” ~ 78 Cancelling a Previous Command: ^C ~ 78 Adding Keyboard Shortcuts: & ~ 78 Separating Macros Visually: -- ~ 79 Adding Submenus: -> ~ 79 Right-Justified Text: \t ~ 80 Grayed-out Item: ~ ~ 80 Adding a Checkmark: !. ~ 80 Waiting for User Input: \ ~ 81 Providing Input to the User: ^H ~ 81 Writing Really Long Macros: + ~ 82 Repeating Commands ~ 82 Toolbars, Accelerator Keys, Image Tiles, Tablet Overlays, and the Screen Menu ~ 82 Toolbar Customization ~ 82 Custom Shortcut Keys ~ 83 Image Tiles ~ 83 Tablet Menus ~ 83 Screen Menu ~ 83 ○ vi ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 6: linetypes ~ 85 Commands Affecting Linetypes ~ 85 System Variables that Affect Linetypes ~ 87 The Special Case of Polylines ~ 87 Customizing Linetypes ~ 87 Tutorial: Making Linetypes with -Linetype Command ~ 87 Tutorial: Testing the New Linetype ~ 89 Tutorial: Making Linetypes with MkLType 2004 ~ 90 Tutorial: Making Linetypes with a Text Editor ~ 91 Simple (1D) Linetype Format ~ 92 Line1: Header ~ 92 Line 2: Data ~ 92 Complex (2D) Linetype Format ~ 93 Text ~ 93 Text Style ~ 93 Text Scale Factor ~ 93 Text Rotation Angle ~ 93 Text Orientation ~ 93 Text Offset Distance ~ 94 Embedding a Shape ~ 94 3D Linetypes ~ 94 Tutorial: Attempting a Parallel Linetype ~ 95 Alternatives to the Parallel Linetype ~ 97 7: hatch patterns ~ 99 Where Do Hatch Patterns Come From? ~ 101 Associative and Non-associatve Patterns ~ 101 Hatch Patterns and Gradient Fills ~ 102 Creating Custom Hatch Patterns ~ 103 Tutorial: Creating Patterns with Hatch ~ 103 Tutorial: Creating Patterns with BHatch ~ 104 Tutorial: Creating Patterns with SuperHatch 2004 ~ 105 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • ○ ○ vii Understanding the acad.pat File ~ 107 Comment and Header Lines ~ 107 The Hatch Data ~ 107 Tips on Creating Pattern Codes ~ 109 Adding Custom Patterns to the Palette ~ 110 8: shapes & fonts ~ 113 About Shape Files ~ 115 Tutorial: Creating Shapes 2004 ~ 115 The Shape File Format ~ 117 Header Fields ~ 117 Definition Lines ~ 118 Vector Codes ~ 118 Instruction Codes ~ 119 0/000: End of Shape ~ 119 1/001: Draw Mode ~ 119 2/002: Move Mode ~ 119 3/003: Reduced Scale ~ 119 4/004: Enlarged Scale ~ 120 5/005: Save (Push) ~ 120 6/006: Recall (Pop) ~ 120 7/007: Subshape ~ 120 8/008: X,y Distance ~ 120 9/009: X,y Distances ~ 121 10/00A: Octant Arc ~ 121 11/ 00B: Fractional Arc ~ 122 12/00C: Bulge Arc ~ 122 13/00D: Polyarc ~ 123 14/00E: Flag Vertical Text Flag ~ 123 ○ ○ viii ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 9: script files ~ 125 What are Scripts? ~ 125 Script Files ~ 125 Drawbacks to Scripts ~ 127 Strictly Command-Line Oriented ~ 127 Script Commands and Modifiers ~ 129 Script ~ 129 RScript ~ 129 Resume ~ 129 Delay ~ 129 Special Characters ~ 130 (space) ~ 130 ; (semicolon) ~ 130 ' (apostrophe) ~ 130 * (asterisk) ~ 131 Backspace ~ 131 Esc ~ 131 10: diesel expressions ~ 133 The History of Diesel ~ 133 What Diesel Does ~ 135 Brief Listing of Diesel Functions ~ 135 Math Functions ~ 135 Logical Functions ~ 135 Conversion Functions ~ 135 String Functions ~ 136 System Functions ~ 136 Jumping Into Diesel ~ 137 Diesel Error Messages ~ 137 $? ~ 137 $(func)?? ~ 137 $(func,??) ~ 137 $(++) ~ 137 Debugging Diesel ~ 138 Diesel Programming Tips ~ 138 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • ○ ○ ix Diesel in Menus ~ 139 [ ~ 139 $(if, ~ 139 $(getvar,dimaso) ~ 139 ,!. ~ 139 ) ~ 140 /vAssociative Dimensions ~ 140 ] ~ 140 '_dimaso ~ 140 $M= ~ 140 $(-,1, ~ 140 $(getvar,dimaso) ~ 140 ) ~ 140 Reusing Toggle Code ~ 141 Diesel in AutoLISP ~ 141 Via the setvar Function ~ 141 Concatenate Two Diesel Strings ~ 141 Via the MenuCmd Function ~ 142 11: autolisp programming ~ 143 The History of AutoLISP ~ 143 The AutoLISP Programming Language ~ 145 Simple AutoLISP: Adding Two Numbers ~ 145 AutoLISP in Commands ~ 147 Remembering the Result: SetQ ~ 147 AutoLISP Functions ~ 149 Math Functions ~ 149 Geometric Functions ~ 150 Conditional Functions ~ 151 String and Conversion Functions ~ 151 External Command Functions ~ 152 Accessing System Variables ~ 154 GetXXX Functions ~ 154 Selection Set Functions ~ 155 Object Manipulation Functions ~ 155 Advanced AutoLISP Functions ~ 156 ○ x ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Writing a Simple AutoLISP Program ~ 156 Why Write a Program? ~ 156 The Id Command ~ 156 The Plan of Attack ~ 156 Obtaining the Coordinates ~ 157 Placing the Text ~ 158 Putting Them Together ~ 159 An Alternative to LISP Programming ~ 159 Writing a Simple AutoLISP Program, Cont’d ~ 160 Sprucing Up the Code ~ 160 Conquering Feature Bloat ~ 160 Wishlist Item #1: Naming the Program ~ 161 Wishlist Item #2: Saving the Program ~ 162 Wishlist Item #3: Automatically Loading the Program ~ 162 Wishlist #4: Using Car and Cdr ~ 162 Saving Data to a File ~ 166 The Three Steps ~ 166 Step 1: Open the File ~ 166 Step 2: Write Data to the File ~ 167 Step 3: Close the File ~ 167 Putting It Together ~ 168 Wishlist #5: Layers ~ 169 Wishlist #6: Text Style ~ 169 Tips in Using AutoLISP ~ 169 Tip #1: Use an ASCII Text Editor. ~ 169 Tip #2: Loading LSP Code into AutoCAD ~ 169 Tip #3: Toggling System Variables ~ 170 Tip #4: Be Neat and Tidy. ~ 170 Tip #5: Suppress That nil ~ 170 Tip #6: Read-Write-Append File ~ 171 Tip # 7: Quotation Marks as Quotation Marks ~ 171 Tip # 8: Keep Variables to Six Characters ~ 171 Tip #9: Tabs and Quotation Marks ~ 172 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ table of contents ○ ○ • ○ ○ xi 12: cad management ~ 173 CAD Standards ~ 175 Tutorial: Create the Standards Drawing ~ 175 Linetype Standards ~ 175 Layer Standards ~ 176 Dimension Style Standards ~ 177 Text Style Standards ~ 177 Tutorial: Save the Standards Drawing ~ 178 Tutorial: Apply the Standards ~ 178 Tutorial: Check the Standards ~ 179 Employing Tool Palettes and DesignCenter ~ 180 DesignCenter ~ 180 Tool Palettes ~ 182 Tab Customization ~ 183 Icon Customization ~ 184 Palette Customization ~ 185 Titlebar Customization ~ 186 XTP File Format ~ 187 XML Metacharacters ~ 187 Tool Palettes XTP ~ 188 XTP Section 1: Header ~ 188 XTP Section 2: Tool Data ~ 189 XTP Section 3: Palette Data ~ 191 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ xii ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 one introduction to customizing tailoring AutoCAD 2004 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? Customizing 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. Note: Features new to AutoCAD 2004 are marked with the 2004 logo. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 1 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ introduction to customization ○ ○ • ○ ○ 1 Table of Contents - Chapter 1 The Many Ways of Customization ~ 3 Shortcut Tips ~ 4 Tip #1: Placing Arcs ~ 4 Tip #2: Placing Text ~ 4 Tip #3: Replacing Text ~ 4 Tip #4: Using PostScript Fonts ~ 4 Tip #5: Template Drawings ~ 4 Tip #6: Fast Custom Drawing Sheets ~ 5 Tip #7: Collapsing Multilines ~ 5 Tip #8: Changing Layers ~ 5 Tip #9: Quick Trim ~ 6 Tip #10: Get the Big Picture 2004 ~ 6 Tip #11: Install Express Tools 2004 ~ 7 Which Customization? ~ 9 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ 2 ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 The Many Ways of Customization By my count, there are more than two dozen ways to customize AutoCAD (some of these may vary, depending on the version of AutoCAD you are working with): 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: DCC DFS FMP MNL MSG MLN UNT dialog color configuration (no longer available as of AutoCAD R14). MvSetup command’s DeFaultS. Font MaPping. MeNu utiLities. message (no longer available as of AutoCAD R14). MultiLiNe style. UNiT conversion factors. ... 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 DIESEL programming, that some enthusiastic users enjoy tinkering with. We look at these as well. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 1 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ introduction to customization ○ ○ • ○ ○ 3 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: Tip #1: 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. Tip #2: Placing Text When you need to place bits of text all around the drawing, use the Text 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, because you will loose all entered text. Instead, press ENTER twice to terminate the Text command. Tip #3: 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. Tip #4: Using PostScript Fonts Although Autodesk promotes the use of TrueType fonts in drawings, you can still use PostScript fonts through an under-documented work-around: Use the Convert command to convert PostScript .psf font files to AutoCAD’s .shx font format. Although the font is not longer in .psf format, you can take advantage of the variety of PostScript fonts available. Tip #5: Template Drawings To help you get started faster on new drawings, AutoCAD includes template drawings with system variables preset for the related standard. Some of the .dwt template drawings found in AutoCAD’s \template folder are: acad.dwt ANSI E -Named Plot Styles.dwt Architectural Title Block.dwt Generic 24in x 36in Title Block.dwt ISO A0 -Named Plot Styles.dwt Gb_a0 -Named Plot Styles.dwt JIS A0 -Named Plot Styles.dwt DIN A0 -Named Plot Styles.dwt ○ 4 ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Default template drawing ANSI (American) drawing standards US architectural D-size Generic D-size drawing with title block ISO (International metric) drawing standards Gb (Chinese) drawing standards JIS (Japan) drawing standards DIN (German) drawing standards ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 In AutoCAD 2004, the new QNew command does one of two actions: 2004 emplate dialog box. • By default, it displays the Use a T Template iles dialog box, QNew starts a new drawing using • If you specify the name of a .dwt file in the Options | F Files that template file. Tip #6: Fast Custom Drawing Sheets The MvSetup command helps you in creating a customized drawing board, title block, and multiple view setup. izard to start a new drawing, but the MvSetup command remains the more powerful You can use the Setup W Wizard tool. Tip #7: Collapsing Multilines To speed up the display of a drawing containing multilines, set the CMlScale system variable to 0. That collapses the multiline to a single line, which displays faster. Before plotting, set CMlStyle back to 1. Tip #8: 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 1 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ introduction to customization ○ ○ • ○ ○ 5 Tip #9: Quick Trim To precisely trim back a pair of intersecting lines, use the Fillet command with radius set to zero. Tip #10: Get the Big Picture 2004 The undocumented CleanScreenOn command maximizes AutoCAD’s drawing area by turning off the title bar, toolbars, and window edges. To further increase the drawing area, you can turn off the scroll bars and layout tabs (via the Options | Display dialog box) and make the command prompt area transparent (see Chapter 2). If you want to see the toolbars as well, use the FullScreen command (available only after installing Express Tools). To return to the normal screen, use the CleanScreeenOff command. As an alternative, you can press CTRL+0 (zero) to toggle between the two views. ○ 6 ○ ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tip #11: Install Express Tools 2004 AutoCAD 2004 includes a package called Express Tools that provides a large number of additional commands not supported by Autodesk. Express Tools, however, is not installed along with AutoCAD, so you need to run the setup.exe program and select “AutoCAD Express Tools Volumes 1-9.” The following commands are included with the Express Tools package: ○ ○ ○ ○ Command Description AliasEdit AlignSpace ArcText AttIn AttOut Edits the aliases stored in acad.pgp. Aligns model space objects in different viewports or with objects in paper space. Places text along an arc. Imports attribute data. Quickly extracts attributes in tab-delimited format. BExtend BlockReplace BlockToXref BreakLine BScale BTrim Burst Extends open objects to objects in blocks and xrefs. Replaces all inserts of one block with another. Convert blocks to xrefs. Creates the break-line symbol. Scales blocks from their insertion points. Trims to objects nested in blocks and external references. Explodes blocks, converts attributes to text. ChSpace ChUrls ClipIt CopyM CopyToLayer Moves objects between model and paper space. DdEdit-like editor for hyperlinks (URL addresses). Adds arcs, circles, and polylines to the XClip command. Copy command with repeat, divide, measure, and array options. Copies objects to other layers. DimEx DimIm Exports dimension styles to an ASCII file. Imports dimension style files created with DimEx. EtBug ExOffset ExPlan Sends bug reports to Autodesk. Adds options to the Offset command. Adds options to the Plan command. FS FullScreen Selects objects that touch the selected object. Toggles between full-screen and regular window. GetSel Selects objects based on layer and type. ImageApp ImageEdit Specifies the external image editor. Launches the image editor to edit selected images. LayCur LayDel LayFrz LayIso LayLck LayMch LayMrg LayOff LayOn LayoutMerge Changes the layer of selected objects to the current layer. Deletes layers from drawings — permanently. Freezes the layers of selected objects. Isolates layers of selected objects (all other layers are frozen). Locks the layers of selected objects. Changes the layer of selected objects to that of a selected object. Merges two layers; removes the first layer from the drawing. Turns off layers of selected objects. Turns on all layers. Places objects from layouts onto one layout. ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 1 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ introduction to customization ○ ○ • ○ ○ 7 ○ 8 ○ ○ ○ • LayThw LayUlk LayVpi LayWalk LMan Lsp LspSurf Thaws all layers. Unlocks layer of selected object. Isolates object’s layer in viewport. Isolates each layer in sequential order. Saves and restores layer settings. AutoLISP function searching utility. LISP file viewer. MkLtype MkShape MoCoRo MoveBak MStretch Creates linetypes from selected objects. Creates shapes from selected objects. Moves, copies, rotates, and scales objects. Moves .bak files to specified folders. Stretches with multiple selection windows. NCopy Copies objects nested inside blocks and xrefs. Plt2Dwg Propulate PsBScale PsTScale Imports HPGL files into the drawings. Updates, lists, and clears drawing properties. Sets and updates the scale of blocks relative to paper space. Sets text height relative to paper space. QlAttach QlAttachSet QlDetachSet QQuit Associate leaders to annotation objects. Associates leaders with annotations. Dissassociates leaders from annotations. Closes all drawings, and then exits AutoCAD. ReDir RepUrls Revert RText RtUcs Changes paths for xrefs, images, shapes, and fonts. Replaces hyperlinks. Closes the drawing, and re-opens the original. Inserts and edits remote text objects. Changes UCSs in real time. SaveAll ShowUrls Shp2blk SuperHatch SysvDlg Saves all drawings. Lists URLs in a dialog box. Converts from a shape definition to a block definition. Uses images, blocks, external references, or wipeouts as hatch patterns. Launches an editor for system variables. TCase TCircle TCount TextFit TextMask TextUnmask TFrames TJust TOrient TScale TSpaceInvaders Txt2Mtxt TxtExp Changes text between Sentence, lower, UPPER, Title, and tOGGLE cASE. Surrounds text and multiline text with circles, slots, and rectangles. Prefixes text with sequential numbers. Fits text between points. Places masks behind selected text. Removes masks from behind text. Toggles the frames surrounding images and wipeouts. Justifies text created with the MText and AttDef commands. Re-orients text, multiline text, and block attributes. Scales text, multiline text, attributes, and attribute definitions. Finds and selects text with overlapping objects. Converts single-line to multiline text. Explodes selected text into polylines. ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 VpScale VpSynch Lists the scale of selected viewports. Synchronizes viewports with a master viewport. XData XdList XList Attaches xdata to objects. Lists xdata attached to objects. Displays properties of objects nested in blocks and xref. Which Customization? That said, you need to make two decisions along the way. As you work with AutoCAD, make a mental or written record of your work. In particular, chronicle repetitive drafting tasks because these are prime candidates for customization. As one of Autodesk’s founders emphasized, “You should never have to draw the same line twice.” The second decision is to pick which of AutoCAD’s many customization possibilities to apply to the repetitive task. Some solutions are obvious, such as writing a .pat file for a custom hatch pattern. Others are less obvious: to draw that 3D staircase, do you use a script file (perhaps not), a DIESEL macro (no), an AutoLISP routine (yes), an ObjectARx application (nope, at least not in this context), or a menu macro (maybe)? For this reason, you need to become familiar with most of AutoCAD’s customization possibilities — even if you never use some of them. That way you craft the solution with the best tool. You also know when to hand over the job to a professional programmer, yet have some intelligent oversight of their work. A third solution is to find out about the thousands of third-party solutions available from the Autodesk Web site, other locations on the Internet, and CDs. The bulk of these are AutoLISP routines written by amateur programmers solving their own problems with AutoCAD. By knowing AutoLISP, you can modify the routine to your needs, which is a lot easier than writing it from scratch. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 1 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ introduction to customization ○ ○ • ○ ○ 9 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 10 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 two customizing the environment tailoring AutoCAD 2004 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. You can customize AutoCAD’s look in many ways: • The way in which you start AutoCAD. • The look and feel of AutoCAD’s user interface. • Taking your preferences with you. • Specifying the locations of support files. • Selecting and creating templates for starting new drawings. • Deciding how to select and work with objects. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 11 Table of Contents - Chapter 2 Starting AutoCAD ~ 13 Tutorial: Support File Paths ~ 22 Tutorial: Using Command-line Switches ~ 13 Search Path Options ~ 25 /b Switch ~ 15 Support File & Working Support File Search Paths ~ /c Switch ~ 15 25 /nologo Switch ~ 15 Device Driver File Search Path /p Switch ~ 15 Project Files Search Path /r Switch ~ 16 Menu, Help, and Miscellaneous File Names /s Switch ~ 16 Text Editor, Dictionary, and Font File Names /t Switch ~ 16 Print File, Spooler, and Prolog Section Names /v Switch ~ 16 Printer and Plot Support Files ~ 26 ~ 25 Automatic Save File Location Changing Window and Layout Elements ~ ~ 25 ~ 26 ~ 26 ~ 26 ~ 27 Color Book Locations ~ 27 17 Data Sources Location Tutorial: Changing Screen Colors ~ 17 ~ 27 Drawing Template Settings ~ 27 Tool Palettes File Location ~ 27 UCS Icon ~ 19 Command Line Font & Transparency ~ 20 Log File Location Keyboard Shortcuts ~ 21 Temporary Drawing File Location Toolbars and Command Line ~ 21 Temporary External Reference File Location Menus and Tablet ~ 21 Texture Maps Search Path ~ 27 ~ 27 ~ 27 ~ 27 i-drop Associated File Location ~ 27 Tutorial: Setting and Restoring Profiles ~ 21 Setting Templates for New Drawings 2004 ~ 28 Tutorial: Specifying the Template File ~ 28 Tutorial: Creating Your Own Template File ~ 31 Tutorial: Importing Layers 2004 ~ 32 Drafting and Selection Preferences ~ 34 AutoSnap Settings ~ 34 Grips Settings ~ 34 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2004 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 12 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Starting AutoCAD When you start AutoCAD, you probably do it in one of three ways: • Double-clicking the icon you found on your computer’s desktop. utoCAD | A utoCAD • Clicking the Start button on the taskbar, and then selecting Programs | A AutoCAD AutoCAD utoCAD. • Double-clicking a .dwg file name in the Explorer (or File Manager). 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, commandline 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 /b /c /nologo /p /r /s /t /v Runs a .scr script file. See Chapter 9. Specifies the .cfg hardware configuration to use. Suppresses display of the startup logo. Specifies the .arg user profile to use. Resets the .cfg configuration file to default values. Specifies the path to a folder for support files. Specifies the .dwt template file. Specifies the named view to display. TIP These command-line switches override settings in the Options dialog box, as well as the values set by environment variables. Tutorial: Using Command-line Switches To use command-line switches, you edit AutoCAD’s command line. Here’s how: 1 . On the desktop, right-click the AutoCAD icon. Notice the shortcut menu. 2 . From the shortcut menu, select Properties roperties. Notice the Properties dialog box. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 13 3 . In the Properties dialog box, select the Shortcut tab. In the Target text box, notice that the command-line text reads something like the following: "C:\AutoCAD 2004\acad.exe" The path (C:\AutoCAD 2004\) may be different for your system. 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:\autocad 2004\acad.exe /s c:\support;c:\dwgs" /s Notice that a space is required after the switch (/s /s), and that a semicolon ( ; ) is needed when the switch specifies more than one path. Here is another example: the following command-line starts AutoCAD with a script file called script.scr: "c:\autocad 2004\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. ○ ○ 14 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 /b Switch 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:\autocad 2004\acad.exe /b c:\autocad 2004\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 file name in the folder must be acad2004.cfg (for AutoCAD 2004). Example usage: "c:\autocad 2004\acad.exe /c c:\autocad 2004\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 acad2004.cfg file does not exist, AutoCAD creates one using default values. See /r switch. TIP AutoCAD 2004 allows parallel installation with a previous release of AutoCAD. This means you can point the new AutoCAD to old support files. /nologo Switch The /nologo switch starts AutoCAD without its logo. Example usage: "c:\autocad 2004\acad.exe /nologo" Some people find the logo (also called the “splash screen”) irritating because it covers up other windows for a few seconds. In AutoCAD 2004, the splash screen looks like this. Shown on the splash screen is the Stade de France stadium designed by Macary, Zublena et Regembal, Costantini - Architectes, Paris. www.stadefrance.com/presentation/vv.cfm /p Switch The /p switch specifies a named profile to use with AutoCAD. Profiles are created with the Options | Profiles dialog box, and are discussed later in this chapter. Example usage: "c:\autocad 2004\acad.exe" /p "my profile" ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 15 /r Switch The /r switch restores the acad2004.cfg configuration file to its default values. The existing configuration file is renamed acad2004.bak. This switch is useful when AutoCAD’s hardware configuration gets mucked up. Example usage: "c:\cad\autocad 2004\acad.exe /r" /s Switch 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:\autocad 2004\acad.exe /s c:\autocad 2004\support\;c:\alisp" iles Usually, AutoCAD starts without the /s switch; instead, it reads the folder(s) specified by the Options | F 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:\autocad 2004\acad.exe /t c:\autocad 2004\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:\autocad 2004\acad.exe /v titleblock" TIP The /s and /t switches are useful for customizing AutoCAD to the needs of different clients. ○ ○ 16 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Changing Window and Layout Elements AutoCAD’s default colors and fonts are, for the most part, pretty good. Nevertheless, the software allows you to change aspects of its user interface; other aspects are controlled by the Windows operating system. To have Windows change colors and fonts, right-click the desktop, and select Properties roperties. The Appearance dvanced | General | Display controls the overall size tab handles fonts and colors, while the Settings | A Advanced of fonts and user interface elements. Here is how to make changes in AutoCAD itself: Tutorial: Changing Screen 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 window, follow these steps: 1 . From the menu bar, select Tools | Options Options. Notice the Options dialog box. 2 . In the Options dialog box, select the Display tab. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 17 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. You can change the color of these user interface elements: • Model T ab Background sets the background color of the drawing area in model space. Tab • Model T ab P ointer sets the color of the crosshair cursor (pointer) in model space. Tab Pointer • Layout T abs Background (P aper) sets the background color of the drawing area in all layouts. Tabs (Paper) ○ ○ 18 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 • Layout T abs P ointer sets the color of the crosshair cursor (but not the pointer cursor) in model space. Tabs Pointer • AutoT racking V ector Color sets the color of tracking vectors, the temporary construction lines that utoTracking Vector appear 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. UCS Icon The color and size of the UCS (user-defined coordinate system) icon is changed with the UCSicon command’s roperties Properties roperties, or enter the Properties option. From the menu bar, select View | Display | UCS Icon | P command at the prompt, as follows: Command: ucsicon Enter an option [ON/OFF/All/Noorigin/ORigin/Properties] <ON>: p Some of the changes you can make to the UCS icon are illustrated by the figure: • Color, separately for model and layout (paper space) modes. • Line thickness. • Arrowhead type. • 2D or 3D style. 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 with the UCSicon command’s OFF option. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 19 Command Line Font & Transparency AutoCAD normally uses the Courier font for text in the command prompt area. To change the size and type of font, from the menu bar select Tools | Options | Display Display, and then click Fonts onts. Select a font, style, and size. Click Apply & Close Close. When the command-line area is dragged away from the edge of the AutoCAD window, it can be made partially transparent. 2004 Right-click the title bar, and then select Transparency ransparency. Notice the Transparency dialog box. evel varies the transparency of the window, ranging from Less (no transparency) to • Transparency L Level More (almost completely transparent). • Turn off window transparency makes the window opaque. The result may or may not be to your liking: transparency allows you to see the drawing through the commandline window, but makes the command line harder to read. ○ ○ 20 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Keyboard Shortcuts You can create keyboard shortcuts for executing commands. For example, you can assign commands to function keys. See Chapter 3 for details. Toolbars and Command Line You can change the position and number of toolbars. Additionally, you can change the icons on toolbar buttons, as well as the command(s) executed when a button is selected. See Chapter 4 for details. Menus and Tablet You can change the content of the drop-down menu, as well as the rarely sued screen and tablet menus. See Chapter 5 for details. Tutorial: Setting and Restoring Profiles After you make changes to the Options dialog box, you can save the settings to an .arg file. By carrying around this file with you (perhaps on a USB memory stick), you can instantly customize AutoCAD on other computers to your preferred settings. Here’s how to save and restore the settings: 1 . From the menu bar, select Tools | Options rofiles. Options. In the Options dialog box, select Profiles ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 21 2 . Click Add to List dd P rofile dialog box, name the profile and provide a description. List. In the A Add Profile Click Apply & Close Close. 3 . To use a profile, select its name from under the list of Available profiles rent profiles, and then click Set Cur Current rent. 4 . To export a profile, select Export Export, provide a file name, and then click Save Save. To import the profile, click Import Import, select a file name, and then click Open Open. Tutorial: Support File Paths After it is freshly installed on your computer, AutoCAD uses a number of folders in which to store support files, such as fonts, on-line help, and hatch patterns. The default settings for AutoCAD 2004 are shown on the next two pages. You may want to change the file paths for several reasons: • Your firms has clients with different standards for fonts, layer sets, and so on. • You are a third-party developer, and need to have paths pointing to different files. Here is how to change file paths: 1 . From the menu bar, select Tools | Options Options. In the Options dialog box, select Files iles. 2 . Select a path heading, such as Support F ile Search P ath File Path ath. To open it, click the + icon. 3. Select a path, such as \AutoCAD 2004\fonts. Notice the buttons that become available: Browse displays the Browse for F older dialog box, which lets you select a drive and folder, including Folder those on the network. Add adds a new path to the group. Remove removes — without warning — the selected path from the group. Move Up moves the selected path up in the list. AutoCAD searches for support files first in the topmost path. Move Down moves the selected path down the list. ○ ○ 22 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Set Current sets the selected item as the current (working). TIP Use the Profiles feature to save and switch between different AutoCAD settings. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 23 ○ ○ 24 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Search Path Options Here is an overview of the many paths that AutoCAD searches for setting options: Support File & Working Support File Search Paths Specifies the path to the folders in which AutoCAD searches for support files. • Support: location of support files specific to the user’s logon name, and general to AutoCAD. • Fonts: location of .shx font files. • Help: location of .chm help files. • Express: location of Express Viewer for viewing and plotting .dwf files. • Color: location of .acb color book files. 2004 2004 AutoCAD also searches the path(s) defined by the Path environment variable in the autoexec.bat file executed when Windows starts up. Device Driver File Search Path 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. Project Files Search Path Specifies project names, which contain search paths for externally-reference drawings; also stored in system variable ProjectName rojectName. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 25 Menu, Help, and Miscellaneous File Names Specifies the names and paths for menu and help files, as well as the default URL (uniform resource locator, a.k.a. Web address). ile • Menu F File ile: path and file name of the default .mnu file. ile • Help F File ile: path and file name of the default .chm file. ocation • Default Internet L Location ocation: the default URL (Web address) used by the Browse command. ile • Configuration F File ile: path to the default .cfg file (read-only). ver P ath • License Ser Server Path ath: “None,” if not using network licence of AutoCAD (read-only). “Read-only” means you cannot change the path in the Options dialog box. The path to the .cfg configuration file stores information about the hardware used with AutoCAD; its path can only be changed by the /c comver mand-line switch. Similarly, the list of client license servers is as stored in system variable AcadSer cadServer ver. Text Editor, Dictionary, and Font File Names • Text Editor Application Application: specifies the text editor to use with the MT MTeext command (stored in system variable MT MTeextEd xtEd). • Main Dictionary: selects the language to use for the Spell command (stored in system variable DctMain DctMain). The list of languages varies, depending on the version of AutoCAD installed. • Custom Dictionar Dictionaryy F File ile: path to the .cus dictionary file (stored in system variable DctCust DctCust). ile ile • Alternate F Font File ile: specifies the name of the replacement font. ont F ile • Font Mapping F File ile: specifies the path to the .fmp font mapping file (stored in system variable FontMap used when: (1) AutoCAD can’t locate the needed fonts; and (2) an alternate font was not specified in the acad.fmp font mapping file. TIP MTextEd understands the following values: • internal - AutoCAD displays the internal Multiline Text Editor, • . (period) - AutoCAD displays the internal Multiline Text Editor • Path and name of a text editor - AutoCAD uses that editor. • :lisped - AutoCAD uses a simpler text editor. Print File, Spooler, and Prolog Section Names • Plot file name for legacy plotting scripts: name of .plt temporary plot files used with R14 (or earlier) plotting scripts. • Print Spool Executable: specifies the name of the application to use for external plot spooling in this format: spooler.bat %s rolog Section Name: specifies the path to the .ps PostScript prolog file. • PostScript P Prolog Printer and Plot Support Files 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. ile L ocation: folder in which spooler files are stored. • Printer Spooler F File Location: ○ ○ 26 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 ath: folder in which .pc3 plotter configuration files are stored. • Printer Configuration Search P Path: ile Search P ath: folder in which .pmp plotter descriptions are stored. • Printer Description F File Path: able Search P ath • Plot Style T Table Path ath: folder in which the .stb and .ctb plot style files are stored. Automatic Save File Location ileP ath Specifies the path for storing automatic backup files (stored in system variable SaveF SaveFileP ilePath ath). Color Book Locations Specifies location of .acb color book files. 2004 Data Sources Location Specifies the path to .udl 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. Drawing Template Settings Drawing T emplate F ile L ocation: path to the .dwt template drawings. Template File Location: Default T emplate F ile Name for QNEW: QNEW name of the .dwt file opened by the QNew command; if Template File emplate dialog box. 2004 “None” QNew opens the Select a T Template Tool Palettes File Location Specifies the path to the .atc tool palette catalog files. 2004 Log File Location Specifies the path to the .log log file created by the LogfileOn command (stored in system variable L ogfileP ath ogfilePath ath). Temporary Drawing File Location Specifies the path to the folder in which AutoCAD stores its temporary files, which are deleted when AutoCAD refix is exited properly (stored in system variable TempP empPrefix refix). If AutoCAD crashes, these temporary files are often left behind, and can be safely erased. Temporary External Reference File Location oadP ath Specifies the path for temporally storing externally-referenced files (stored in system variable XL XLoadP oadPath ath). Texture Maps Search Path Specifies the path in which texture maps are stored for rendering. i-drop Associated File Location Specifies the associated data files that are transferred with i-drop content inserted in the drawing. 2004 ath for ObjectARX Applications option was removed with AutoCAD 2004. Note: The Search P Path ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 27 Setting Templates for New Drawings 2004 emplate dialog box: New to AutoCAD 2004 is the QNew command. By default, it displays the Use a T Template iles dialog box, QNew starts a new drawing using But, if you specify the name of a .dwt file in the Options | F Files that template file. Tutorial: Specifying the Template File Here’s how to specify a template file: 1. From the menu bar, select Tools | Options Options. 2. In the Options dialog box, click the Files tab. emplate Settings Settings. 3. In the Files tab, scroll down the list until you get to Drawing T Template 4. Click the + marker next to Default T Template File emplate F ile Name for QNEW. QNEW Notice that the setting is “None.” This causes the QNew command to display the Use a Template dialog box, as shown above. 5. Click on “None,” and then click the Browse button. Notice that the Select a file dialog box lists all the .dwt template files provided with AutoCAD. 6. Select a template file, and then click Open Open. Notice that the Options dialog box now lists the .dwt file you selected. 7. Click OK to close the Options dialog box. 8. Execute the QNew command. Notice that AutoCAD starts the new drawing using the template you selected. ○ ○ 28 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Templates included with AutoCAD 2004 Generic Template Files acad -Named Plot Styles acad acadISO -Named Plot Styles acadiso Architectural Title Block.dwg Architectural, English units -Color Dependent Plot Styles Architectural, English units -Named Plot Styles Generic 24in x 32in Title Block -Color Dependent Plot Styles Generic 24in x 32in Title Block -Named Plot Styles Metric Layout templates ANSI (American) Template Files ANSI A (portrait) -Color Dependent Plot Styles ANSI A (portrait) -Named Plot Styles ANSI A -Color Dependent Plot Styles ANSI A -Named Plot Styles ANSI B -Color Dependent Plot Styles ANSI B -Named Plot Styles ANSI C -Color Dependent Plot Styles ANSI C -Named Plot Styles ANSI D -Color Dependent Plot Styles ANSI D -Named Plot Styles ANSI E -Color Dependent Plot Styles ANSI E -Named Plot Styles ANSI Layout templates DIN (German) Template Files DIN A0 -Color Dependent Plot Styles DIN A0 -Named Plot Styles DIN A1 -Color Dependent Plot Styles DIN A1 -Named Plot Styles DIN A2 -Color Dependent Plot Styles DIN A2 -Named Plot Styles DIN A3 -Color Dependent Plot Styles DIN A3 -Named Plot Styles DIN A4 -Color Dependent Plot Styles DIN A4 -Named Plot Stylesg Gb (Chinese) Template Files Gb -Color Dependent Plot Styles Gb -Named Plot Styles Gb_a0 -Color Dependent Plot Styles Gb_a0 -Named Plot Styles Gb_a1 -Color Dependent Plot Styles Gb_a1 -Named Plot Styles Gb_a2 -Color Dependent Plot Styles Gb_a2 -Named Plot Styles Gb_a3 -Color Dependent Plot Styles Gb_a3 -Named Plot Styles Gb_a4 -Color Dependent Plot Styles Gb_a4 -Named Plot Styles ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 29 ISO ISO ISO ISO ISO ISO ISO ISO ISO ISO ISO (International) Template Files A0 -Color Dependent Plot Styles A0 -Named Plot Styles A1 -Color Dependent Plot Styles A1 -Named Plot Styles A2 -Color Dependent Plot Styles A2 -Named Plot Styles A3 -Color Dependent Plot Styles A3 -Named Plot Styles A4 -Color Dependent Plot Styles A4 -Named Plot Styles JIS (Japanese) Template Files JIS A0 -Color Dependent Plot Styles JIS A0 -Named Plot Styles JIS A1 -Color Dependent Plot Styles JIS A1 -Named Plot Styles JIS A2 -Color Dependent Plot Styles JIS A2 -Named Plot Styles JIS A3 -Color Dependent Plot Styles JIS A3 -Named Plot Styles JIS A4 (landscape) -Color Dependent Plot Styles JIS A4 (landscape) -Named Plot Styles JIS A4 (portrait) -Color Dependent Plot Styles JIS A4 (portrait) -Named Plot Styles TIPS The File | New and CTRL+N commands execute the New command. 2004 The New drawing icon, however, executes the QNew command. To remove the assigned .dwt file, select it in the Options | Files dialog box, and then click Remove. 2004 The Propulate command (available after Express Tools are installed) creates a template for the Drawing Properties dialog box (DwgProps command). ○ ○ 30 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Creating Your Own Template File While AutoCAD includes a large number of templates for starting new drawings, none might suit your needs. The problem is that AutoCAD’s templates only include the drawing border and title block, albeit drawn to international standards. They are a good starting point, but lack many settings you would expect in a template. For example, you may want to preset the snap and grid, include all the layers your firm or clients expect, and preload linetypes. 1 . Start AutoCAD with a new drawing. If you wish, start with one of the many template drawings provided by Autodesk. 2 . Prepare the drawing with all the settings and variables you think you will need. The list of possibilities includes: • Snap and grid settings. • Layer names (more later). • Linetypes. • Lineweight scale. • Text and dimension styles. • Units and CAD standards. • Multiline and point styles. • Customized DesignCenter and Tool Palettes. • Automatically loaded AutoLISP and ObjectARX routines. • Changes to system variables. • Customized menus and toolbars. Many of these options are found in the Format and Tools menus. 3 . Once you create a drawing that holds all the settings you need, use the File | Save As command. 4 . In the Files of type droplist, select “AutoCAD Drawing Template (*.dwt).” Notice that the dialog box switches to the \templates folder. 5 . In the File name text box, give your custom template a name, and the click Save Save. 6 . To use this template with the QNew command, follow the instructions in the previous tutorial. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 31 Tutorial: Importing Layers 2004 AutoCAD has never been particularly supportive of layer standards. The many template drawings, based on international standards, fail to include the related layer standards. Numerous standards bodies have created layer standards for disciplines, such as architecture and construction. In addition, most corporations have adopted a layer standard, either home-grown or based on an industry standard. LMan is available To share layer standards, the LMan command allows you to import layers from a text file. (LMan only after Express Tools have been installed with AutoCAD 2004.) Here is how to do import layers into your template drawing: 1 . Place the layer names in a text editor, such as Notepad. You might get the names from a text file, or a Web site. Ensure that each layer name is on a line by itself, and surrounded by quote marks, as shown below: 2 . Save the file, using the extension of .lay. 3 . In AutoCAD, start the Layer Manager: from the menu bar, select Express | Layers | Layer Manager ager, or simply enter lman at the ‘Command:’ prompt. Notice the Layer Manager dialog box. ○ ○ 32 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 4. Click Import Import. In the Import file name dialog box, select the .lay file, and then click Open Open. AutoCAD imports the layers. 5 . Check that the layers were indeed imported by click on the layers list: 6. Save the drawing as a .dwt template file. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 2 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ customizing the environment ○ ○ • ○ ○ 33 Drafting and Selection Preferences The Drafting and Selection tabs of the Options dialog box let you to customize the look of autosnaps and grips. AutoSnap Settings For AutoSnap, you have the option of changing: • Toggle (turn on and off) the display of the marker, magnet, tooltip, 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. color The grip changes to this color when New to AutoCAD 2004 is a third grip color: Hover grip color. tips which works only with custom objects. the cursor pauses over a grip. Also new is the Enable grips tips, 2004 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 34 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 three command aliases tailoring AutoCAD 2004 t he best-known way to run commands in Windows programs is from their menus and toolbars. But power users know that the fastest method for entering commands is the keyboard. Once you memorize them, shortcuts T-TAB, CTRL+V that copy to the Clipboard, switch to another application, and then ALT — such as CTRL+C, AL paste — 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 to any command. CTRL /SHIFT /AL T -key ALT combinations • 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 35 Table of Contents - Chapter 3 Shortcut Keys ~ 37 Shortcuts New to AutoCAD 2004 ~ 37 AutoCAD’s Default Accelerator Keys ~ 38 Tutorial: Defining Shortcut Keys ~ 39 The .pgp File — Aliases ~ 40 Alias Format ~ 40 Alias Rules ~ 40 Aliases Defined by Autodesk ~ 40 Creating New Aliases ~ 43 Tutorial: Alias Creation by Dialog Box 2004 ~ 43 Tutorial: Alias Creation by Hand ~ 44 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 36 ○ • ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Shortcut Keys AutoCAD predefines a number of shortcut keys. Shortcut keys let you carry out a command by simply pressing the assigned key on the keyboard. For some users, this is faster than selecting the command from the menu, toolbar, or typing it whole at the keyboard. AutoCAD permits you to assign shortcut keys to: eys are those keys marked with the F prefix, such as F1 and F2 F2. • Function kkeys eys operate by holding down the • Control kkeys +B. key, such as CTRL+F2 and CTRL+B CTRL key, and then pressing a function, number, or alphabet ted function kkeys eys operate by holding down the • Shif Shifted SHIFT • Control + Shift keys operate by holding down both the function, number, or alphabet key. key, and then pressing a function key. CTRL eys operate by holding down both the • Control + Alternate kkeys number or alphabet key. and and AL T ALT keys, and then pressing a CTRL and AL T ALT CTRL eys operate by holding down the • Control + Alternate + Shif Shiftt kkeys then pressing a number or alphabet key. keys, and then pressing a SHIFT and SHIFT keys, and Out-of-the-box, AutoCAD defines a number of shortcut keys, as listed on the next page. 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 example, indow command-and-option. you can assign the Zoom command, but not the Zoom W Window TIP You should not redefine F1 CTRL+Esc SHIFT+Tab CTRL+F6 CTRL+F4 these keys, because they are used by Windows: Displays help. Opens the Windows Start menu. Changes focus to the next window. Changes focus to the next window. Closes the current window. Other shortcut keys used by Windows include: ALT Accesses the menu bar. ALT+F4 Exits AutoCAD. ALT+Tab Switches to the next running program. Shortcuts New to AutoCAD 2004 F10 toggles polar mode. CTRL+0 (zero) toggles “clean screen” mode, where AutoCAD maximizes its drawing area by displaying only the menu, scroll bars, tabs, and command prompt area. This executes the CleanScreenOn and CleanScreenOff commands.) CTRL+3 alettes window. This executes the ToolP alette command. toggles the display of the Tool P Palettes oolPalette CTRL+Q previously toggled the log file recording; in AutoCAD 2004, it quits AutoCAD. This is not a useful change, since the alt+F4 shortcut also exits AutoCAD. CTRL+ SHIFT+S runs the SaveAs command. CTRL+SHIFT+C executes the CopyBase command, which copies objects to the Clipboard after you specify a base point. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 37 CTRL+ SHIFT+V executes the PasteBlock command, which pastes objects from the Clipboard after you specify an insertion point. Caution: This command pastes anything in the Clipboard, and may create in unexpected results. Make sure you V immediately after CTRL +SHIFT +C C. use CTRL +SHIFT +V AutoCAD’s Default Accelerator Keys The following table lists the keystroke shortcuts defined by default in AutoCAD 2004: ○ ○ 38 ○ • ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Defining Shortcut Keys t+F Here are the steps to define shortcut keys. In this tutorial, you assign the Find command to CTRL+shif +shift+F t+F: 1 . From the menu bar, select Tools | Customize | K eyboard Keyboard eyboard. Notice that the Customize dialog box displays the Keyboard tab. All of AutoCAD’s commands are categorized in three ways. • Sorted by menu order: from the Categor Categoryy list, select a menu name, such as File Menu Menu. oolbar • Sorted by toolbar order: from the Categor Categoryy list, select a toolbar name, such as Draw T Toolbar oolbar. Commands. • All commands in alphabetical order: from the Categor Categoryy list, select AutoCAD Commands 2 . From the Categories list, select the Edit Menu command category. 3 . From the Commands list, select Find ind, the command you wish to assign to a keystroke. 4 . Click in the Press new shortcut kkey ey bo boxx, and then press the key combination: 5 . Click Assign Assign. Notice that CTRL+ SHIFT+F CTRL+ SHIFT+F +F. rent K eys list. appears in Cur Current Keys 6 . Click Close to dismiss the dialog box. 7 . Test the keystroke shortcut by holding down the CTRL and SHIFT keys, and then pressing F. AutoCAD ind and R eplace dialog box. should execute the Find command by displaying the F Find Replace ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 39 The .pgp File — Aliases In addition to keystroke shortcuts, AutoCAD also allows you to define one- and two-letter command shortcuts, called aliases. An alias typically is an abbreviation of a command name, such as L for the Line command, and OS for OSnap (object snap). You can assign aliases to system variables, as well. Like keyboard shortcuts, aliases work only with command names; they cannot include options. 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. ctrl+N), Snap (already on the status line), Examples include the New command (already assigned to ctrl+N 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. Aliases Defined by Autodesk 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: ALI, AP, AR, -AR, ARO, ASE, ASQ, ATE, -ATE, ATT, -ATT, ATTE, AV, 3 3A, 3DO, 3F, 3P, *3DARRAY *3DORBIT *3DFACE *3DPOLY A A, AA, AAD, ADC, AEX, AL, ○ ○ 40 ○ • *ARC *AREA *DBCONNECT *ADCENTER *DBCONNECT *ALIGN ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ *DBCONNECT *APPLOAD *ARRAY *-ARRAY *DBCONNECT *DBCONNECT *DBCONNECT *ATTEDIT *-ATTEDIT *ATTDEF *-ATTDEF *-ATTEDIT *DSVIEWER ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ B B, -B, BH, BO, -BO, BR, *BLOCK *-BLOCK *BHATCH *BOUNDARY *-BOUNDARY *BREAK C C, -CH, CH, CHA, ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ *CIRCLE *CHANGE *PROPERTIES *CHAMFER ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 CO, *COPY COL, *COLOR C O L O U R ,*COLOR CP, *COPY E, ED, EL, EX, EXIT, EXP, EXT, D D, *DIMSTYLE DAL, *DIMALIGNED DAN, *DIMANGULAR DBA, *DIMBASELINE DBC, *DBCONNECT DCE, *DIMCENTER DCO, *DIMCONTINUE DDA, *DIMDISASSOCIATE DDATTDEF, *ATTDEF DDATTEXT, *ATTEXT DDCHPROP, *PROPERTIES DDCOLOR, *COLOR DDI, *DIMDIAMETER F, FI, ○ H, -H, HE, HI, ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 O, *OFFSET OP, *OPTIONS OPENURL, *OPEN ORBIT, *3DORBIT OS, *OSNAP -OS, *-OSNAP *BHATCH *HATCH *HATCHEDIT *HIDE P P, *PAN -P, *-PAN PA, *PASTESPEC PARTIALOPEN, *-PARTIALOPEN PE, *PEDIT PL, *PLINE PO, *POINT POL, *POLYGON PR, *OPTIONS PRCLOSE, *PROPERTIESCLOSE PRE, *PREVIEW PRINT, *PLOT PROPS, *PROPERTIES PS, *PSPACE PTW, *PUBLISHTOWEB PU, *PURGE -PU, *-PURGE I ○ I, *INSERT -I, *-INSERT IAD, *IMAGEADJUST IAT, *IMAGEATTACH ICL, *IMAGECLIP IM, *IMAGE -IM, *-IMAGE IMP, *IMPORT IN, *INTERSECT INF, *INTERFERE INSERTURL, *INSERT IO, *INSERTOBJ L L, *LINE LA, *LAYER -LA, *-LAYER LE, *QLEADER LEAD, *LEADER LEN, *LENGTHEN LI, *LIST LINEWEIGHT, *LWEIGHT LO, *-LAYOUT LS, *LIST LT, *LINETYPE -LT, *-LINETYPE LTS, *LTSCALE ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ *MOVE *MATCHPROP *MEASURE *MIRROR *MLINE *PROPERTIES *MSPACE *MTEXT *MVIEW O *GROUP *-GROUP *DDGRIPS H *DIVIDE *DIMLINEAR *DONUT *DIMORDINATE *DIMOVERRIDE *DRAWORDER *DIMRADIUS *DIMREASSOCIATE *DSETTINGS *DIMSTYLE *DTEXT *DVIEW ○ M, MA, ME, MI, ML, MO, MS, MT, MV, *FILLET *FILTER G, -G, GR, DIMALI,*DIMALIGNED D I M A N G ,*DIMANGULAR DIMBASE, *DIMBASELINE D I M C O N T, *DIMCONTINUE DIMDIA, *DIMDIAMETER DIMED, *DIMEDIT DIMLIN,*DIMLINEAR DIMORD, *DIMORDINATE DIMOVER, *DIMOVERRIDE D I M R A D ,*DIMRADIUS DIMSTY, *DIMSTYLE DIMTED, *DIMTEDIT ○ M G DIM ○ *ERASE *DDEDIT *ELLIPSE *EXTEND *QUIT *EXPORT *EXTRUDE F DDLMODES, *LAYER DDLTYPE, *LINETYPE DDMODIFY, *PROPERTIES D D O S N A P, *OSNAP DDUCS, *UCS DED, *DIMEDIT DI, *DIST DIV, DLI, DO, DOR, DOV, DR, DRA, DRE, DS, DST, DT, DV, LTYPE, *LINETYPE -LTYPE, *-LINETYPE LW, *LWEIGHT E ○ R R, RA, RE, REA, REC, REG, REN, -REN, REV, ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ *REDRAW *REDRAWALL *REGEN *REGENALL *RECTANGLE *REGION *RENAME *-RENAME *REVOLVE ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 41 RM, RO, RPR, RR, *DDRMODES *ROTATE *RPREF *RENDER T V T, -T, TA, TH, TI, TM, TO, TOL, TOR, TR, S S, *STRETCH SAVEURL, *SAVE SC, *SCALE SCR, *SCRIPT SE, *DSETTINGS SEC, *SECTION SET, *SETVAR SHA, *SHADE SL, *SLICE SN, *SNAP SO, *SOLID SP, *SPELL SPE, *SPLINEDIT SPL, *SPLINE ST, *STYLE SU, *SUBTRACT *MTEXT *-MTEXT *TABLET *THICKNESS *TILEMODE *TILEMODE *TOOLBAR *TOLERANCE *TORUS *TRIM V, -V, VP, -VP, *VIEW *-VIEW *DDVPOINT *VPOINT W W, -W, WE, *WBLOCK *-WBLOCK *WEDGE X U UC, UCP, UN, -UN, UNI, X, XA, XB, -XB, XC, XL, XR, -XR, *DDUCS *DDUCSP *UNITS *-UNITS *UNION *EXPLODE *XATTACH *XBIND *-XBIND *XCLIP *XLINE *XREF *-XREF Z Z, ○ ○ 42 ○ • ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ *ZOOM ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Creating New Aliases To create a new alias, or to edit existing aliases, there are two methods — by hand, or by dialog box. Here we look at both methods. Tutorial: Alias Creation by Dialog Box 2004 To edit aliases via dialog box, you must ensure that the Express Tools are installed with AutoCAD 2004. For this tutorial, you add the HOR alias for the DimHorizontal command. 1 . From the menu bar, select Express | T ools | Command Alias Editor Tools Editor. Notice the AutoCAD Alias Editor dialog box. 2. Click Add dd. Notice the New Command Alias dialog box. 3 . In the Alias text box, type an alias, such as HOR. DimHorizontal), or Under AutoCAD Command Command, you can either enter a command name (such as DimHorizontal select it from the list. Notes: The list does not include all of AutoCAD’s command, but it does include system variables. If you enter an alias the same as an existing one, AutoCAD warns that you will redefine it. OK. If you are adding a new command, AutoCAD asks if you want to add it to the list of com4. Click OK mands. Click Yes es. Notice that the new alias is listed in the dialog box. 5. Click OK to exit the dialog box. (There is no need to use the ReInit command to update AutoCAD with the new alias.) In addition to adding aliases, the AutoCAD Alias Editor allows you to edit (change) and remove aliases. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 43 Tutorial: Alias Creation by Hand If you prefer to handcraft aliases, follow these steps to directly edit the acad.pgp file. For this tutorial, you add the LIN alias for the DimLinear command. 1 . Open the acad.pgp file with the Notepad text editor, as follows: From AutoCAD 2004’s menu bar, select Tools | Customize | Edit Custom F iles | P rogram P arameters (acad.pgp) Files Program Parameters (acad.pgp). Notice that Notepad displays the file: 2 . Scroll down to the alias section, until you reach the dimensioning commands. 3 . Press Enter to make room for another line of text. 4 . Enter the following text: lin,* dimlinear 5 . From the menu bar, select Edit | Save Save. ○ ○ 44 ○ • ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 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. 7 . Select the PGP F ile option, and then click OK File OK. AutoCAD reloads the acad.pgp file. 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. TIP ○ ○ ○ ○ ○ ○ ○ ○ Command aliases can be used in toolbar and menu macros. ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 3 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ command aliases ○ ○ • ○ ○ 45 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 46 ○ • ○ ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 four toolbar macros tailoring AutoCAD 2004 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. (The first version of AutoCAD for Windows came out during Release 11 and was called the “AutoCAD Windows Extension,” or AWE for short. It was meant by Autodesk to be more of an experiment than a working release.) Toolbar buttons give you single-click access to almost any command or group of commands. Instead of hunting uct uct?) or trying to recall the through AutoCAD’s maze of menus (is the Hatch command under Draw or Constr Construct Vpoint), toolbars let you collect your most-used comexact syntax of a typed command (was that Viewpoint or Vpoint) mands 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 47 Table of Contents - Chapter 4 Customizing Toolbars ~ 49 Rearranging Toolbars ~ 49 Tutorial: Dragging Toolbars ~ 49 Tutorial: Toggling Toolbars ~ 52 Tutorial: Changing Toolbar Buttons ~ 53 Tutorial: Changing Button Size ~ 55 Tutorial: Drawing Icons ~ 56 Tutorial: Writing Toolbar Macros ~ 58 Simple Macros ~ 59 Advanced Macros ~ 60 Toolbar Macros Are No Panacea ~ 61 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ 48 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Customizing Toolbars There are two approaches to customizing toolbars. One is to simply rearrange the icons, perhaps creating a toolbar containing oft-used commands, or containing commands not found on the four toolbars AutoCAD disroperties plays by default — Draw Draw, Edit Edit, Standard Standard, and Object P Properties roperties. The second approach is to delve into all aspects of toolbar customizing: writing macros that activate when their button is clicked, creating new icons for the buttons, and modifying the help text. In this chapter, we look at both approaches. 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 dualmonitor 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. Tutorial: 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. You can relocate toolbars to other edges of the drawing area, or make the toolbars float. To move a toolbar: 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 49 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. 6. To dock the toolbar again, drag it by its title bar back against one edge of the drawing area. ○ 50 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 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. To dock, drag the prompt area back into place. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 51 Tutorial: Toggling Toolbars Toolbars can be turned off and on: 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 command, 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. ○ 52 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Changing Toolbar Buttons You can create a new toolbar with the buttons (commands) to your liking. Here is how to create such a toolbar: 1. Right-click any toolbar. From the context menu, select Customize Customize. (If no toolbar is visible, from the menu oolbars select Tools | Customize | T Toolbars oolbars.) 2. In the Toolbars tab, click New to create a new toolbar. Notice the New T oolbar dialog box. Toolbar 3. In the New T oolbar 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 Commands 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). ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 53 5. From the Command list, drag command names into the new toolbar. As you do, notice the buttons appearing. The I-beam cursor helps you position the button in the toolbar. 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. Note: There is no need to “save” the new toolbar; it is saved automatically by AutoCAD, and will appear the next time you start AutoCAD. ○ 54 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Changing Button Size 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. 2. Select Large Buttons Buttons. Notice that the buttons immediately grow larger. 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 55 Tutorial: Drawing Icons 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.) 2. Right-click the blank button, and select Edit Button Image Image. Notice the Button Editor Editor. The Button Editor provides a number of tools and functions: • 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. ○ 56 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 • Grid toggles the display of grid lines to assist your drawing; I recommend turning on the gird. • Clear erases the drawing from the button. • Open opens a .bmp file, which must be 16x16 pixels in size. • Undo undoes the last drawing step; it is a single undo, and there is no redo. • Save As saves the icon as a .bmp (Windows bitmap) file. • Save saves the icon to the toolbar. • Close closes the button editor. 3. Draw the icon. 4. When satisfied with your artistic endeavor, click Save Save, and then click Close Close. Notice that the toolbar’s formerly blank button is now adorned with your artwork. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 57 Tutorial: Writing Toolbar Macros In addition to creating custom toolbars and icons, you can also change the command(s) that lie behind each button. When you click a toolbar button, AutoCAD executes the macro (collection of commands) assigned to the button. In this tutorial, you assign a macro to the button with the custom icon created earlier. 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 P roperties tab. Properties roperties tab has several areas that correspond to AutoCAD’s user interface: The Button P 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 • Button Image is an enlarged view of the button’s icon. • Edit brings up the Icon Editor Editor, described earlier, so that you can edit the icon. • Apply applies the changes you made to the button. • Reset changes the button’s properties back to when you first began. ○ 58 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 3. And below the Edit button is a collection of icons, which you can borrow for use with the button. Select an icon, and then click Apply to see the icon on the button. Simple Macros A simple macro consists an AutoCAD command, prefixed by some unusual-looking characters: ^C^C_open The characters have the following meaning: ^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 — endtransmission — 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. TIP 1 AutoCAD recognizes these control characters in toolbar macros: ^A Toggles group mode, like pressing Ctrl+A1. ^B Toggles snap mode between on and off, like Ctrl+B. ^C Cancels current command, like pressing Esc. ^D Changes coordinate display mode, like Ctrl+D. ^E Switches to next isometric plane, like Ctrl+E. ^G Toggles grid display, like Ctrl+G. ^H Backspaces, like Ctrl+H. ^I Same as pressing Tab. ^M Same as pressing Enter. $M= Allows use of Diesel expressions; see chapter 10. ^O Toggles ortho mode, like Ctrl+O. ^P Toggles MenuEcho system variable. ^V Switches to next viewport, like Ctrl+V. ^U Toggle polar mode, like Ctrl+U1. ^W Toggle object snap tracking, like Ctrl+W1. ^X Deletes, like Del1. ^Z Suppresses automatic Enter at the end of a macro. Not documented by Autodesk. ^C^C Most macros start with two ^C because some AutoCAD commands are two levels deep. I PEdit, are three levels deep. recommend three of ’em — ^C^C^C — because some commands, like PEdit 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 59 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. Nothing is needed at the end of the macro to terminate it. AutoCAD automatically does the “pressing ENTER” for you. If you need to suppress the automatic Enter for some reason, hang a ^Z at the end of the macro, like this: ^C^Copen^z Advanced Macros You may string together more than one command in a toolbar macro. In addition, you can include Diesel expressions 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: Red Macro control characters. Cyan AutoCAD commands, AutoLISP functions, and system variables. Black Diesel expressions. Start of Diesel expression: If equal value of RefEditName system variable to empty then execute the (ai_refedit_alert) AutoLISP function. Otherwise, if and equal value of system variable TileMode 0 (model space) and value of system variable CvPort 1 (no viewports) then $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 ○ 60 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ execute RefSet command or RefSet Add command. Suppress Enter at end of Diesel expression. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Toolbar Macros Are No Panacea Toolbar macros are best suited for quick’n dirty programming. There are drawbacks, however, to using toolbar and toolbox macros. The length of the macro is limited to a maximum 255 characters. The variety of options for writing creative macros is limited compared with AutoCAD’s programming languages. Despite these drawbacks, the toolbar is the fastest and most convenient way to minimize keystrokes and mouse clicks in AutoCAD. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 4 toolbar macros ○ ○ ○ ○ • 61 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. ○ 62 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 five menu macros tailoring AutoCAD 2004 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 63 Table of Contents - Chapter 5 Loading (and Unloading) Menu Files ~ 65 Making Macros “Official” ~ 78 Loading Menu Groups ~ 65 Cancelling a Previous Command: ^C ~ 78 Loading Menu Bar Items ~ 66 Adding Keyboard Shortcuts: & ~ 78 Menu File Types ~ 66 Separating Macros Visually: -- ~ 79 Adding Submenus: -> ~ 79 Your First Menu ~ 67 Right-Justified Text: \t ~ 80 Tutorial: A Single-Command Menu ~ 67 Grayed-out Item: ~ ~ 80 Section Labels Adding a Checkmark: !. ~ 80 ~ 71 Menu Metacharacters ~ 73 Waiting for User Input: \ ~ 81 Shortcut Menu Aliases ~ 74 Providing Input to the User: ^H ~ 81 Writing Really Long Macros: + ~ 82 Your Second Menu ~ 75 Repeating Commands ~ 82 Tutorial: Loading .mnu a Second Time ~ 75 Toolbars, Accelerator Keys, Image Tiles, Adding More Menu Macros ~ 76 Tablet Overlays, and the Screen Menu ~ Adding Options to Commands ~ 76 82 Using Coordinates in Macros ~ 77 Toolbar Customization ~ 82 Custom Shortcut Keys ~ 83 Image Tiles ~ 83 Tablet Menus ~ 83 Screen Menu ~ 83 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 64 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Loading (and Unloading) Menu Files When you look at the menu bar, you see a number of labels, such as File ile, Edit Edit, and Tools ools. Each of these is called a partial menu (a.k.a. menu group). AutoCAD has a clever system for loading and unloading partial menus ile | will, with one exception: you cannot remove portions of partial menus defined by Windows, such as the F File Exit item. To load and unload partial menus, you use the MenuL MenuLoad oad command. The related MenuUnload command is identical, and the purpose for its existence is not clear to me. Both commands display the same dialog box, with these two tabs: 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) — File, Edit, View, and so on — with the menu bar displayed by AutoCAD: TIP AutoCAD remembers a maximum of 24 partial menus. Loading Menu Groups The Menu Groups tab loads menu and partial menu files: • Click the Browse button to locate .mnu, .mns, and .mnc files. • The Replace All option should only be used if you are sure you want to erase the existing menu system and replace it with a new one. 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. • EXPRESS is the menu for the Express Tools. To remove a menu group, select it and click the Unload button. You can always reload the menu group with the Browse button. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 65 Loading Menu Bar Items The Menu Bar tab lets you control which partial menus appear on the menu bar. Under Menus Menus, you see all titles associated with a specific menu group. For example, the ACCOV menu group contains the Image menu title. Bar you see the title that appear on the menu bar currently. You probably see titles such In the list under Menu Bar, as File ile, Edit Edit, and so on. To add and remove titles to and from the menu bar, click the Insert and Remove buttons. If the Insert button is grayed out, it means that all the titles of a menu group are already on the menu bar. TIP To load an full menu system, use the Menu command. It prompts you to select an .mnu, .mnc or .mns file. Menu File Types 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: File typeMeaning 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 MNS MNT Menu resource file contains the menu’s bitmaps. Source menu file generated by AutoCAD. 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. TIP To open the acad.mns file with the Notepad text editor in AutoCAD 2004: from the menu bar, select Tools | Customize | Edit Custom Files | Current Menu. Notice that Notepad opens with the .mns file, which you can view and edit. ○ ○ 66 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Your First Menu Writing a menu is simple — or it can be complex. To view a complex menu, open acad.mnu in a word processor. You typically create a custom menu to easily make available commands and functions that you (or someone else) has written. We’ll work our way through the steps of creating a single-command menu. Later, we add features. Tutorial: A Single-Command Menu Menus are written with a text editor, such as Notepad. 1 . Open Notepad, and enter the following lines of text: ***MENUGROUP=MyFirstMenu ***POP ID_mnuTailoring [Tailoring] [Rectangle]rectang; 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.” ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 67 ***POP 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 following 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. 2 . Save the macro in an .mnu file: As Notice the Save As dialog box. • From the menu bar, select File | Save As. • In the Save As dialog box, select the \AutoCAD\Support folder. • Specify the file name of mymacro.mnu. • Click Save. 3. Switch over to AutoCAD, and load your new menu file: • From the menu bar, select Tools | Customize | Menus (or, at the ‘Command:’ prompt, enter menuload menuload.) Notice the Menu Customization dialog box. If necessary, click the Menu Groups tab. ile dialog box. • Click Browse Browse. Notice the Select Menu F File • From the Files of type drop list, select Menu Template (*.mnu). (If necessary, change Look in to \AutoCAD\Support.) ○ ○ 68 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 • Select mymacro.mnu, and then click Open Open. • Back in the Menu Customization dialog box, click Load Load. Notice that AutoCAD warns you needlessly: (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.” ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 69 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 MyFirstMenu irstMenu. Notice that Tailoring appears under the irstMenu Menu list. • Click Insert Insert. Notice that Tailoring now appears under the Menu Bar list. Look at the menu bar: you should also see Tailoring there, probably located before File ile. • Click Close Close. 5 . Finally, it is time to test the new menu: • On the menu bar, click Tailoring ailoring. Notice that the Rectangle item appears below. ectangle. In the command prompt area, notice that AutoCAD starts the Rectang command. • Select Rectangle 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. ○ ○ 70 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Section Labels Section labels segregate the menu file into major sections and associated subsections. An AutoCAD menu file can have any, all, or none of these sections: Section Label Meaning ***MENUGROUP=name Menu’s group name. ***BUTTONSn ***BUTTONS1 ***BUTTONS2 ***BUTTONS3 ***BUTTONS4 Pointing device buttons: Buttons. Shift+button. Ctrl+button. Shift+Ctrl+button. ***AUXn ***AUX1 ***AUX2 ***AUX3 ***AUX4 Additional pointing device button: Button. Shift+button. Ctrl+button. Shift+Ctrl+button. ***POPn ***POP0 ***POP1-499 ***POP500-999 Pull-down menus: Default object-snap shortcut menu. Menu bar items. Shortcut menu items. ***TOOLBARS **name Toolbars section: Toolbar name. ***IMAGE ○ ○ ○ ○ Image menus (palettes). ***SCREEN Screen menu. ***TABLETn **TABLET1 **TABLET2 **TABLET3 **TABLET4 Tablet menu areas: Top area. Left area. Right area. Bottom area. ***HELPSTRINGS Help text displayed on the status bar. ***ACCELERATORS Accelerator keys. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 71 ○ ○ 72 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Menu Metacharacters AutoCAD menus use special characters to indicate actions equivalent to pressing keys on the keyboard. (These special characters are sometimes called metacharacters.) For example, after you enter a command at the keyboard, you press Enter Enter; in a menu, you use the semicolon ( ; ) to represent the Enter key. Similarly, the carat ( ^ ) is represents the Ctrl key; there is no metacharacter for the Alt key. Here is a list of menu metacharacters acceptable to AutoCAD: Character Meaning Menu Controls $ =* $I= $M=$( Loads menu sections. Returns to top-level menu. Displays an image menu. Starts a DIESEL macro. $Pn= $Pn=$Pn=* Pn.i=? Swaps menu items at position n. Removes menu item n. Restores menu item n (after swapping or removing). Returns the disabled and marked status of menu item n in a string: "~" Item is disabled. "!." Item has check mark. "" Item is neither disabled or check-marked. 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 [--] [->label] [<-label] [<-<-label] ~ !. & \t ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Separator line between items on pull-down and shortcut menus. Start of a submenu. End of the submenu or parent menu. 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 / . Right justifies text following. ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 73 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. Shortcut Menu Aliases The following aliases are reserved for use by AutoCAD: Alias Comment GRIPS CMDEFAULT CMEDIT OBJECT(S)_obj CMCOMMAND COMMAND_cmd Defines hot grip shortcut menu: right-click a hot (red) grip. Defines default shortcut menu (right-click blank area in the drawing). Defines Edit shortcut menu (right-click an object). Defines shortcut menu specific to the object (obj = DXF name). Defines Command shortcut menu (right-click while a command is active). 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. ○ ○ 74 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Your Second Menu Earlier in this chapter, I fleshed out for you the basics of a menu file. In review, the skeleton consisted of: ***MENUGROUP=name ***POP ID_mnuname [menuLabel] [label]command; 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 of text in the .mnu file. Tutorial: Loading .mnu a Second Time After making changes to the mymacro.mnu file in Notepad, you must save the file, and then load it into AutoCAD. Unlike the good old days, you can’t simply reload it. No, you have to first unload the old version of the menu file from AutoCAD, and then load the new one. Here’s how: 1 . In AutoCAD, use the MenuL oad command to display the Menu Customization dialog box. If MenuLoad necessary, select the Menu Groups tab. 2 . Under the Menu Groups list, select MyF irstMenu MyFirstMenu irstMenu, and then click Unload Unload. 3 . Now you can load your modified menu file: • Click Browse Browse, and select the .mnu file. • Click L oad oad, and answer Yes es. • Switch to the Menu Bar tab, and insert the Tailoring menu. 4 . Test the new menu and its macros. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 75 Adding More Menu Macros It’s not a good idea to keep creating new menu items; it makes more sense to list a number of menu macros under a single menu item. It’s as easy as adding to the end of an existing menu file, like so (the original menu code is shown in cyan): ***MENUGROUP=MyFirstMenu ***POP ID_mnuTailoring [Tailoring] [Rectangle]rectang; [Turn on log file recording]logfileon; Update your mymacro.mnu menu file in Notepad — remember to save it! — and load the modified menu into oad command. When you select the Tailoring item, the menu has two comAutoCAD with the MenuL MenuLoad mands. Adding Options to Commands In addition to command names, you can also have command options in menu macros. You enter them just as you would at the keyboard. For this reason, it is good to have a command reference handy, which lists commands and all their options, such as my own The Illustrated AutoCAD Quick Reference (Autodesk Press). Options are simply added to the command, such as this erase-last macro: [Erase Last]erase l; 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.) Return to Notepad, and add a second semi-colon to the macro, as follows: [Erase Last]erase l;; This time, AutoCAD selects the object and erases it. 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; ○ ○ 76 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Using Coordinates in Macros The Rectang command starts off with the following options: Specify first corner point or [Chamfer/Elevation/Fillet/Thickness/Width]: The options have the following meaning: Option Abbreviation Meaning Specify first corner point none Chamfer C Elevation E Fillet F Thickness T Width W X,y-coordinates of the rectangle’s first corner. Distance for corner chamfers. Height of the rectangle above the x,y-plane. Radius of corner fillets. Thickness of the rectangle in the z-direction. Linewidth of all four segments. To draw a rectangle of a specific size, you cannot enter coordinates as you would at the keyboard. Bummer, eh? ectangle]rectang 0 0 8.5 11; . It would not For example, you cannot draw an A-size rectangle using [R [Rectangle]rectang work because AutoCAD interprets the numbers as commands (silly AutoCAD!), complaining “0 Unknown command.” The workaround is to use the AutoLISP command function with the command coordinates in quotations marks, as follows: [Rectangle](command "rectang" "0,0" "8.5,11"); Make sure you use "straight quotes" and not “curly quotes,” also known as typesetter’s quotes. AutoCAD does not understand curly quotes. TIPS The rule-of-thumb in user interface design is: Five, plus-or-minus Two. The ideal menu has between three and seven items. Any fewer than three, and the items should perhaps appear on another menu. Any more than seven, and perhaps the items should be split among two menus. When a menu item calls a dialog box, the convention is to include the ellipsis ( ... ) as a suffix, like this: [Open...]^C^C_open; ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 77 Making Macros “Official” So far, we have been cheating. We haven’t observed conventions for writing menu macros. Specifically, every macro should start with ^C^C^C_ ^C^C^C_. Cancelling a Previous Command: ^C The ^C (code for ESC) cancels any other command that might still be running when you select this menu item. Three of the ^C in a row ensures commands with many levels of options, such as PEdit PEdit, are cancelled effectively. The underscore ( _ ) ensures your macro will work with other language versions of AutoCAD, such as in a German or Chinese version. Modify the mymacro.mnu file, as follows (changes shown in boldface boldface): ***MENUGROUP=MyFirstMenu ***POP ID_mnuTailoring [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;; Notice that the AutoLISP code is handled differently. The three ^C appear before the AutoLISP parentheses, while the underscore appears inside the parentheses in front of the command name. Adding Keyboard Shortcuts: & 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 T+F+S because the F and the S are underlined. ALT command, you press AL For AutoCAD menus, you use the ampersand ( & ) to specify the keyboard shortcut (and underlined) characters. 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;; The result looks like this: 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 ectangle front of the “R” in &R &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 T&ailoring the T underlined, you would only ever get to the first word. ○ ○ 78 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Separating Macros Visually: -- 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;; The result is two gray lines, a shown in the figure below: Adding Submenus: -> 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;; Notice how AutoCAD generates the submenu: 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; ...] metacharacter: It’s optional, but you can also indicate the end of both a submenu and its parent with the [<[<-label...] [<-Erase All...]^C^C_erase _a; ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 79 Right-Justified Text: \t 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 And here is the result in the menu itself: 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 oad command (replaceable text is in boldface boldface): code for toggling the gray text in the Partial L Load [$(if,$(eq,$(getvar,fullopen),0),,~)Partia&l Load]^C^C_partiaload This code reads as follows: oad with ~ ; • If system variable FullOpen is not 0 , prefix Partia artiall L Load • If FullOpen is equal to 0, don’t prefix it. oad command is available only when FullOpen is 0 (which indicates that What this means is that the PartiaL artiaLoad the 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 Again, I’ve boldfaced the parts of the code which you can replace with the system variables, values, and commands you need. ○ ○ 80 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 This sample code displays a checkmark next to Off Off, when system variable TabMode equals 0, as shown by the figure: TIP Search the acad.mnu file for examples of how to use metacharacters and macros in AutoCAD’s menus. Waiting for User Input: \ You can make the menu macro wait for the user to input a value, and then continue on with the macro. You use the backslash metacharacter ( \ ), as shown by this example: [S&tart, Center, Angle]^C^C_arc \_c \_a 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;; Providing Input to the User: ^H 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 81 Writing Really Long Macros: + Upon rare occasions, you might find yourself writing a r-e-a-l-l-y long macro. This used to be more common in the early days of AutoCAD, before AutoLISP came along. To allow a macro to span more than one line, place the plus ( + ) metacharacter at the end of the line. AutoCAD knows to read the next line as part of the same macro. The sample below illustrates this: [$(if,$(eq,$(getvar,refeditname),””),~,)&Remove from Working set]+ $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 _rem;))^Z 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 Commands Some commands repeat automatically, such as Donut Donut; others, such as Circle Circle, do not. When you want a Multiple command to repeat itself, you prefix it with 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. Toolbars, Accelerator Keys, Image Tiles, Tablet Overlays, and the Screen Menu With the .mnu file, you can also define custom toolbars, image tile dialog boxes, digitizing tablet overlays, and the side screen menu. But, in practice, you don’t. Here’s why: Toolbar Customization Toolbars are far easier to define using the Tools | Customize | T Toolbars oolbars command than tediously coding them in 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! ○ ○ 82 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Custom Shortcut Keys Accelerator keys (a.k.a keystroke shortcuts) are easier to customize with the Tools | Customize | K Keyeyboard command. See chapter 3 to learn how to create custom keystroke shortcuts visually, and let AutoCAD do the hard work for you! Image Tiles Image tiles create a type of dialog box so rarely used by AutoCAD that it appears in just one undocumented Surfaces In any case, you cannot complete construction of the image tile command: Draw | Surfaces | 3D Surfaces. 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 very few use it anymore. Indeed, it is turned off by default, so most people aren’t even aware of its existence. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 5 ○ ○ ○ ○ ○ ○ ○ ○ ○ menu macros ○ ○ • ○ ○ 83 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 84 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 six linetypes tailoring AutoCAD 2004 u ntil 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. Commands Affecting Linetypes As noted above, linetypes are defined in .lin files external to AutoCAD. It’s always been a source of irritation to me that I gotta load the file into the drawing before I can use any linetype. The Linetype command (and its commandline cousin, -Linetype -Linetype) loads the linetypes, and lists linetypes already loaded. You can apply a linetype to individual objects with the Linetype command, or you can have all objects located on a layer use the same linetype through the Layer command. Like text, linetypes are tricky to size. You have to size the gaps and dashes just the right way. Too small, and the line looks solid (but takes a suspiciously long time to redraw). Too large, and the line looks solid, too. It’s the LtScale command that lets you set the scale of the linetype. Typically, the scale used for text and dimensions and hatch patterns also applies to the linetype. Nice, eh? Until Release 13, the linetype scale factor applied equally to all linetypes in the drawing; as of Release 13 — and LT R3 — you can apply an individual linetype scale factor for each and every object in the drawing. (That’s probably one reason R13 files are 40% larger than the same R12 file!) Type creates complex linetypes from objects And quickly now, the other commands that affect linetypes: MkL MkLT rop (a.k.a. Painter rop selected in the drawing; MatchP MatchProp ainter) is another way to set the linetype. The Change Change, ChP ChProp rop, and Properties commands let you change the linetype and scale. Rename changes the name of linetypes. Purge removes unused linetype definitions. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 85 Table of Contents - Chapter 6 Commands Affecting Linetypes ~ 85 System Variables that Affect Linetypes ~ 87 The Special Case of Polylines ~ 87 Customizing Linetypes ~ 87 Tutorial: Making Linetypes with -Linetype Command ~ 87 Tutorial: Testing the New Linetype ~ 89 Tutorial: Making Linetypes with MkLType 2004 ~ 90 Tutorial: Making Linetypes with a Text Editor ~ 91 Simple (1D) Linetype Format ~ 92 Line1: Header ~ 92 Line 2: Data ~ 92 Complex (2D) Linetype Format ~ 93 Text ~ 93 Text Style ~ 93 Text Scale Factor ~ 93 Text Rotation Angle ~ 93 Text Orientation ~ 93 Text Offset Distance ~ 94 Embedding a Shape ~ 94 3D Linetypes ~ 94 Tutorial: Attempting a Parallel Linetype ~ 95 Alternatives to the Parallel Linetype ~ 97 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Conact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 86 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 System Variables that Affect Linetypes Because linetypes are affected by scale, paper space becomes a problem. A linetype scale that looks fine in model space is going to look wrong in paper space (layout mode). The solution comes with a system variable, PLineGen PLineGen. Its job is to scale all linetypes relative to paper space (default = 1.0). Say, for example, the paper space scale is 1/4" = 1' (that’s 1:48 scale). Then, by setting PLineGen to 48, AutoCAD automatically displays linetypes 48 times larger in paper space than in model space. There are a couple of other system variables that relate to linetypes. CeLtype holds the name of the linetype currently in effect. LtScale stores the current linetype scale factor (default = 1.0). The Special Case of Polylines 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 — ah, instant relief! Customizing Linetypes AutoCAD provides several methods for creating new linetypes: • At the command prompt with the -Linetype command. • Interactively with the MkLtype command. • Edit the acad.lin file with a text editor. Tutorial: Making Linetypes with -Linetype Command 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 87 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. 4. After clicking the Save button to dismiss the dialog box, AutoCAD checks: Wait, checking if linetype already defined .... 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> In this case, press ENTER, and then try giving it another name. 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 dot dot. 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, Type the codes after the A, as follows: A, .25,-.1,0,-.1 You could go on for a total of 78 characters... ○ ○ 88 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 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. TIP Where did 47 come from? A question: What about those unusual character limits of 31 and 47 and 78? They come from the limit of 80 characters being the maximum length of a line in the linetype definition. So, where did 80 come from? If you have ever used DOS, then you know the screen has a width of 80 characters. When AutoCAD displays the contents of the acad.lin file on the text screen, none of the text wraps around, making a nice display. Why is the DOS screen 80 characters wide? If you ever punch-coded computer cards back in the ’60s and ’70s, then you know that the punch cards were 80 characters wide. Why is that? When IBM invented the punch card, it made it the same size as the American dollar bill of the time (which were smaller than the current dollar bill). Why the dollar bill? I don't know for sure, but I am guessing that IBM simply adapted the bill-counting machine to make punchcard readers. Back to where 47 comes from ... Until AutoCAD 2000, the limit to names of named objects was 31 characters (such as layer names, view names, linetype names, and so on). The asterisk and comma take up two characters. That leaves 47: 80 - 31 - 2 = 47. Tutorial: Testing the New Linetype It is important to always test a new custsomization creation. As simple as they are, linetypes are no exception. Test the Dit-Dah pattern, as follows: 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 F ile dialog box. Select acad.lin, and then click Open File Open. AutoCAD confirms: Linetype DIT-DAH loaded. 3. Use the -Linetype Set command to set the linetype, as follows: ?/Create/Load/Set: s New entity linetype (or ?) <BYLAYER>: ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 89 4. Here you can type either the name of a loaded linetype (such as “dit-dah”) or enter “?” to see which linetypes 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. Tutorial: Making Linetypes with MkLType 2004 The MkLtype command (short for “make linetype”) creates simple and complex linetypes by selecting objects from the drawing. (This command is part of Express Tools, which must be installed separately from AutoCAD.) Here’s how: 1. Before defining the linetype, draw a symbol, such as a box or letters, such as CW (cold water). You can use the xt, and Shape Shape. PLine, Line Line, Point oint, Text following commands: PLine 2. From the menu bar, select Express | T ools | Mak Makee Linetype Linetype. Notice that you are prompted to select a .lin Tools linetype file. Select acad.lin, and then click Save — a misleading button name, since the linetype is not being save; Select would be more accurate. 3. Look at the command prompt area. The first couple of prompts are similar to that of the -Linetype command, familiar to you from the previous tutorial. Enter linetype name: Coldwater Enter linetype description: Cold Water Line If you enter a name that’s already in the .lin file, AutoCAD asks if you want to overwrite it. 4. AutoCAD prompts you to pick two points that define the length of the linetype: Specify starting point for line definition: (Pick a point.) Specify ending point for line definition: (Pick another point.) The length you pick is important, because it defines the distance between the symbols. 5. AutoCAD prompts you to select the objects that become part of the linetype pattern: Select objects: (Pick one or more objects.) Select objects: (Press ENTER.) 6. AutoCAD adds the definition to the .lin file, and then loads it into the drawing (nice touch!). Linetype "COLDWATER" created and loaded. In the .lin file, the linetype code looks like this: *COLDWATER,Cold Water Line A,0,-1.780678,["CW",Standard,y=-.083736,s=.2],-2.367254 ○ ○ 90 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 You can, following the explanation later in this chapter, edit this linetype code. 7. Finally, draw a line using the linetype: Tutorial: Making Linetypes with a Text Editor You can edit the acad.lin linetype file directly to create custom linetypes. Here’s how: 1. Start a text editor (not a word processor), such as NotePad. 2. Load the acad.lin file from the \support folder. 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 91 Simple (1D) Linetype Format To recap, the linetype definition consists of two lines of text: Line1: Header Line 1 is the header, such as *DIT-DAH, . __ . __ . __ , where: * (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 ? command. Line 2: Data Line 2 is the data, such as A, .25,-.1,0,-.1, where: 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. ○ ○ 92 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Complex (2D) Linetype Format “Complex” linetypes are 2D: they can wiggle back and forth (within limits) and include text characters. Truth be told, that’s all they are: text — or, more accurately, shapes. The complex linetype can consist entirely of 2D shapes, or can be mixture of 2D shapes and the 1D linetype codes — the dash, gap, and dot you learned of earlier in this chapter. The 2D shapes can be a combination of: (1) text characters from an .shx font file; and/or (2) shapes from an .shx shape file. Understanding and creating shapes is described in chapter 8. AutoCAD comes with seven complex linetypes. Two of them, the gas line and the hot water supply, simply combine a dash and gap with the letters GAS and HW from the Standard text style. Here is what the hotwater code looks like, as found in the ltypeshp.lin 2D linetype definition file: *HOT_WATER_SUPPLY,---- HW ---- HW ---- HW ---- HW ---- HW ---A,.5,-.2,["HW",STANDARD,S=.1,R=0.0,X=-0.1,Y=-.05],-.2 Much of this should look familiar to you, with the exception of the stuff between the square brackets shown in boldface. It’s the square brackets that allow the embedding of text in linetypes. Here’s what it means: boldface Text "HW" prints the letters HW between the dashes. Text Style ST AND ARD is the name of the text style to apply the text. This is optional; when missing, AutoCAD uses the STAND ANDARD current text style, stored in system variable TextStyle xtStyle. Text Scale Factor S=.1 is the text scale factor. It means one of two things: (1) when the text style’s height is 0 (as is so often the case), then S defines the height; in this case, 0.1 units; or (2) when the text style height parameter is not 0, then multiple the text style’s height by this number; in this case, the linetype would place the text at 10% of the height defined in the text style. Text Rotation Angle R=0.0 rotates the text relative to the direction of the line; in this case, 0.0 means there is no rotation. This parameter is optional and can be left out; in this case, AutoCAD assumes zero degrees. The default measurement is degrees, but you can use other forms of angular measurement: • r specifies radians, such as R=1.4r (there are 2 pi radians in a circle). • g specifies grads, such as R=150g (there are 400 grads in a circle). • d for degrees, such as R=45d (there are 360 degrees in a circle). 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 93 Text Offset Distance X=-0.1 shifts text in the x-direction from the linetype definition vertex, which helps center the text in the line. 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 between 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 regenerating 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 Here is what the text boldfaced in brackets means: BA T 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. ○ ○ 94 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Attempting a Parallel Linetype Chris Neperud asked if it were possible to create a custom linetype that is simply a continuous double line. I suggested he use the MLine command (or the DLine command in LT and earlier releases of AutoCAD). Chris replied with more details: “This works great, but I should have been more specific. What I was hoping for was a linetype that I could use with polylines. For example, I would like to digitize water features using a double it command. The MLine and MlEdit commands do not polyline, which I can then smooth with the PEdit F Fit allow me to smooth the vertices. Digitizing with one polyline, smoothing it, and then offsetting it is a possibility but I am hoping to find a better way to do it.” In theory, a parallel linetype should be possible; but in practice, it is not. Here is what I found — if you can find a work-around that fixes the problem, please let me know! 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: *135 is the start of the next shape code. 11 is the number of bytes in the code (fill in this number last). DU AL is the name of the shape code, which is referenced by the linetype .lin file. DUAL 2 is the Move (pen up) command 014 is a vector (line), where "1" is the length and "4" is the direction (straight up or north). 1 is the Draw (pen down) command. 020 is another vector, where "2" is the length and "0" is the direction (west) 02C is a two-unit vector in direction C (straight down, or south). 028 is a two-unit vector in direction 8 (east). 014 is a one-unit vector in direction 4 (north). 0 signals the end of the shape definition; the eleventh byte. 2. I saved the ltypeshp.shp file, then switched to AutoCAD. 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 95 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: *P ARALLEL_LINES starts and names the linetype. *PARALLEL_LINES ====== is a graphic representation using ASCII characters; optional. A is the alignment code. [ starts the complex linetype section. DU AL is the name of the shape code to use. DUAL ltypeshp.shx is the name of the .shx file containing the shape code. s=.1 scales the shape; here, scale = 10%. ] ends the complex linetype section. 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 ile dialog box. I select ltypeshp.lin, and then click the Open button. AutoCAD displays the Select Linetype F 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. The next step was to try AutoCAD 2004’s MkLtype command, which is supposed to create a linetype from selected objects. I drew two lines, one unit long and 0.1 units apart. I worked through the MkLtype command, but when I got to the final step, selecting the objects, AutoCAD complained: 2004 *Invalid* That's the continuous linetype! 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 ○ ○ 96 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Alternatives to the Parallel Linetype 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 segments into a single polyline. 3. Now use PEdit Spline or PEdit F it command to create a smoothly flowing polyline. Fit Perhaps a splinable MLine will make its appearance in a future AutoCAD. As a historical note, the MLine first appeared in Autodesk’s Generic CADD software, which could draw straight lines, automatically filleted lines, or Bezier curves. To see Generic CADD generate 14 parallel, multicolored lines as swooping Bezier curves is truly a beautiful sight to see. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 6 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ linetypes • 97 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 98 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 seven hatch patterns tailoring AutoCAD 2004 w hen Autodesk first introduced hatch patterns to AutoCAD (many years ago in version 1.4), they consisted of 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 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). ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ 99 Table of Contents - Chapter 7 Where Do Hatch Patterns Come From? ~ 101 Associative and Non-associative Patterns ~ 101 Hatch Patterns and Gradient Fills ~ 102 Creating Custom Hatch Patterns ~ 103 Tutorial: Creating Patterns with Hatch ~ 103 Tutorial: Creating Patterns with BHatch ~ 104 Tutorial: Creating Patterns with SuperHatch 2004 ~ 105 Understanding the acad.pat File ~ 107 Comment and Header Lines ~ 107 The Hatch Data ~ 107 Tips on Creating Pattern Codes ~ 109 Adding Custom Patterns to the Palette ~ 110 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 100 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Where Do Hatch Patterns Come From? Hatch patterns are defined in a file external to AutoCAD. The file has an extension of .pat. You can have many pattern files, each with an extension of .pat. I find it easier, however, to keep all patterns in a single file, acad.pat, which is where AutoCAD stores all of it hatch patterns (located in the \support folder). No hatch patterns are predefined in a new AutoCAD drawing. Unlike linetypes, however, the hatch pattern file is loaded automatically the first time you use the Hatch and BHatch commands. When AutoCAD applies a hatch pattern to an area, AutoCAD generates an infinite number of parallel patterns from the definition in the .pat file. The infinite pattern comes to a stop when it reaches a boundary (see figure). Once in place, you can use the Move command to move the hatch pattern elsewhere in the drawing. The pattern consists of only lines, line segments (dashes), dots, and gaps; AutoCAD cannot create hatch patterns made of circles and other nonlinear objects. Since Release 14, AutoCAD also supports solid filled areas in any color, and since 2004 AutoCAD support gradient fills and named colors defined by the Pantone and RAL standards. The Hatch and -BHatch commands create hatch patterns at the command line; the BHatch command displays a dialog box. Associative and Non-associative Patterns AutoCAD creates non-associative and associative hatch patterns. Non-associative means the shape of the pattern’s area is fixed; when you change the boundary, the pattern does not change. This is useful when you want the pattern to remain fixed. Associative hatching means the shape of the pattern changes as you change the boundary. 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 many system variables that report the most-recent setting of hatch pattern parameters: GfAng GfClr1 GfClr2 GfClrLum GfClrState GfName Specifies the angle of the gradient fill. Specifies first gradient color in RGB format. Specifies second gradient color in RGB format. Specifies luminance for one-color gradients. Specifies whether the gradient uses one or two colors. Specifies the gradient pattern: Linear, Cylindrical, Inverted cylindrical, Spherical, Inverted spherical, Hemispherical, Inverted hemispherical, Curved, and Inverted curved. Specifies the position of gradient fill: centered or shifted to the upper-left. Specifies the name of the current hatch pattern (default = ANSI31). GfShift HpName ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 101 HpScale HpAng Specifies the current scale factor (default = 1.0). Specifies the current angle of the hatch pattern in degrees (default = 0 degrees). Determines whether the hatch is applied a second time at 90 degrees. Specifies the spacing between hatch pattern lines (default = 1.0 units). Specifies the rotation angle of the hatch pattern in degrees (default = 0 degrees). Specifies the x,y-coordinates of the origin for the hatch pattern (default = 0,0). HpDouble HpSpace SnapAng SnapBase 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 Patterns and Gradient Fills ○ ○ 102 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Creating Custom Hatch Patterns AutoCAD has several ways to create custom hatch patterns: • You can create simple patterns at the ‘Command:’ prompt. • You can edit the acad.pat file with a text editor. • You can fill an area with any object using the SuperHatch command. To create the simple hatch pattern at the ‘Command:’ prompt, use the Hatch or BHatch commands. AutoCAD does not, unfortunately, save the fruits of your labor (unlike when you created a custom linetype at the ‘Command:’ prompt with the -Linetype command.) For this reason, think of the first method of creating custom hatch pattern on-the-fly. Tutorial: Creating Patterns with Hatch 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. 2 . Enter the Hatch command: Command: hatch 3 . Select the User-defined option: Enter a pattern name or [?/Solid/User defined] <ANSI31>: u 4 . Specify the three parameters for the custom hatch pattern: First, the angle. Specify angle for crosshatch lines <0>: 45 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. 5 . Second, the spacing between parallel lines Specify spacing between the lines <1.0000>: 2 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 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 103 7. Finally, you select the object or boundary to hatch, as follows: Select objects to define hatch boundary or <direct hatch>, Select objects: (Press Enter.) Retain polyline boundary? [Yes/No] <N>: y Specify start point: (Pick a point.) Specify next point or [Arc/Length/Undo]: (Pick a point.) Specify next point or [Arc/Close/Length/Undo]: a Specify next point or [Arc/Close/Length/Undo]: (Pick a point.) Specify next point or [Arc/Close/Length/Undo]: (Press Enter.) Specify start point for new boundary or <apply hatch>: (Press Enter to apply the pattern.) AutoCAD draws the pattern, but — as I mentioned earlier — your custom hatch pattern isn’t saved to the .pat file. Tutorial: Creating Patterns with BHatch To do the same thing with the BHatch command is a bit different; it’s more like filling out a form: 1 . From the menu bar, select Draw | Hatch (or, at the keyboard enter the BHatch command). ype area. 2 . When the Boundar Boundaryy Hatch dialog box appears, select User Defined from the Pattern T Type 3 . AutoCAD allows you to enter values for Angle Angle, Spacing Spacing, and Double Double. 4 . Click the PickP oints button and select the area you want hatched. AutoCAD automatically creates a ickPoints boundary, unlike the Hatch command. 5 . Click Apply Apply, and AutoCAD applies the hatch pattern. ○ ○ 104 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Creating Patterns with SuperHatch 2004 The SuperHatch command lets you fill an area with these kinds of objects: • Blocks defined in the drawing, or stored on disk as .dwg files (i.e., any AutoCAD drawing). • Any drawing, placed as an xref (externally-referenced drawing) in the drawing or found on disk. • Raster images, such as .bmp, .gif, .jpg, and .tif files. • Wipeouts, which are blank areas created with the Wipeout command. The SuperHatch command is not available until you install Express Tools for AutoCAD 2004. Follow these steps to create a hatch pattern from blocks, xrefs, images, and wipeouts: 1 . From the menu bar, select Express | Draw | Super Hatch Hatch. Notice the SuperHatch dialog box. 2 . Select an option: • Image displays the Select Image F File ile dialog box, and then inserts the image in the drawing using the Image command’s prompts. After the image is placed, AutoCAD asks: Is the placement of this IMAGE acceptable? [Yes/No] <Yes>: Answer Y, and AutoCAD prompts you to pick a point inside the hatch boundary. An example result using an image is shown below: ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 105 • Block displays the SuperHatch - Insert dialog box, which looks identical to the Insert dialog box. You select a block in the drawing, or a .dwg file from disk. AutoCAD inserts the block in the drawing using the Insert command’s prompts. After the block is placed, AutoCAD asks: Is the placement of this BLOCK acceptable? [Yes/No] <Yes>: Answer Y, and AutoCAD prompts you to select all or a portion of the block: Specify block [Extents] First corner <magenta rectang>: The magenta (pink) rectangle shows the extents of the block. Press ENTER to accept that, or pick two points to create a new extents (picking different points allows some creativity). Finally, AutoCAD prompts you to pick a point inside the hatch boundary. An example result using a block is shown below (block at left, pattern at right): ttach displays the Select R eference F ile dialog box. Select any .dwg file, and AutoCAD • Xref A Attach Reference File eference dialog box. AutoCAD inserts the xref in the drawing using the Xef displays the External R Reference command’s prompts. After the xref is placed, AutoCAD asks: Is the placement of this XREF acceptable? [Yes/No] <Yes>: Answer Y, and AutoCAD prompts you to pick a point inside the hatch boundary. The result is similar to the block example illustrated above. • Wipeout requires that the Express | T Teext | T Teext Mask command be used beforehand. Other than that, I couldn’t get it to work. • Select Existing prompts to you select a block, image, xref, or wipeout in the drawing. Ordinary objects, such as lines, arcs, and polylines, cannot be selected. ve Er ror T olerance is required because AutoCAD converts curved objects (arcs, circles, and so • Cur Curve Error Tolerance on) into a series of short lines. Note: The “hatch pattern” created by SuperHatch is not a pattern, but an unnamed group. Thus, the pattern is not associative. Unlike the MkLtype command, SuperHatch does not add a pattern definition to .pat files. ○ ○ 106 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Understanding the acad.pat File Let’s now dig into the contents of the acad.pat file to get a better understanding of how a pattern is constructed. 1 . Start a text editor (not a word processor), such as Notepad. 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 Comment and Header Lines The semicolon ( ; ) indicates a comment line, such as ;; Ver. 12.0 - AutoCAD Hatch Pattern File. That lets you include notes to yourself that are ignored by AutoCAD. The definition of a hatch pattern consists of two or more lines of text. The first line is called the header, such as *ANGLE, Angle steel. The asterisk ( * ) is important because it signals to AutoCAD the start of a new hatch pattern definition. Next comes the name for the hatch pattern, such as ANGLE. The name must be unique in the file. If it isn’t, AutoCAD uses the first pattern it finds by that name. The comma following the name merely separates the name from the description. The comma is optional; it doesn’t have to be there: a space works just as well. The text following the pattern name is the description displayed by the Hatch ? command, such as “Angle Steel.” This description is also optional but highly recommended. You are limited to a maximum of 80 characters for the name, comma, and the description. If you need more room for the description, use comment lines, such as: ; The hatch patterns that start with AR-xxxxx ; come from AEC/Architectural. *AR-B816, 8x16 Block elevation stretcher bond The Hatch Data With the comment lines and the header line out of the way, let’s get down to the nitty-gritty hatch pattern data and how it is coded. Lines 2 and following are the data, such as: 0, 0,0, 0,.275, .2,-.075 90, 0,0, 0,.275, .2,-.075 Every line of data uses the same format: angle, x-origin, y-origin, x-offset, y-offset [, dash1, ...] 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 107 Comma (,) separates the numbers. X-origin means that the first line of the hatch pattern passes through this x-coordinate. 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. 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. ○ ○ 108 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tips on Creating Pattern Codes Some miscellaneous comments on hatch pattern coding: 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 necessary, as long as it reaches a boundary. AutoCAD will not draw the hatch pattern unless it does find a boundary. origin offset At the very least, each line of pattern code must include the angle angle, x- and yy-origin origin, and the x- and yy-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. To change the angle of a hatch pattern upon placing it in the drawing, you’ve got a couple of options: • Specify the angle during the Hatch and BHatch commands. • Set the angle in system variable SnapAng SnapAng. The effect of SnapAng on the hatch pattern angle is additive: if the hatch pattern defines the lines drawn at 45 degrees and SnapAng is 20 degrees, then AutoCAD draws the hatch lines at 65 degrees. For example: Command: snapang New value for SNAPANG <0>: 20 offset and yoffset is always in the The xx-offset y-offset x-offset offset parameters are unaffected by the angle parameter, because xdirection of the line and y-offset is always perpendicular (90 degrees) to the line. 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,ySnapBase. The effect of SnapBase origin of a hatch pattern upon placing it in the drawing, use system variable 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 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 109 To draw dash and gap segments at an angle, use the sine of the angle in degrees, like this: Angle Dash length (sine) 0 30 45 60 90 0 0.433 0.707 0.866 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 ;angle x,-yorigin 37.5, 0,0, 7.5, 0,0, -32.5, -1.23,0, -42.5, -1.23,0, dot pattern x,y-offset 1.123,1.567, 2.123,2.567, 2.6234,1.678, 1.6234,2.678, dash 0, 0, 0, 0, codes (dot, gap, dot, -1.52, 0, -1.7, -.82, 0, -1.37, -.5, 0, -1.8, -.25, 0, -1.18, gap, 0, 0, 0, 0, dot, gap) -1.625 -.525 -2.35 -1.35 Adding Custom Patterns to the Palette Finally, let’s see how to add your custom-made hatch pattern to the BHatch dialog box. Craig Hunt made the following discovery: “In AutoCAD 2000 and newer you no longer need the slide library utility (slidelib.exe) to show hatch pattern previews. AutoCAD automatically creates the preview from the hatch patterns in the acad.pat file. “I combined several separate .pat files into the acad.pat file. The new hatch patterns are previewed, along with the others. You do, however, have to restart AutoCAD after adding patterns to acad.pat before they show up.” To test Mr Hunt’s finding, I added the following pattern definition to the end of the acad.pat file: *CUSTOM, Tailoring AutoCAD 0, 0,0, 0,.5, .5,-.005 45, 0,0, 0,.25, .5,-.005 I saved the file, and then started AutoCAD. No sign of the pattern. I did eventually get the new pattern to show up in the Boundary Hatch dialog box’s preview panes. The problem is that AutoCAD 2004 is designed for use with Windows 2000 and XP, both of which are multi-user operating systems. This means that AutoCAD 2004 stores user-specific files, such as acad.pat, in a variety of locations in order to keep files customized by different users separate from each other. Using the Windows Search facility, I found acad.pat stored in seven locations, some of which are hidden folders: \AutoCAD 2004\Support \AutoCAD 2004\Backup \AutoCAD 2004\UserDataCache\Support (a hidden folder) \Documents and Settings\username\Application Data\Autodesk\AutoCAD 2004\R16.0\en\Support (a hidden folder) \Documents and Settings\username\Favorites\Autodesk \Documents and Settings\username\Recent I added the above code to each of the acad.pat files, one at a time, re-starting AutoCAD each time. I finally discovered that the correct acad.pat file is the one stored in \documents and settings\username\application data\autodesk\autocad 2004\r16.0\en\support (a hidden folder). ○ ○ 110 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 To see the preview image, start the BHatch command, click the ... button (next to Pattern attern), and then select the Other P redefined tab. Scroll to the end to see the preview of the added pattern definition (“CUSTOM”). Predefined ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 7 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ hatch patterns ○ ○ • ○ ○ ○ 111 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 112 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 eight shapes & fonts t a i l o r i n g A u t o C A D a utoCAD uses .shp and .shx files for several purposes: 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), when 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 are usually to be hand-coded using an arcane method described in this chapter, although the MkShape command can be used to create shapes from selected objects. 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 QT QTeext command that turned lines of text into rectangles); 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 initially 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. MTeext commands. Fonts are loaded with the Style command, and placed with the Text and MT Complex 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 113 Table of Contents - Chapter 8 About Shape Files . . .115 Tutorial: Creating Shapes 2004 . . .115 The Shape File Format . . .117 Header Fields . . .117 Definition Lines . . .118 Vector Codes . . .118 Instruction Codes . . .119 0/000: End of Shape . . .119 1/001: Draw Mode . . .119 2/002: Move Mode . . .119 3/003: Reduced Scale . . .119 4/004: Enlarged Scale . . .120 5/005: Save (Push) . . .120 6/006: Recall (Pop) . . .120 7/007: Subshape . . .120 8/008: X,y Distance . . .120 9/009: X,y Distances . . .121 10/00A: Octant Arc . . .121 11/ 00B: Fractional Arc 12/00C: Bulge Arc 13/00D: Polyarc . . .122 . . .122 . . .123 14/00E: Flag Vertical Text Flag ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ . . .123 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 114 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 About Shape Files There are two kinds of shape files: .shp and .shx. In summary, the differences are: • .shp shp are shape source files. When you write or edit a shape or font, you work with the .shp file. A .shp file looks like this: *130,6,TRACK1 014,002,01C,001,01C,0 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. Tutorial: Creating Shapes 2004 The traditional method of creating shapes was tedious: writing the code in a text editor, and then repeated debugging by loading it into AutoCAD. Via the Express Tools collection, AutoCAD 2004 provides the MkShape command, which creates shapes from objects selected in the drawing. Here’s how to use it: 1 . In AutoCAD, draw something you want turned into a shape. 2 . From the menu bar, select Express | T ools | Mak Tools Makee Shape Shape. Notice that AutoCAD displays the MKSHAPE - Select Shape F ile dialog box. File 3 . Enter a file name, and then click Save — a bit misleading, since the saving doesn’t occur until later. Note: You can add shapes to an existing .shp file, or start a new file. 4. AutoCAD prompts you to give the shape a name: Enter the name of the shape: spotlight ... and a resolution: Enter resolution <128>: (Press ENTER.) TIP A higher resolution draws a more accurate shape. Resolution is rounded to the nearest value 8; the maximum value is 32,767. The default of 128 is good enough for most cases. 5. AutoCAD asks you to pick the insertion point: Specify insertion base point: (Pick a point, such as the center or lower-left.) ... and the objects Select objects: (Select one or more objects.) Select objects: (Press ENTER.) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 115 AutoCAD then gets busy creating the shape: Determining geometry extents...Done. Building coord lists...Done. Formating coords...|Done. Writing new shape...Done. Compiling shape/font description file Compilation successful. Output file C:\Tailor.shx contains 315 bytes. Shape "SPOTLIGHT" created. Use the SHAPE command to place shapes in your drawing. 6 . The prompt is, unfortunately, incorrect. To place shapes in the drawing, first use the Load command, followed by the Shape command: • The Load command loads the .shx (compiled .shp) file into AutoCAD. Recall that the .shx file contains one or more shapes. • The Shape command places the shape in the drawing: Command: shape Enter shape name or [?]: spotlight Specify insertion point: (Pick a point.) Specify height <1.0000>: (Press ENTER.) Specify rotation angle <0>: (Press ENTER.) The shape appears in the drawing. Examining the code in the tailor.shp file reveals the following mysterious string of numbers, letters, and punctuation. Aren’t you glad that someone took the time to write MkShape MkShape? *1,268,SPOTLIGHT 4,125,4,80,3,125,3,100,3,128,002,9,(33,35),(0,0),001,9,(11,12),(0,0),002,9,(-26,2),(0,0),001,9,(2,7),(0,0),002,9,(-20,-4) (0,0),001,9,(0,16),(0,0),002,9,(43,-43),(0,0),001,9,(7,3),(0,0),002,9,(-7,-45),(0,0),001,9,(7,3),(0,0),002,9,(-68,69) (0,0),001,9,(-2,7),(0,0),002,9,(-13,-17),(0,0),001,9,(-11,12),(0,0),002,9,(1,-68),(0,0),001,9,(7,-3),(0,0),002,9,(7,45) (0,0),001,9,(-7,3),(0,0),002,9,(93,-3),(0,0),001,9,(-4,7),(-5,6),(-5,5),(-7,4),(-7,3),(-16,2),(-7,1),(-8,-2),(-7,-3) (-6,-4),(-6,-5),(-5,-6),(-3,-6),(0,0),002,9,(76,-56),(0,0),001,9,(11,-12),(0,0),002,9,(26,2),(0,0),001,9,(2,-7),(0,0) 002,9,(-20,4),(0,0),001,9,(0,-16),(0,0),002,9,(-18,19),(0,0),001,9,(-2,-7),(0,0),002,9,(13,17),(0,0),001,9,(-11,-12) (0,0),002,9,(1,26),(0,0),001,9,(4,-7),(5,-6),(5,-5),(7,-4),(7,-3),(16,2),(7,1),(8,2),(7,3),(6,4),(6,5),(5,6),(3,6),(0,0) 002,9,(-43,21),(0,0),001,4,128,4,100,4,125,3,80,3,125,0 ○ ○ 116 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 The Shape File Format There are two forms of the shape file: one for shapes (simple blocks), and one for fonts. The difference is that fonts include a code 0 that alerts AutoCAD to treat the file as a font, not a shape. A shape file typically defines one or more shapes, up to 258 shapes in total. A font file typically defines all the characters — such as A-Z, a-z, 0-9, and punctuation — for a single font; Unicode font files can have up to 32,768 definitions. Like some other customization files, a shape definition consists of two or more lines. The first line is the header, which labels the shape, while the second (and following) lines define the shape through codes. The final code in each definition is 0, which is called the terminator. Each line can be up to 128 characters in length; AutoCAD will not compile a shape file with longer lines. A single definition is limited to 2,000 bytes. You can use blank lines to separate shape definitions, and the semi-colon ( ; ) to include comments in the file. 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 following describes the fields of the shape’s header description: * 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-orminus, and diameter symbols. In Unicode fonts, these are numbered U+00B0, U+00B1 and U+2205 in the Latin Extended-A subset. totalBytes After defining the shape, you have to add up the number of bytes that describe the shape, including the terminator, 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 117 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 measurement) 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). Vector codes are always in hexadecimal notation, such as 02C: xadecimal • 0: First character is always 0 to alert AutoCAD that the number is in he hexadecimal xadecimal. • 2: Second character specifies the vector’s length length, ranging from 1 through F (15 units). direction, as noted by the figure above. • C: Third character indicates the direction 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. ○ ○ 118 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 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. Hex Dec Description 000 001 002 003 004 005 006 007 008 009 00A 00B 00C 00D 00E 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 End of shape definition. Begin draw mode (pen down). End draw mode (pen up). Divide vector lengths by next byte. Multiply vector lengths by next byte. Push current location onto stack. Pop current location from stack. Draw subshape number given by next byte. X,y displacement given by next two bytes. Multiple x,y displacements; terminated with (0,0) code. Octant arc defined by next two bytes. Fractional arc defined by next five bytes. Arc defined by x,y displacement and bulge. Multiple bulge-specified arcs. Process next command only if vertical text code exists. 0/000: End of Shape Code 0 must mark the end of every shape definition. It appears at the end of the last line. 00C,(2,0,-127),0 1/001: Draw Mode Code 1 starts drawing mode (“pen” is down). By default, every shape definition starts with draw mode turned on. 2/002: Move Mode 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 3/003: Reduced Scale 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 119 4/004: Enlarged Scale 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. 5/005: Save (Push) 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. 6/006: Recall (Pop) 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. 8/008: X,y Distance 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 The example below shows that code 8 is used often: 2,14,3,2,14,8,(-21,-50),14,4,2,14,5,8,(11,25),1,8,(-7,-32),2, 8,(13,32),1,8,(-7,-32),2,8,(-6,19),1,0E0,2,8,(-15,-6),1,0E0,2, 8,(4,-6),14,6,14,3,2,14,8,(21,-32),14,4,2,0 In the first example, 8,(-21,-50) draws 21 units down (-x), and 50 units left (-y). ○ ○ 120 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 9/009: X,y Distances 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) 10/00A: Octant Arc Code 10 defines an octant arc, which is an arc whose angle is limited to multiples of 45 degrees, as shown by the figure. The arc is specifies by the following bytes: 10,radius,- 0 startingOctant octantSpan The 10 specifies an octant arc. The radius is a value between 1 and 255. The negative sign changes the direction of the arc to clockwise; leave it out for counterclockwise direction. The 0 specifies the following characters are hexadecimal. The startingOctant specifies where the arc starts; the value ranges between 0 and 7). The octantSpan specifies how hard the arc travels, again a number between 0 through 7. TIP When octantSpan is 0, the shape draws a circle. The octant arc code usually uses parentheses to make itself a bit clearer, such as: 10,(25,-040) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 121 11/ 00B: Fractional Arc 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 The 11 defines the fractional arc. The startOffset specifies how far (in degrees) from the octant angle the arc begins. The endOffset specifies how far from an octant angle the arc ends. The highRadius specifies a radius larger than 255 units; when the arc has a radius of 255 units or smaller, then this parameter is 0. AutoCAD multiplies the highRadius by 256, then adds it to radius value to find the radius of the arc. The radius is a value between 1 and 255. The negative sign changes the direction of the arc to clockwise; leave it out for counterclockwise direction. The 0 specifies the following characters are hexadecimal. The startingOctant specifies where the arc starts; the value ranges between 0 and 7. The octantSpan specifies how hard the arc travels, again a number between 0 through 7. 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. 12/00C: Bulge Arc 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 clockwise), while line would have a value of 0. For an arc of greater than 180 degrees, use two arcs in a row. ○ ○ 122 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 13/00D: Polyarc 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 zerobulge arc, than to switch between arcs and lines. 14/00E: Flag Vertical Text Flag 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. TIP The shapes, in The The ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ Express Tools collection has several commands useful for working with addition to MkShape described earlier in this chapter. Shp2Blk command converts shapes into blocks. TxtExp command explodes text and mtext into polylines. ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 8 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ shapes & fonts ○ ○ • ○ ○ ○ 123 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 124 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 nine script files tailoring AutoCAD 2004 i n this chapter, we look at AutoCAD’s clearest customization possibility: the script. What are Scripts? Script programming was introduced to AutoCAD with version 1.4, w-w-a-a-y-y back in 1983. A script does one thing and one thing only: it mimics what you type at the keyboard. Anything you type in AutoCAD that shows up at the ‘Command:’ prompt can be put into a script file. That includes AutoCAD commands, their option abbreviations, your responses, and — significantly— AutoLISP code. Anything you cannot type at the keyboard, including selecting buttons in dialog boxes and toolbars, cannot be included in a script file. The purpose of the script is to reduce keystrokes by placing the keystrokes in a file. Think of it as a predecessor to the toolbar macro. A script file to draw a line and a circle looks like this: line 1,1 2,2 circle 2,2 1,1 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 power user, I write scripts at the Windows command prompt: C:\> copy con filename.scr ;This is the script file line 1,1 2,2 circle 2,2 1,1 Z to tell Windows that I’ve finish editing, and to close the file. When I’m done, I press F6 or CTRL+Z ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 9 ○ ○ ○ ○ ○ ○ ○ script files ○ ○ • ○ ○ ○ 125 Table of Contents - Chapter 9 What are Scripts? ~ 125 Script Files ~ 125 Drawbacks to Scripts ~ 127 Strictly Command-Line Oriented ~ 127 Script Commands and Modifiers ~ 129 Script ~ 129 RScript ~ 129 Resume ~ 129 Delay ~ 129 Special Characters ~ 130 (space) ~ 130 ; (semicolon) ~ 130 ' (apostrophe) ~ 130 * (asterisk) ~ 131 Backspace ~ 131 Esc ~ 131 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 126 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Drawbacks to Scripts One limitation to scripts is that only one script file can be loaded into AutoCAD at a time. The script can, however, call other script files. Or, you can use some other customization facility to load script files with a single mouse click, such as toolbox or menu macros, and AutoLISP routines. Another limitation is that scripts stall when they encounter invalid command syntax. I sometimes have to go through the code-debug cycle a few times to get the script correct. It is useful to have an AutoCAD reference text on hand, such as my own The Illustrated AutoCAD Quick Reference (Delmar Learning), which lists all command names and their options. Some third-party developers have attempted to write automated script creation software. Strictly Command-Line Oriented There are two limitations to scripts that are significant in this age of GUIs (graphical user interfaces): scripts cannot record mouse movements, and scripts cannot control dialog boxes. For these reasons, nearly all commands that display a dialog box have a command line equivalent in AutoCAD. AutoCAD is, however, inconsistent in how it employs these commands. There are, in fact, five different ways to going about this: Layer), • Some commands have different names, such as (dialog box version in brackets): -Layer (Layer Layer ChP rop (DdChP DdChP rop Open ChProp DdChProp rop), and FileOpen (Open Open). • Sometimes it’s a command, and other times it’s a system variable. For example, the DSettings dialog box controls about a dozen system variables; to change settings in the script, use the related system variable(s) instead. If a script needs to 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 commands that display ile or Save F ile dialog boxes — such as DxfIn the Open F File File DxfIn, Script Script, and VSlide — to prompt for the filename at the command line. Thus, a script file would include the following lines to turn off dialog boxes: ; Turn filedia ; Load vslide off dialog boxes: 0 slide file: filename When FileDia is turned off, use the ~ (tilde) as a file name prefix to force the display of the dialog box. For example: Command: script Script file: ~ (AutoCAD displays Select Script File dialog box.) • To control plotting with a script, use the -Plot command, as follows: -plot Detailed plot configuration? [Yes/No] <No>: etc... ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 9 ○ ○ ○ ○ ○ ○ ○ script files ○ ○ • ○ ○ ○ 127 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 ools dialog box, AutoCAD displays the following prompt: Instead of the Multiline Edit T 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 ender, Lights Lights, Scene Scene, and so on. There is no way to control these comand rendering: OleLinks OleLinks, Render mands from a script file. ○ ○ 128 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Script Commands and Modifiers There are a grand total of four commands that relate specifically to scripts. In fact, these commands are of absolutely no use for any other purpose. In rough order of importance, these are: 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 ifthen, 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 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 9 ○ ○ ○ ○ ○ ○ ○ script files ○ ○ • ○ ○ ○ 129 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) represent you pressing the spacebar and Enter key. In fact, both are interchangeable. But the tricky part is that they are invisible. Sometimes, I’ll write a script that requires a bunch of blank space because the command requires that I press the Enter key several times in a row. AttEdit is an excellent example: ; Edit the attributes one at a time: attedit 1,2 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! ○ ○ 130 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 * (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 ...is the key I already mentioned for pausing a script file. 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). ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 9 ○ ○ ○ ○ ○ ○ ○ script files ○ ○ • ○ ○ ○ 131 Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 132 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 ten diesel expressions tailoring AutoCAD 2004 f or a dozen years, the status line of AutoCAD remained unchanged. Right through 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 were 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. The History of Diesel Then with AutoCAD Release 12 for DOS, Autodesk introduced the fully customizable status line. Users could not, unfortunately, simply select options from a dialog box. Instead, users needed to learn Yet Another Programming Language, this one called Diesel, and the sixth programming interface added to AutoCAD at the time. Short for “direct interactively evaluated string expression language,” the programming logic of Diesel is as clear as the acronym’s meaning. Despite the word “string,” Diesel operates on numbers primarily, not strings. While its purpose is to customize the status line, Diesel has found its way into menu macros, and became the most powerful programming environment available in AutoCAD LT — much to the chagrin of Autodesk, who deliberately disabled the AutoLISP that was supposed to ship with LT (retailers were worried LT’s low price would cannibalize sales of full-blown AutoCAD). Despite the handicap, European and Australian programmers, who are more price sensitive, have done some amazing things for LT third-party software with Diesel’s limited facilities. Is Diesel a true programming language? For me, the line of differentiation between a macro language and a programming language is whether it contains logical functions, such as If, While, or even GreaterThan, and so on. Logic functions make it possible for the program to make decisions. Diesel has logic functions, but the syntax is so obscure and its functions are so few that it begs to be known as a simple macro language — and that’s how I’ll refer to it from now on. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 10 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ diesel expressions ○ ○ • ○ ○ ○ 133 Table of Contents - Chapter 10 Diesel in Menus ~ 139 The History of Diesel ~ 133 What Diesel Does ~ 135 [ ~ 139 Brief Listing of Diesel Functions ~ 135 $(if, ~ 139 $(getvar,dimaso) ~ 139 Math Functions ~ 135 ,!. ~ 139 Logical Functions ~ 135 Conversion Functions ~ 135 ) ~ 140 String Functions ~ 136 /vAssociative Dimensions ~ 140 System Functions ~ 136 ] ~ 140 '_dimaso ~ 140 Jumping Into Diesel ~ 137 $M= ~ 140 Diesel Error Messages ~ 137 $(-,1, ~ 140 $(getvar,dimaso) ~ 140 $? ~ 137 $(func)?? ) ~ 140 ~ 137 $(func,??) Reusing Toggle Code ~ 141 ~ 137 $(++) ~ 137 Diesel in AutoLISP ~ 141 Debugging Diesel ~ 138 Via the setvar Function ~ 141 Diesel Programming Tips ~ 138 Concatenate Two Diesel Strings ~ 141 Via the MenuCmd Function ~ 142 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] for payment on additional copies. ○ ○ 134 ○ ○ • ○ ○ ○ Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 What Diesel Does Diesel allows you to change AutoCAD’s status line so that it displays useful information, such as the z-coordinate, the .dwg file name, and the time. There is a limitation, however: the text displayed by Diesel is truncated after a certain number of characters, no matter how big you make the window. The limits are 32 characters in AutoCAD 12, and 39 characters in Release 13 for Windows and later. Diesel has an unusual format for its macro language. Every function begins with the dollar sign and a bracket: $(function,variable) 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 functions 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. 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. Brief Listing of Diesel Functions Here is a summary of the functions supported by Diesel: Math Functions + * / Addition Subtraction Multiplication Division Logical Functions = < > != <= >= and eq if or xor Equal Less than Greater than Not equal Less than or equal Greater than or equal Logical bitwise AND Determines if all items are equal If-then Logical bitwise OR Logical bitwise XOR Conversion Functions angtos Converts number to angle format fix Converts real number to an integer rtos Converts number to units format ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 10 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ diesel expressions ○ ○ • ○ ○ ○ 135 String Functions index nth strlen substr upper Extract one element from a single comma-separated series Extract the nth element from a one or more items Returns the number of characters of the string Returns a portion of a string Converts text string to uppercase characters System Functions edtime eval getenv getvar linelen Displays the system time Passes a string to Diesel Gets a variable from the .ini file Gets a system variable. Returns the length of the display TIP AutoCAD 2004 allows interactive modification of the status line, although it is limited to toggling the display of existing buttons, and not the addition of user-useful items. Right-click the status line to display the shortcut menu: ○ ○ 136 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Jumping Into Diesel Enough of the preliminary stuff. Let’s jump right in, and put the customizable status line feature to work. 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) AutoCAD displays 0.0000 or something similar on the status line. Diesel Error Messages To go along with its obscure syntax, Diesel has an equally-bazaar set of error messages— all four of them. The cryptic error messages are printed by Diesel on the status line. Here’s what they mean, along with an example of how the error can occur: $? 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) $(++) The output string too long. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 10 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ diesel expressions ○ ○ • ○ ○ ○ 137 Debugging Diesel race system variable, as follows: To help track down bugs in Diesel macro, turn on the undocumented MacroT MacroTrace Command: macrotrace New value for MACROTRACE <0>: 1 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 race causes it to reevaluate the most recent Diesel expression over and over again. Each time A bug in MacroT MacroTrace race re-displays its I type something at the ‘Command:’ prompt (such as the Line command), MacroT MacroTrace race when you no evaluation. It does not, however, interfere except visually. For this reason, turn off MacroT MacroTrace longer need it, as follows: Command: macrotrace New value for MACROTRACE <1>: 0 Diesel Programming Tips Here are some tips for working with Diesel: 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 est"" the status line, use double quotations: ""T ""Test"" Tip #5: Use the MacroT race 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. ○ ○ 138 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Diesel in Menus Let’s now see how to use Diesel in menu macros and AutoLISP routines, and see just how complex Diesel can get. To use Diesel code within a menu file, you must prefix the code with the $M= code. Autodesk uses Diesel in the menu files it provides with AutoCAD to turn check marks on and off in the pull-down menus. For example, click on the Associative Dimensions item in the Options menu, AutoCAD turns off associative dimensions (actually, it sets the value of system variable DimAso to 0) and removes the check mark from in front of Associative Dimensions in the menu. It is fairly trivial to display the check mark: simply prefix the word with the !. symbol. Turning the check mark on and off is tricky and requires the use of Diesel programming. The menu macro below shows how Autodesk programmers accomplished this: [$(if,$(getvar,dimaso),!.)/vAssociative Dimensions]'_dimaso $M=$(-,1,$(getvar,dimaso)) (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 Dimensions with or without the check mark. case, you would see Associative Dimensions, $(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: DimAso Meaning for AutoCAD Meaning for Diesel "if" Expression 1 (default) 0 Use associative dimensions Use non-associative dims True False ,!. 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 10 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ diesel expressions ○ ○ • ○ ○ ○ 139 ) The final parenthesis ends the Diesel "if" expression. /vAssociative Dimensions The / metacharacter is how AutoCAD displays the underlined character in pull-down menus. In this case, the v in the word Associati Associativve is underlined. Recall that the underlined character is the keyboard shortcut: you don’t need 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 ar command is that all system variables can be typed at the ‘Command:’ prompt like a command; the SetV SetVar optional. 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) ar function again. This time, however, after the value of Embedded inside the subtract function is Diesel’s GetV 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: DimAso Action of Macro 1 (default) 0 1-(DimAso) 1-(DimAso) New Value of Macro 0 1 ) Finally, the macro ends with the closing parenthesis. ○ ○ 140 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Reusing Toggle Code Does your head hurt yet? The happy ending to this mind-numbing exercise is that you can reuse the code for all kinds of toggle situations. There are many toggle-type commands in AutoCAD. I can think of Grid Grid, Snap Snap, Ortho rame ... Ortho, TileMode ileMode, SplF SplFrame In fact, simply go though the list of system variables: any one with a value of just 0 or 1 is a toggle. To reuse the code for other toggles, simply replace the parts shown in boldface boldface: [$(if,$(getvar, dimaso ),!.)/ vAssociative Dimensions ]'_ dimaso $M=$(-,1,$(getvar, dimaso )) ; ; ; ; ; ; ; ; ; Keep this code. Replace with appropriate system variable name. Keep. Replace with appropriate shortcut key and label name. Keep Replace with system variable name, same as above. Keep. Replace with system variable name, same as above. Keep. 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! Diesel in AutoLISP ar function; and (2) There are two ways to use Diesel expressions inside an AutoLISP routine: (1) with the SetV SetVar the MenuCmd function. I don’t know if there is a preference for either among the programming community; in either case, I am accessing Diesel in an indirect manner. Via the setvar Function The setvar function is used in conjunction with the ModeMacro system variable. You’ll recall from the earlier tutorial that the ModeMacro system variable is used to execute Diesel from the ‘Command:’ prompt. The same trick is used here. To show how this works, I'll write an AutoLISP routine to displays the fillet radius on the status line — using Diesel (shown in boldface). (defun frad () (setvar "modemacro" "Current fillet radius: $(getvar,filletrad)") ) The FilletRad system variable stores the current setting for the filleting radius. Concatenate Two Diesel Strings To display more than one piece of information on the status line, I use the StrCat function to concatenate the two Diesel strings to the ModeMacro system variable in one piece. The following AutoLISP code displays the two chamfer distances at the status line: (defun chab () (setvar "modemacro" (strcat "Chamfer A: $(getvar,chamfera)" "Chamfer B: $(getvar,chamferb)") ) ) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 10 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ diesel expressions ○ ○ • ○ ○ ○ 141 Via the MenuCmd Function The second method for using Diesel in AutoLISP functions uses the MenuCmd function, along with the M= construct, as follows: (defun chab () (menucmd "M=Current fillet radius: $(getvar,filletrad)") ) The M= should be familiar from the earlier discussion of using Diesel inside of menu macros. Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 142 ○ ○ • ○ ○ ○ v1.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 eleven autolisp programming tailoring AutoCAD 2004 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. The History of AutoLISP For 20 years now, AutoCAD has had a full-fledged programming language embedded in itself: AutoLISP. At no extra cost to you, AutoLISP lets you create programs that manipulate nearly every aspect of AutoCAD and the drawing. AutoLISP first appeared as an undocumented feature in AutoCAD v2.15 during the summer of 1985. Programmers at Autodesk had taken XLISP, a public domain version of LISP written by David Betz, and adapted it for AutoCAD. With the next release of AutoCAD, v2.17, only third-party developers were told about the new feature, then called “Variables and Expressions.” Finally, in v2.18 the new programming language was documented by Autodesk. The first versions of AutoLISP were very weak, lacking even conditional statements. Early uses of Variables and Expressions included gimmick routines like repeatedly zooming into a drawing. With AutoCAD v2.5, Autodesk got serious: they renamed the programming language AutoLISP, and added the GETxxx and SSxxx routines that provided direct access to objects in the database. Third-party developers could now write powerful routines that manipulated the entire drawing. Regular users found AutoLISP simple for writing short routines that helped automate their everyday drafting activities. The drawback, however, was the AutoLISP was interpreted, which meant that it ran slowly. This was not an issue for short routines, but did affect large programs. To solve the problem, Autodesk introduced with AutoCAD Release 10 for OS/2 a new programming environment, called ADS (AutoCAD development system), which allowed programmers to hook C-language routines into AutoCAD. Later, Autodesk purchased Visual LISP from Bitwise Solutions, which compiled LISP code to run faster. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 143 Table of Contents - Chapter 11 The History of AutoLISP ~ 143 Writing a Simple AutoLISP Program, Cont’d ~ 160 The AutoLISP Programming Language ~ 145 Sprucing Up the Code ~ 160 Conquering Feature Bloat ~ 160 Simple AutoLISP: Adding Two Numbers ~ 145 Wishlist Item #1: Naming the Program ~ 161 AutoLISP in Commands ~ 147 Wishlist Item #2: Saving the Program ~ 162 Remembering the Result: SetQ ~ 147 Wishlist Item #3: Automatically Loading the Program ~ 162 AutoLISP Functions ~ 149 Wishlist #4: Using Car and Cdr ~ 162 Math Functions ~ 149 Saving Data to a File ~ 166 Geometric Functions ~ 150 The Three Steps ~ 166 Conditional Functions ~ 151 String and Conversion Functions ~ 151 Step 1: Open the File ~ 166 External Command Functions ~ 152 Step 2: Write Data to the File ~ 167 Step 3: Close the File ~ 167 Accessing System Variables ~ 154 Putting It Together ~ 168 GetXXX Functions ~ 154 Selection Set Functions ~ 155 Wishlist #5: Layers ~ 169 Object Manipulation Functions ~ 155 Wishlist #6: Text Style ~ 169 Advanced AutoLISP Functions ~ 156 Tips in Using AutoLISP ~ 169 Writing a Simple AutoLISP Program ~ 156 Tip #1: Use an ASCII Text Editor. ~ 169 Tip #2: Loading LSP Code into AutoCAD ~ 169 Why Write a Program? ~ 156 Tip #3: Toggling System Variables ~ 170 The Id Command ~ 156 Tip #4: Be Neat and Tidy. ~ 170 The Plan of Attack ~ 156 Tip #5: Suppress That nil ~ 170 Obtaining the Coordinates ~ 157 Placing the Text ~ 158 Tip #6: Read-Write-Append File ~ 171 Putting Them Together ~ 159 Tip # 7: Quotation Marks as Quotation Marks ~ 171 An Alternative to LISP Programming ~ 159 Tip # 8: Keep Variables to Six Characters ~ 171 Tip #9: Tabs and Quotation Marks ~ 172 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 144 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 The AutoLISP Programming Language AutoLISP lets you do anything from adding together two numbers — in the middle of a command — to drawing parametrically a staircase in 3D, to generating a new user interface for AutoCAD. AutoLISP has the ability to manipulate data in the drawing database. In fact, many new commands (such as ray and Edge 3dAr 3dArray Edge) and Express Tools are actually AutoLISP programs. (AutoCAD 2000 switched to another programming interface, called ObjectARX, to provide new commands. Still, a search of the AutoCAD 2004 folders finds 85 LISP files!) The most important aspect of AutoLISP, in my opinion, is that you can toss off a few lines of code to help automate your work. In this chapter’s tutorials, I’ll show you how to write simple AutoLISP code that makes your AutoCAD drafting day easier. Also, I show you how to integrate AutoLISP code into toolbar macros and script files. In contrast, AutoCAD’s most powerful programming facility— known as ObjectARx (AutoCAD Runtime eXtension) — is merely an interface: you have to buy additional the programming tools (read: $$$) and have an in-depth knowledge of advanced programming methodology. The primary advantage to using ObjectARx is speed: these programs run compute-intensive code as much as 100 times faster than AutoLISP. For this reason, Autodesk wrote most of the new commands in ObjectARX. Look for filenames ending in .arx as examples of ObjectARX program and commands — I found 107 of them in AutoCAD 2004. (AutoCAD LT users are out of luck: AutoLISP is not available to you. Even though Autodesk had AutoLISP in the beta version of LT Release 1, the code was yanked in the last days before the software began shipping because dealers were worried the cheaper LT would be too powerful and eat into sales of the more expensive AutoCAD. When you try to use AutoLISP, LT responds: “AutoLISP command not available.”) Simple AutoLISP: Adding Two Numbers With that bit of background, let’s dive right into using AutoLISP. Start with something easy, something everyone knows about: add together two numbers, like 9 plus 7. 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> AutoCAD displays the 1> prompt to tell you that one closing parenthesis is missing. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 145 4. Type the missing ) and AutoCAD is satisfied: 1> ) 16 Command: 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 Unknown command Command: 9 (Press Unknown command Command: 7 (Press Unknown command Command: Spacebar.) "+". Type ? for list of commands. Spacebar.) "+". Type ? for list of commands. Spacebar.) "+". Type ? for list of commands. 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: 7 . Multiplication is done using the familiar * (asterisk) symbol, as follows: Command: (* 9 7) 63 Command: 8 . Finally, division is performed with the / (slash) symbol: Command: (/ 9 7) 1 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: And AutoLISP returns the answer correct to five decimal places. 9 . Finally, let’s see how AutoLISP lets you nest calculations: Command: (+ (- (* (/ 9.0 7.0) 4) 3) 2) 4.14286 Command: Note how the parentheses aid in separating the nesting of the terms. ○ ○ 146 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 AutoLISP in Commands Okay, so you’ve learned how AutoCAD works as a $3,250 four-function calculator. This calculator pays its way when you employ AutoLISP to perform calculations within a command. For example, you need to draw a linear array of seven circles to fit in a 9" space. 1 . Start the Circle command, as follows: Command: circle 3P/2P/TTR/<Center point>: (Pick a point.) Diameter/<Radius>: d 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 -Array command, and draw the other six circles, as follows: 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. TIP An alternative to using AutoLISP for mid-command calculations is the ’Cal command. Its primary benefit is that it includes advanced vector functions, which are lacking from AutoLISP roster of functions. Remembering the Result: SetQ In the above example, you used the (/ 9.0 7) equation twice: once in the Circle command and again in the Ar ray command. Just like the M-key on a calculator lets it remember the result of your calculation, AutoLISP Array can be made to remember the results of all your calculations. 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 147 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. 3. AutoLISP isn’t limited to just one variable. You can make up any combination of characters to create variable names, such as Pt1 Pt1, Diameter Diameter, and Yvalue Yvalue. The only limitation is that you cannot use AutoLISP function names, such as SetQ SetQ, T, and GetInt GetInt. In fact, it is good to create variable names that reflect the content, such as the circle diameter calculated above. But you also want to balance a descriptive name, such as Diameter with minimized typing, such as x. A good compromise for our example is Dia Dia. You make one variable equal another, as follows: Command: (setq dia x) 1.28571 Command: !dia 1.28571 Command: 4 . Redo the Circle and -Array commands, this time using variable Dia 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 AutoCAD precisely draws the same seven circles. ○ ○ 148 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 AutoLISP Functions Autodesk made AutoLISP so powerful that it can manipulate almost any aspect of the AutoCAD drawing. In this tutorial, you get a taste of the many different kinds of functions AutoLISP offers you for manipulating numbers and words. As we start on our whirlwind tour of five groups of functions, start AutoCAD and type the examples in the text screen at the ‘Command:’ prompt. 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 Returns the sine of the angle of 3 radians. TIP You must provide the angle in radians (such as for 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 exclamation 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 149 Geometric Functions Since CAD deals with geometry, AutoLISP has a number of functions for dealing with geometrics. For example, the Distance function is just like the Dist command: Command: (setq p1 '(1.3 5.7)) (1.3 5.7) Command: (setq p2 '(7.5 3.1 11)) (7.5 3.1 11) Command: (distance p1 p2) 6.72309 It returns the 3D distance between two points. You may have missed that single quote mark in front of the list of x,y,z-coordinates, as in: '(1.3 5.7). That tells AutoLISP you are creating a pair (or triple) of coordinates, and that it shouldn’t try to evaluate the numbers. TIPS Don’t use commas! Use spaces to separate the values of the coordinates. When you leave out the z-coordinate, AutoLISP assumes it equals 0.0. 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.) Command: (osnap p1 "mid") (4.4 4.4 5.5) 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. ○ ○ 150 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Conditional Functions You could say that conditional functions are the most important, since they define the existence of a programming language. If you’re not sure if it’s a programming language or merely a macro language, check for conditionals. The toolbar macros have no conditionals; they are not a true programming language. It is conditionals that allow a computer program to “think” and make decisions. Conditional functions check if one value is less than, equal, or greater than another value. They check if something is true; they repeat an action until something is false. For example, if the floor-to-ceiling distance is greater than eight feet, then draw 14 steps; else, draw 13 steps. A similar wording is used in condition functions: Command: (if (> height 96) (setq steps 14) (setq steps 13)) 13 Let's break this down to see how the function compares with our statement: (if (> height 96) If greater than floor-to-ceiling distance 8 feet; Then use 14 steps. Else use 13 steps. (setq sets 14) (setq steps 13) ) String and Conversion Functions You can manipulate strings (one or more characters) in AutoLISP but to a lesser extent than numbers. For example, you can find the length of a string as follows: Command: (strlen "AutoCAD World") 13 en (short for STRing LENgth) function tells you that “AutoCAD World” has 13 characters in it, The StrL StrLen counting the space. Notice how “AutoCAD World” is surrounded by quote marks. That tells AutoLISP you are utoCAD W orld) working with a string, not a variable. If you type (strlen A AutoCAD 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" Command: (setq world "The planet earth") "The planet earth" Command: (strlen autocad world) 34 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" That’s how you create reports, such as 13 “steps drawn drawn”” by mixing text and variables. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 151 Related to string functions are the conversion functions because some of them convert to and from strings. For example, earlier we showed how to convert 45 degrees to radians. That’s fine for decimal degrees, like 45.3711 degrees. But how do you convert 45 degrees, 37 minutes and 11 seconds, which AutoCAD represents as 45d37'11"? That’s where a conversion function like Angtof (short for ANGle TO Floating-point) comes in. It converts an angle string to a real number radians: Command: (angtof "45d37'11\"" 1) 0.796214 Here we’ve supplied Angtof with the angle in degrees-minutes-seconds format. Notice how the seconds indicator (") is handled: \". That’s so it doesn't get confused with the closing quote mark (") that indicates the end of the string. AutoLISP isn’t, however, smart enough to know that, so we tell it by means of the mode number, 1 in this case. This (and some other functions) use the following as mode numbers: Mode Meaning Example 0 1 2 3 4 Decimal degrees Degrees-minutes-seconds Grad Radian Surveyor units 45.3711 45d 37' 11" 100.1234 0.3964 N 45d37'11" E Notice the similarity between the mode numbers and the values of system variable AUnits AUnits. 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 ar (short for GET VARiable), the AutoLISP function that gets the value of a system variable. Here we use GetV GetVar We used Getvar to get AUnits Units, which holds the state of angular display as set by the Units command. Other conversion functions convert one unit of measurement into another (via the Cvunit function and the acad.unt file), an integer number into a string, a character into its ASCII value (for example, letter A into ASCII 65), and translates (i.e. moves) a point from one coordinate system to another. External Command Functions “Powerful” often equates to “complicated,” yet one of AutoLISP’s most powerful functions is its simplest to understand: the Command function. As its name suggests, Command executes AutoCAD commands from within AutoLISP. Think about it: this means that it is trivial to get AutoLISP to draw a circle, place text, zoom a viewport, whatever. Anything you type at the ‘Command:’ prompt is available with the Command function. Let’s see how the Command function works by drawing a circle. First, though, let’s recall how the Circle command works: Command: circle 3P/2P/TTR/<Center point>: 2,2 Diameter: D Diameter: 1.5 ○ ○ 152 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 In the Command function, you mimic what you type at the ‘Command:’ prompt like this: Command: (command "circle" "2,2" "D" "1.5") Notice how all the typed text is in quotation marks. After you type that in, AutoCAD responds by drawing the circle: circle 3P/2P/TTR/<Center point>: 2,2 Diameter: D Diameter: 1.5 Command: nil (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 Converted to AutoLISP-ese, this becomes: Command: (command "text" "5,10" "1.5" "" "Tailoring AutoCAD") And AutoCAD responds with: text Justify/Style: 5,10 Height <0.2000>: 1.5 Rotation angle <0>: Text: Tailoring AutoCAD Command: nil and draws the text. For the ‘Rotation angle:’ prompt, we simply pressed the ENTER key. Notice how that was dealt with in the AutoLISP function: "" — a pair of empty quotation marks. You use the same thing for commands that automatically repeat themselves, such as the Line command: Command: (command "line" "1,2" "3,4" "") 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 153 Accessing System Variables While you could use the Command function to access system variables, AutoLISP has a pair of more direct ar and SetV ar ar gets the value of a system variable, while SetV ar changes (sets) the functions: GetV GetVar SetVar ar. GetV GetVar SetVar value. rame determines whether the frame of a spline polyline is displayed; by For example, system variable SplF SplFrame rame is 0: the frame is not displayed, as confirmed by GetV ar: default, the value of SplF SplFrame GetVar ar Command: (getvar "splframe") 0 rame to 1 with SetV ar as follows: To display the frame, change the value of SplF SplFrame SetVar Command: (setvar "splframe" 1) 1 rame is 0. Zero is the default value We have made, however, a crass assumption here: that the initial value of SplF 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: GetPoint GetAngle GetString GetReal Returns Returns Returns Returns the the the the x,y,z-coordinates of a picked point. angle in radians. text the user types in. value of a real number typed in by the user. 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 eal converts the 2 (an integer) to a real number, 2.0. Notice how GetR 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) ○ ○ 154 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 oint returns the x, y, and z values of the coordinate, even though z is zero. Finally, we execute Notice how GetP GetPoint the 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. Selection Set Functions To work with more than one object at a time, AutoLISP has a group of functions for creating a selection set. These all begin with SS, as in: SsAdd SsDel SsLength SsMemb Adds an object to the selection set. Deletes an object from the selection set. Reports the number of objects in the selection set. Checks if an object is part of the selection set. 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. Object Manipulation Functions The really powerful AutoLISP functions are the ones that go right in and manipulate the drawing database. Unlike the Command function, which is powerful but simple, the object manipulation functions are powerful and complicated. Here’s a summary of what some of these are: EntMake EntGet EntMod EntDel TblObjName Creates a new object. Gets the data that describes an object in the drawing. Changes the object. Erases an object from the database. Gets the name of an object in a symbol table. 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 ay is the name of the layer. You can see that to two values: 2 is the DXF code for layer names, and RightOfW RightOfWay work with these object manipulating functions, you need a good grasp of the DXF format. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 155 Advanced AutoLISP Functions There is a whole host of AutoLISP functions that you may never use in your AutoCAD programming career. For example, Autodesk has written 41 AutoLISP functions for controlling the ASE (AutoCAD Structured query language Extension) link between objects in the AutoCAD drawing and records in an external database file. These functions are not hard to spot: they all start with “Ase_”, as in Ase_LsUnite and Ase_DoCmp Ase_DoCmp. Another set of AutoLISP functions — 21 of ’em — are strictly for loading and displaying dialog boxes, such as Load_Dialogue and New_Dialogue New_Dialogue. Another five functions are for memory management, whose use is so rarified that Autodesk recommends never using them. Writing a Simple AutoLISP Program In this part of the chapter, you learn the first steps in writing an AutoLISP routine of your own. Why Write a Program? If you are like many CAD users, you are so busy creating drawings that you have no time to learn how to program. No doubt, you may be wondering, “Why bother learning a programming language?” In some ways, it’s like being in school all over again. Sitting in the classroom seems like a waste of time, sometimes. But the things you learn now make life easier later. Learning some AutoLISP programming now means you’ll feel really good whipping off a few lines of code and letting AutoLISP perform a tedious task for you. The nice thing about AutoLISP is that you can program it on the fly. And you can use it for really simple but tedious tasks. Here’s the example we’ll use for this tutorial: 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. The Plan of Attack Before you write any AutoLISP code, you need to figure out how you’re going to get those x,y,z- coordinates off the command prompt area and into the drawing. We’ve just recognized the two parts to solving the problem: Part 1. Obtain the coordinates from the drawing, probably by picking a point. Part 2. Place the coordinates as text in the drawing. ○ ○ 156 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Obtaining the Coordinates 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"). oint system variable with the GetV • Use the LastP LastPoint GetVar "lastpoint"). ar function, as in (getvar "lastpoint") ick a point: ") oint function, as in (getpoint "P • Use the GetP GetPoint "Pick It would be a useful lesson to use each of the three, and then 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" because the command is a string (programmer talk for “text”). Just like before, AutoCAD prompts you for the point. 2 . This time use an object snap to snap to a geometric feature, like the end of a line: Point: end of (Pick a point.) X = 8.9227 Y = 6.5907 Z = 0.0000 That’s great! You’ve typed in a tiny AutoLISP routine. Now, AutoCAD stores the x,y,z- coordinates of the oint last-picked point in system variable LastP 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 ar is the name of the GetVar LastP oint AutoLISP that retrieves the value stored in a system variable. And "LastP 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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 157 4 . So, we’ve now solved the first problem in one manner. We obtained the coordinates off the drawing and oint stored them in a variable. We did mention a third AutoLISP function we could use, GetP GetPoint oint. Programoint because it is more efficient than the Id-LastP oint combo we used above. Type mers prefer GetP GetPoint Id-LastPoint the following 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 GetPoint oint "P oint: " function waits for you to pick a point on the screen. The "Point: is called a prompt and tells the user what the program is expecting the user to do. In this case, we mimicked the prompt of the ID command. 5 . But we could just as easily have written anything, like: Command: (setq xyz (getpoint "Press the mouse button: ")) Press the mouse button: (Pick a point.) (8.9227 6.5907 0.0000) 6 . Or, we could have no prompt at all, as follows: Command: (setq xyz (getpoint)) (Pick a point.) (8.9227 6.5907 0.0000) 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. We’ve now seen several approaches that solve the first problem in several different ways. With the x,y,z-coordinates safely stored in a variable, let’s tackle the second problem Placing the Text To place text in the drawing, there is just one solution: the command function in conjunction with the Text command. I suppose the MT MTeext command might work, but we are placing one line of text, and the Text command is excellent for that. The Text command is trickier than the Id command. It has four prompts that your AutoLISP routine must answer: • Start point: a pair of numbers, x,y-coordinates. • Height: a number that makes the text legible. • Rotation angle: a number, probably 0. • Text: a string, the x,y,z-coordinates. 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: (command is the Command function. "te xt" is the AutoCAD Text command being executed. "text" xyz variable stores the starting point for the text. 200 is the height of the text. Change this number to something convenient for your drawings. ○ ○ 158 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 0 is the rotation angle of the text. xyz — we’re lucky: the Text command accepts numbers stored in variables as text. ) and remember: one closing parenthesis for every opening parenthesis. Let's try this out at the ‘Command:’ prompt: Command: (command "text" xyz 200 0 xyz) text Justify/Style/<Start point>: Height <1.0>: 200 Rotation angle <0>: 0 Text: 2958.348773815669,5740.821183398367 Command: nil 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. Putting Them Together Let’s put together the two solutions to our problem: (setq xyz (getpoint "Pick point: ")) (command "text" xyz 200 0 xyz) 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, you 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. An Alternative to LISP Programming Just because this tutorial is about AutoLISP doesn’t mean that it is always the best approach. Here’s a wacky work-around to labeling points that uses no programming at all: 1 . Use the Id command and pick a point: Command: id Point: (Pick a point.) X = 8.9227 Y = 6.5907 Z = 0.0000 2 . Switch to the text screen by pressing function key F2 F2. 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. 6 . Press F2 to switch back to AutoCAD drawing window. 7 . Press CTRL+V +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. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 159 Writing a Simple AutoLISP Program, Cont’d In the last tutorial, you learned the first steps in writing an AutoLISP routine of our own. You created a two-line AutoLISP program that looks like this: (setq xyz (getpoint "Pick point: ")) (command "text" xyz 200 0 xyz) 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. 2. When AutoCAD prompts, “Pick point: “, pick a point on the drawing: Pick point: (Pick a point.) 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. Sprucing Up the Code There we have it: a full-fledged AutoLISP program. Well, not quite. What we have is the algorithm — the core of every computer program that performs the actual work. What is lacking is most of the user interface — the part that makes it easier for the user to employ the program. All we have for a user interface is part of the first line that prompts, “Pick point: ”. There are many user interface problems with our little program. How many can you think of? Here’s a list of problems I’ve come up with: • 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. Conquering Feature Bloat “Okay,” you may be thinking, “I can agree that these are all desirable improvements. Go right ahead, Mr. Grabowski, and show how to add them in.” But, wait a minute! When you’re not familiar with AutoLISP, you may not realize how a user interface adds a tremendous amount of code, which mean more bugs and more debugging. If you are familiar with programming, then you know how quickly a simple program fills up with feature-bloat. While all those added features ○ ○ 160 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 sound desirable, they may make the program less desirable. Can you image how irritated you’d get if you had to answer the questions about decimal places, text font, text size, text orientation, layer name, filename — each time you want to label a single point? Take a second look at the wishlist to check off what is important, and cross off what you could live without. Wishlist Item #1: Naming the Program To give the program a name, 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) ) Let’s take a look at what’s been added, piece by piece: (defun defines the name of the function. In AutoLISP, the terms function, program, and routine are used interchangeably. 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 you 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 you run the program like an AutoLISP function with the parentheses, as follows: Command: (label) Pick point: (Pick a point.) TIP The c: prefix turns an AutoLISP function into an AutoCAD command. You can use other prefixes for your own purposes, such as to identify subroutines you created, such as: (defun rhg:label) ( / 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 programmers; the indents make it easier to read code. You can use a pair of spaces or the tab key since AutoLISP doesn’t care. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 161 Wishlist Item #2: Saving the Program By saving the program to a file on disk, you avoid retyping the code with each new AutoCAD session. To do this: 1 . Start a text editor (the NotePad supplied with Windows is good). 2 . Type the code shown: (defun c:label ( / xyz) (setq xyz (getpoint "Pick point: ")) (command "text" xyz 200 0 xyz) ) 3. Save the file with the name label.lsp in AutoCAD’s folder named \support. Wishlist Item #3: Automatically Loading the Program To load the program into AutoCAD, type the following: Command: (load "label") If AutoCAD cannot find the AutoLISP program, then you have to specify the path. Assuming you saved label.lsp in the folder \autocad 2004\support you would type: Command: (load "\\autocad 2004\\support\\label") Now use the point labelling routine, as follows: Command: label Pick point: (Pick a point.) 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. Wishlist #4: Using Car and Cdr 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 rec — the precision specified by the user via the Units Or steal the value stored in system variable LUP UPrec command — under the (not necessarily true) assumption that the user want consistent units. The code to do this is as follows: (setq uprec (getvar "LUPREC")) ○ ○ 162 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 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) ) Save and load label.lsp into AutoCAD. 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. 3 . At the ‘Command:’ prompt, type the following: Command: !xyz (6.10049 8.14595 10.0) The exclamation mark forces AutoCAD to print the value of variable XYZ XYZ, which holds the x,y,zcoordinates. Your results will differ, depending on where you picked. 4 . LISP has several functions for picking apart a list. Here we’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 5 . The cdr function is the compliment to car car. It removes the first item from the list and gives you what’s left: Command: (cdr xyz) (8.14595 10.0) 6 . In addition to car and cdr cdr, 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 7 . And to extract the z-coordinate, use caddr caddr, as follows: Command: (caddr xyz) 8.14595 8 . You now have a way to extract the x-coordinate, the y-coordinate, and the z-coordinate from variable XYZ XYZ. Store them in their own variables, as follows: Command: (setq ptx (car xyz) 1> pty (cadr xyz) 1> ptz (caddr xyz) 1> ) Use PtX to store the x-coordinate, PtY for the y-coordinate, and so on. In addition, we are using a form of LISP shorthand that allows us apply the SetQ function to several variables. Recall the reason for AutoCAD’s 1> prompt: it reminds us that a closing parenthesis is missing. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 163 9 . Now that the three coordinates are separated, you can finally reduce the number of decimal places. There are a couple of ways to do this, but we’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" The RtoS function uses three parameters: PtX Name of the variable holding the real number. 2 Type of conversion, decimal in this case. The number 2 is based on system variable LUnits, which defines five modes of units: Mode Units 1 2 3 4 5 UPrec Scientific Decimal Engineering Architectural Fractional 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.” rec is 1, the RtoS function in the code fragment above reduces Assuming, then, that the precision in UP UPrec 6.10049 to 6.1. 10. 0. 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 you 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 PtX PtX. Reusing a variable name like this helps conserve memory. 11. With the coordinates truncated, you 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 we was hoping for. Since LISP can’t know when we want spaces, it doesn’t provide any. You have to insert them. StrCat is one of the most useful LISP functions, since it lets you create a string that contains text and variables, like this: Command (setq xyz (strcat ptx ", " pty ", " ptz)) "6.1, 8.1, 10.0" That’s more like it. ○ ○ 164 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 13. Back to the text editor. Add in the code we 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) ) (setq xyz1 (strcat ptx ", " pty ", " ptz)) (command "text" xyz 200 0 xyz1) ) Notice that all the variables are 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, you should add comments to the code to remind you what it does when you 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) ; Ask user for the number of decimal places: (setq uprec (getint "Label precision: ")) ; Ask the user to pick a point in the drawing: (setq xyz (getpoint "Pick point: ")) ; Separate 3D point into individual x,y,z-values: (setq ptx (car xyz) pty (cadr xyz) ptz (caddr xyz) ) ; Truncate values: (setq ptx (rtos ptx 2 uprec) pty (rtos pty 2 uprec) ptz (rtos ptz 2 uprec) ) ; Recombine individual values into a 3D point: (setq xyz1 (strcat ptx ", " pty ", " ptz)) ; 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" ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 165 16. Run the routine: Command: label Label precision: 1 Pick point: (Pick a point.) text Justify/Style/<Start point>: Height <200.0000>: 200 Rotation angle <0>: 0 Text: 5012.3, 773.2, 0.0 Command: nil Saving Data to a File In the last tutorial, we began to worry about user interface enhancements. What started out as two lines of code has now bulged out into 23 lines of code. In this tutorial, we add the ability to save data to a file and learn how to fight feature bloat. A reader wrote, “The LISP file comes in very handy with some of the programs I use, but I would like to be able to save the data collected on the x,y,z- coordinates in a text file.” Saving the data to file is easily done with the (open "a") "a"), (write-line) (write-line), and (close) functions. Let’s take a look at how to do this. Dealing with files in AutoLISP is simpler than for most programming languages because AutoLISP has very weak file access functions. All it can do is read and write ASCII files in sequential order; AutoLISP cannot deal with binary file nor can it access data in random order. While AutoCAD users have often asked for those abilities, Autodesk has chosen not to add them. The Three Steps There are three steps in writing data to a file: • Open the file. • Write the data to the file. • Close the file. Step 1: Open the File 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 FIL FIL. 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. ○ ○ 166 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Now that you have the file descriptor stored in variable FIL FIL, you work with FIL FIL, 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 "a" "w" "r" Append data to end of file. Write data to file, after erasing existing data. Read data from file. Step 2: Write Data to the File 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 pty ptz ) (setq ptx (car xyz) (cadr xyz) (caddr xyz) xyz1 (strcat ptx ", " pty ", " ptz)) Step 3: Close the File 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) ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 167 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) ) ; Format the x,y,z coordinates: (setq ptx (rtos ptx 2 uprec) pty (rtos pty 2 uprec) ptz (rtos ptz 2 uprec) ) ; Add commas between the three coordinates: (setq xyz1 (strcat ptx ", " pty ", " ptz)) ; Write coordinates to the drawing: (command "text" xyz 200 0 xyz1) ; Open the data file for appending: (setq fil (open "xyzdata.txt" "a")) ; Write the line of data to the file: (write-line xyz1 fil) ; Close the file: (close fil) ) 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") And run the program by typing Label at the ‘Command:’ prompt: Command: label Label precision: 4 Pick point: (Pick a point.) 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, 7.0856, 6.4295, 5.5303, 5.4331, ○ ○ 168 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ 3.2752, 4.4883, 5.6528, 6.7688, 8.3215, ○ ○ ○ ○ 0.0000 0.0000 0.0000 0.0000 0.0000 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Wishlist #5: Layers 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. Wishlist #6: Text Style 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 following: (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. Tips in Using AutoLISP Here are some tips for helping out when you write your own AutoLISP functions. You may want to save clip this for reference. Tip #1: Use an ASCII Text Editor. AutoLISP code must be written in plain ASCII text — no special characters of the sort that all word processors add in. If you were to write AutoLISP code with, say, Word, then save as a .doc file (the default), AutoCAD would refuse to load the AutoLISP file, even when the file extension is .lsp. In an increasingly WYSIWYG world, it is becoming harder to find a true ASCII text editor. There is one pure ASCII text editor supplied free by Microsoft with Windows called Notepad, which you’ll find in the \windows folder. Do not use Write or WordPad supplied with Windows. While both of these have an option to save in ASCII, you’re bound to forget sometimes and end up frustrated. Almost any other word processor has an option to save text in plain ASCII, but not by default. Word processors have a number of different terms for what I mean by “pure ASCII format”. Word calls it “Text Only”; WordPerfect calls it “DOS Text”; WordPad calls it “Text Document”; and Atlantis calls it “Text Files.” Tip #2: Loading LSP Code into AutoCAD To load the AutoLISP code into AutoCAD, you use the load command, which is not to be confused with the Load command (which is for loading a .shx compiled shape files). load is for loading AutoLISP code. Clear? Here’s an example where points.lsp is the name of the AutoLISP routine: Command: (load "points") ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 169 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. Tip #3: Toggling System Variables One of the problems in programming is: How to change a value when you don't know what the value is? In AutoCAD, you come across this problem with system variables, many of which are toggles. A toggle system variable has a value of 0 or 1, indicating that the value is either off (0) or on (1). For example, system variable SplF rame is by default 0: when turned off, splined polylines do not display their frame. SplFrame rame is going to be zero just because that’s its No computer programmer ever assumes that the value of SplF SplFrame default value. In the case of toggle system variables, there two solutions: • Use the if function to see if the value is 0 or 1. • Subtract 1, and take the absolute value. Tip #4: Be Neat and Tidy. Remember, your mother told you to always pick up your things. This advice applies to the problem of the settings of system variables. When your AutoLISP routine changes values of system variables, it must always set them back to the way they were before the routine began running. Many programmers write a set of generic functions that save the current settings at the beginning of the routine. After carrying out changes, restore the saved values at the end of the routine. Here's a code fragment that shows this: (setq splvar (getvar "splframe")) ... (setvar "splframe" splvar) Tip #5: Suppress That nil Any time you run an AutoLISP routine, there is that pesky "nil" appearing as the very last thing displayed. There is an actual reason for nil appearing, but the reason isn’t good enough for leaving it there. Here’s how to prevent that nil from appearing: end your routine with a (princ) all by itself. ○ ○ 170 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tip #6: Read-Write-Append File In (almost) all cases, AutoLISP doesn’t care if you use UPPERCASE or lowercase for writing the code. For legibility, there are some conventions, such as AutoLISP function names in all lowercase, your function names in Mixed Case, and AutoCAD variables and command names in all UPPERCASE. As I said, AutoLISP doesn’t care, and converts everything into uppercase in any case. It also strips out all comments, excess white space, tabs, and return characters. The exception is text in quote marks, such as prompts, is left as is. There are two exception where AutoLISP does care: when you are working with file functions and escape codes. The open function uses the arguments "r" "r", "w" "w", and "a" to read to, write from, and append to a file, respectively. Those three characters must be lowercase. Escape codes used in text strings must also remain lowercase. For example, \e is the escape character (equivalent to ASCII 27) and \t is the tab character. Note that they use backslashes; it is for this reason that you cannot use the backslash for separating folders names back in Tip #2. AutoLISP would think you were typing an escape code. Tip # 7: Quotation Marks as Quotation Marks As we have seen, AutoLISP uses quotation marks " and " for strings. Thus, you cannot use a quotation mark as for displaying quotation marks and inches, such as displaying 25 inches as 25". The workaround is to use the escape codes mentioned above in Tip #6, specifically the octal code equivalent for the ASCII character for the quotation mark. Sound complicated? It is. But all you need to know is 042. Here’s how it works. First, assign the strings to variables, as follows: (setq disttxt "The length is ") (setq distval 25) (setq qumark "\042") 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 ... Then concatenate the three strings together with the strcat function: (strcat distxt distval qumark) To produce the prompt: The length is 25" Tip # 8: Keep Variables to Six Characters To write the most efficient code, keep the variable names to a length of six characters or fewer. You may have notice that the variables I used above were all six characters or fewer. When you go above the six-character length, AutoLISP uses twice the space to hold the variable name. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 11 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ autolisp programming ○ ○ • ○ ○ ○ 171 Tip #9: Tabs and Quotation Marks Vijay Katkar is writing code for a dialog box with a list box. He told me, “I want to display strings in it — just like the dialog box displayed by the Layer command. I am able to concatenate the values and print the strings but there is no vertical alignment, since the strings are of different lengths. I tried using the tab metacharacter (\t) in the string but it prints the literal '\t' in the list box. Is there any way I can get around this problem?” I recall a similar problem: How to display quotation marks or the inches symbol within a text string? For example, I have a line of AutoLISP code that I want to print out as: The diameter is 2.54" 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.” Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 172 ○ ○ • ○ ○ ○ v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 twelve cad management tailoring AutoCAD 2004 i n this chapter, we look at customizing AutoCAD 2004 through the CAD management tools: • Create and check standards of linetypes, layers, dimension and text styles with the Standards and CheckStandards commands. rans commands (see Chapter 2). LayTrans • Control layers with the LMan and LayT alletes and DesignCenter windows. oolPalletes • Manage drawing elements with the ToolP ool P alettes tab of And we examine the innards of the XML-based .xtp file format, which is ex/imported by the T Tool Palettes the Customize dialog box. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 173 Table of Contents - Chapter 12 CAD Standards ~ 175 Tutorial: Create the Standards Drawing ~ 175 Linetype Standards ~ 175 Layer Standards ~ 176 Dimension Style Standards ~ 177 Text Style Standards ~ 177 Tutorial: Save the Standards Drawing ~ 178 Tutorial: Apply the Standards ~ 178 Tutorial: Check the Standards ~ 179 Employing Tool Palettes and DesignCenter ~ 180 DesignCenter ~ 180 Tool Palettes ~ 182 Tab Customization ~ 183 Icon Customization ~ 184 Palette Customization ~ 185 Titlebar Customization ~ 186 XTP File Format ~ 187 XML Metacharacters ~ 187 Tool Palettes XTP ~ 188 XTP Section 1: Header ~ 188 XTP Section 2: Tool Data ~ 189 XTP Section 3: Palette Data ~ 191 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 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. Contact [email protected] to purchase additional copies. Copyright © 2003 by upFront.eZine Publishing, Ltd. All rights reserved worldwide. ○ ○ 174 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 CAD Standards You can enforce drawing standards by applying AutoCAD’s Standards command. The steps to implement standards work are create, save, apply, and check: Step 1 – Create a drawing with the standards. Step 2 – Save the drawing as a .dws file. Step 3 – Apply the standards to working drawings. Step 4 – Check that working drawings conform to standards. Tutorial: Create the Standards Drawing 1. Start AutoCAD with a new drawing. 2. In the drawing, import linetypes, create layers, setup dimension styles, and specify text styles. (At this time, the only standards that AutoCAD checks are for linetypes, layers, dimension styles, and text styles.) TIP It is important that you load linetypes before creating layers. That way the linetypes are available for assigning to layers. Linetype Standards Use the Linetype command to load linetypes into the drawing: 1. From the menu bar, select Format | Linetype Linetype. 2. Click the Load button, and then select the linetypes you want part of the standards drawing. If necessary, click the File button to select a different .lin file. TIP You can select more than one linetype at a time: hold down the CTRL key as you pick them. Or, to select all linetypes, right-click and click on Select All. 3. Click OK twice. The linetypes are loaded in the drawing. See Chapter 6 for creating custom linetypes, both simple (1D) and complex (2D). ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 175 Layer Standards Use the Layer command to create layers. TIPS You can import layer names into a drawing using the LMan command provided with the Express Tools installation; see Chapter 2. For each layer, set the following properties: • On determines the initial visibility and plotability of the layer, on or off. When off, the layer is not displayed and is not plotted, overriding the setting of the Plot property (more below). Usual setting: on on. • Freeze in All VP VP: determines the “existence” of the layer, frozen or thawed in all viewports. When frozen, the layer is not displayed, plotted, hidden, rendered, or regenerated. Layer visibility for individual viewports is rent VP F reeze (more later). Usual setting: thaw Current Freeze thaw. controlled by the Cur • Lock determines whether the layer can be edited, locked or unlocked. Locked layers are displayed, but ed cannot be edited. Usual setting: unlock unlocked ed. • Color determines the color of all objects placed on the layer (a.k.a “ByLayer”). Color of individual objects White/black. can be overridden by the Change and Properties commands. Usual setting: White/black • Linetype determines the linetype of all objects placed on the layer. Linetype of individual objects can be overridden by the Change and Properties commands. Usual setting: Default Default. • Lineweight determines the line width of all objects placed on the layer (a.k.a “ByLayer”). Linetype of Continuous. individual objects can be overridden by the Change and Properties commands. Usual setting: Continuous • Plot Style determines the plot style applied to all objects on the layer (this property is unavailable when olicy is set to 1, color-dependent plot styles.) Usual setting: ByLayer system variable PStyleP PStylePolicy ByLayer. • Plot determines whether the layer is plotted, on or off. Usual setting: On On. Layers that are turned off or frozen also do not plot. roperties Manager When AutoCAD is in layout mode, the following options are also available in the Layer P Properties dialog box: rent VP F reeze freezes the layer in the current viewport, frozen or thawed. Frozen layers are not • Cur Current Freeze displayed and are not plotted. Usual setting: thawed thawed. reeze freezes the layer when a new viewport is created. Usual setting: thawed • New VP F Freeze thawed. roperties Manager dialog box, the settings are saved in the drawing. Once you close the Layer P Properties ○ ○ 176 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Dimension Style Standards Use the DimStyle command to create dimension standards. Or, borrow the dimension styles that Autodesk includes with its international template files: Template Group Dimension Style Name ANSI .dwt DIM .dwt Gb .dwt ISO .dwt JIS .dwt Standard (Autodesk’s default settings). DIN (German industrial standard). GB-5 (Chinese standard). ISO-25 (international organization of standards). JIS (Japanese industrial standard). TIPS Drawings can have more than one dimension style. To copy dimension styles from one drawing to another, use these Express Tools: DimEx exports selected dimension styles from the current drawing as .dim files. DimIn imports the .dim files into other drawings. Text Style Standards Use the Style command to create text standards. You can use any TrueType (.ttf) font in a drawing, as well as Autodesk’s own .shx fonts. You can use PostScript (.pfb) fonts after they have been converted to the .shx format ont F ile dialog box, click on Files of type, type and select “Postwith the Convert command (in the Select Shape or F Font File Script Fonts (*.pfb)”). Like linetypes, layers, and dimension styles, you easily copy text styles between drawings: 1. In AutoCAD, press CTRL+2 to open the DesignCenter DesignCenter. 2. In the Folder List, List go to the drawing from which you wish to copy text styles. 3. Open to the Text Styles item, and then drag the text style into the current drawing. AutoCAD notes, “Textstyle(s) added. Duplicate definitions will be ignored.” TIP You can use the DesignCenter to copy blocks, dimension styles, layers, layouts, linetypes, text styles, and xrefs from one drawing to another. CAD standards, however, checks only for linetypes, layers, dimension and text styles. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 177 Tutorial: Save the Standards Drawing With all the settings in the drawing, you can now save it as a standards drawing: 1. From the menu bar, select F ile | Save As File As. 2. In the Save Drawing As dialog box: • Click on the Files of type drop list, and then select “AutoCAD Drawing Standard (*.dws)”. • Enter a name in the File name text box. • In Save in in, select the drive and folder in which to save the standard drawing. 3. Click Save Save. AutoCAD saves the drawing in regular .dwg format, but gives it the .dws extension. Tutorial: Apply the Standards Now you need to attach the CAD standard to your working drawings: 1. Open a working drawing. 2. From the menu bar, select Tools | CAD Standards | Configure Configure. Notice the Configure Standards dialog box. 3. In the Standards tab, click the button with the blue + , the Add Standards F ile button (alternatively, press File F3 ile dialog box. F3). Notice the Select Standards F File 4. Select the .dws file you created earlier, and then click Open Open. TIP You can attach more than one .dws standards file to drawings. AutoCAD reads them in priority order, top to bottom in the list. Use the F4 and F5 keys to move drawings up and down the list. 5. If you wish, click the Plug-ins tab to view the standards that’ll be checked. With the standards loaded into the working drawing, you can go on to checking for standards violations. ○ ○ 178 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tutorial: Check the Standards To check whether a drawing violates CAD standards, do this: 1. From the menu bar, select Tools | CAD Standards | Check Check. Notice the Check Standards dialog box. 2. If problems are found, AutoCAD displays them — one at a time — in the dialog box. Click the Fix and Ne xt buttons to work your way through the violations. Next 3. When done, AutoCAD displays a summary screen: Even if you don’t run the Standards command, AutoCAD 2004 can check standards in the background, and alert you with a yellow balloon: TIP An alternative is to use the LayTrans command, which allows you to manually or automatically map layers from one drawing to another. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 179 Employing Tool Palettes and DesignCenter AutoCAD’s Tool Palettes and DesignCenter work together: Tool Palettes lets you easily place blocks (and drawings) and hatch patterns (and color fills) in the current drawing; DesignCenter provides access to content in other drawings and on the Internet. DesignCenter DesignCenter provides access to blocks, dimension styles (dimstyles), layers, layouts, linetypes, text styles, and xrefs located in other drawings. Curiously, hatch patterns are not supported, even though they were supported by the DesignCenter’s predecessor, called Content Explorer. You access DesignCenter by pressing CTRL+2. Once you locate content you wish to use, simply drag it from DesignCenter into your drawing. Access to content is provided in different by the four tabs along the top: • Folders provides access to content stored on your computer, and other computers connected via the local area network. TIP The Load button on DesignCenter’s toolbar allows you to open all kinds of nonCAD files, including many kinds of raster images, and AutoCAD .pat hatch pattern files. You can also drag these items into the drawing. Although the Load button appears to support IGES files, I could not drag them into the drawing. ○ ○ 180 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 • Open Drawings provides access to content in all the drawings currently open in AutoCAD. • Histor Historyy provides quick access to previously accessed files. • DC Center provides access to content located on Autodesk’s Web site. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 181 Tool Palettes In addition to dragging objects from DesignCenter into drawings, you can also drag them into the Tool Palette(s), new to AutoCAD 2004. (The name has a plural, even though it is a single window. I guess the “palettes” refers to the many tabbed parts to the window.) The purpose of the palettes is to provide a collection of often-used blocks and hatch/fill patterns. Instead of rummaging through the DesignCenter, the BHatch dialog box, and the Insert dialog boxes – all of which list all hatches and blocks available. (Use the object properties toolbar for access to line weights, linetypes, colors, text styles, dimension styles, and so on.) You turn on the tool palettes with Ctrl+3 Ctrl+3: You can perform the following dragging operations: • From DesignCenter into the drawing. • From DesignCenter into the tool palettes • From the tool palettes into the drawing. But, you cannot drag from the drawing into DesignCenter or the palettes; nor can you drag from the palettes into DesignCenter. Maybe next release of AutoCAD... The user interface is a bit too subtle for my liking; there are options hidden in shortcut menus all over the place. To customize the tool palettes: ○ ○ 182 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Tab Customization I don’t know if this is a bug or a feature, but I get three different shortcut menus, depending on which tab I rightclick. I recommend right-click the tab belonging to the current palette, because it displays the most options: • Move Up moves up the palette one position (available only for the second and lower tabs). • Move down moves down the palette by one position (available only for the second last and higher tabs). • View Options displays a dialog box that determines the size and look of icons and descriptive text: • Paste pastes data from the Clipboard into the palette. This option is available only if the Clipboard contains appropriate data, such as an AutoCAD block. Another bug or feature: I can copy a block in DesignCenter for pasting in the tool palette, but not from AutoCAD itself. ool P alette creates a new blank palette, and prompts you to name the tab: • New T Tool Palette ool P alette warns you against deleting it, and then does it when you answer OK. • Delete T Tool Palette ool P alette allows you to rename a tab. Palette • Rename T Tool ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 183 Icon Customization Right-click an icon (called “tools” by Autodesk) to get the following shortcut menu: • Cut removes the tool and places it in the Clipboard. (You can then right-click the palette, and select Paste aste.) • Copy copies the tool to the Clipboard. ool removes the tool. • Delete T Tool • Rename renames the tool. • Properties displays this dialog box for changing (most) of the properties: Shown above are the properties of hatches. Any property in white can be changed; those in gray cannot be changed. ○ ○ 184 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 Palette Customization Right-click anywhere on an unused area of the palette — not on an icon or a tab — to get the following shortcut menu: • Allow Docking toggles whether you want the tool palette to dock against the side of the AutoCAD window, should it get close enough. -Hide toggles whether the tool palette shrinks to just its title bar when the cursor leaves it. • Auto uto-Hide • Transparency displays the following dialog box for setting the “see thru-ness” of the tool palette: • View Options displays the same dialog box as does the tab shortcut menu. • Paste pastes a tool, if one has been copied or cut to the Clipboard. ool P alette adds a new blank palette. • New T Tool Palette ool P alette removes a palette. • Delete T Tool Palette ool P alette changes the name on the tab. Palette • Rename T Tool alettes dialog box: • Customize displays the Customize dialog box with the T Tool Palettes ool P ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 185 Tool palettes showing off its maximum transparency over DesignCenter: Titlebar Customization There is one more shortcut menu that comes up when you right-click the title bar — you actually customize the title bar: Most of the options are repeats from other shortcut menus, or else are self-evident. The one interesting option is: • Rename changes the name on the title bar from the default of “Tool Palette.” ool P alette option does not create a new window; instead, it simple adds Unlike what you might think, the New T Tool Palette another palette and tab to the existing window. ○ ○ 186 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 XTP File Format AutoCAD 2002 introduced a dialect of XML (extended markup language) called DesignXML. Autodesk “hid” the import and export in the Insert and WBlock commands; with AutoCAD 2004, the feature was removed. XML still, however, resides in minor areas of AutoCAD 2004. One example is shown in this section. To that you can share tool palettes with other users, AutoCAD exports the content of the Tool Palette in a variant of XML with an extension of .xtp, which could be an acronym of either “eXport Tool Palette” or “Xml-format Tool Palette.” To export the Tool Palette: from the menu bar, select Tools | Customize | T Tool Palettes alettes, and then click the ool P alettes Export button. Notice that AutoCAD prompts you to save the palette as an .xtp file. Use a text editor to view the file, which looks something like the code listed below. XML Metacharacters XML is a an easy format to read, and somewhat less easy to understand. It is easy to read because it is saved in human-readable ASCII format; it is somewhat self-documenting, although sometimes it takes some guessing to be clear on the meaning of a parameter. If you know HTML, on which XML is based, XML is a snap to understand. XML employs a bare minimum of metacharacters: • Tags identify data. The tag is a single word; notice the use of uppercase letters to make clearer compound words, such as DependentFilesPath. • Tags are surrounded by angle brackets; data is not: <DependentFilesPath> Space Plan </DependentFilesPath> Here, for example, <DependentFilesPath> is the name of the tag, while Space Plan is the data. • Data is often headed by a starting tag, and followed by an ending tag. The ending tag is identified by the slash character immediately following the opening angle bracket, as in <\DependentFilesPath>. • Sometimes data is stored inside tags. For example: <PropValue unspecified="TRUE" valueType="2" value="0"/> In this case, the tag has the slash character at the end, before the closing angle bracket. In the example above, three pieces of data are defined by the tag — unspecified, valueType, and value. Notice that data is always surrounded by quote marks, no matter if numbers or text. ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 187 Tool Palettes XTP The .xtp file format consists of three major sections: Section 1 – Header introduces the tool palette Section 2 – Tools Data defines the symbols stored in the tool palette. Section 3 – Palette Data defines the position and look of the tool palette. To make the .xtp format easier to read, I have indented tag sections, and have bold-faced the starting tag. The example code is based on the “Desk - 30 x 60 in.” block shown in the tool palette below. XTP Section 1: Header The header section identifies: • File type – ToolPaletteExport • Paths to related files – DependentFilesPath • Date and time of creation – Time <ToolPaletteExport> <DependentFilesPath> Space Plan </DependentFilesPath> <PaletteSets> <PaletteSetData> <PaletteSetContent> <Palettes> <PaletteData> <PaletteContent> <Palette> <ItemID idValue=”{184C56D6-62F7-42FB-9087-28BA130ABFA1}”/> <Properties> <ItemName> Space Plan </ItemName> <Images/> <Time createdUniversalDateTime=”2002-12-04T22:34:02" modifiedUniversalDateTime=”2002-12-04T22:34:02"/> </Properties> <Source/> <Tools> ○ ○ 188 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 XTP Section 2: Tool Data The tool data section describes each item in the palette, typically a block or hatch pattern. There is one <tool> </tool> section for each item. The item is defined by: • Name displayed on the tool palette, such as “Desk - 66 x 68 in.” – ItemName • Large and small icons in .png format – Image Image. • Time and date created – Time ime. Color, Layer Layer, Linetype Linetype, LinetypeScale LinetypeScale, PlotStyle PlotStyle, and Lineweight Lineweight. • General properties common to all objects – Color • Properties specific to objects – Block and Hatch (drawings are treated as blocks). <Tool> <ItemID idValue=”{67D3B8AB-7D80-4079-A230-B3760B71157D}”/> <Properties> <ItemName> Desk - 66 x 68 in. </ItemName> <Images> <Image cx=”32" cy=”32" src=”Images\DESK232.PNG”/> <Image cx=”64" cy=”64" src=”Images\DESK264.PNG”/> </Images> <Time createdUniversalDateTime=”2002-12-03T17:53:19" modifiedUniversalDateTime=”2002-12-03T17:53:19"/> </Properties> <Source idValue=”{DB288698-E6B7-4C26-9BB7-8881A36785F2}”/> <StockToolRef idValue=”{C9AB9290-FC5A-458B-AEB4-BDF9BE6A5E55}”/> <Data> <GeneralProperties> <Color> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”2" value=”2"/> </BasicPropInfo> </Color> <Layer> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”1"/> </BasicPropInfo> </Layer> <Linetype> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”1"/> </BasicPropInfo> </Linetype> <LinetypeScale> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”3" value=”1"/> </BasicPropInfo> </LinetypeScale> <PlotStyle> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”1"/> </BasicPropInfo> </PlotStyle> <LineWeight> <BasicPropInfo> <PropValue unspecified=”TRUE” valueType=”2" value=”0"/> </BasicPropInfo> </LineWeight> </GeneralProperties> ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 189 Blocks are defined by these tags: •BlockT BlockType BlockT ype (value always seems to be 1). •Name of the block – BlockName. ile. •Path to the .dwg source file in which the block is stored – SourceF SourceFile. •Scale of the block, where 1 means unscaled – Scale. •Rotation angle of the block, where 0 means unrotated – Rotation. •And whether the block is exploded, which 0 means unexploded – Explode Explode. <Block> <BlockType> 1 </BlockType> <BlockName> DESK2 </BlockName> <SourceFile> d:\foldername\NewFeaturesWorkshop\Sample\Office Space Plan.dwg </SourceFile> <Scale> 1 </Scale> <Rotation> 0 </Rotation> <Explode> 0 </Explode> </Block> Hatches are defined by these tags: ype (value always seems to be 1). • HatchT HatchType • Name of the hatch – PatternName (user-defined hatches are named “_U”). • Path to the .pat source file in which the pattern is defined – SourceF ile. SourceFile. • Angle of the pattern, where 0 means unrotated – Angle. • Scale of the pattern, where 1 means unscaled – Scale. • Spacing between lines of user-defined hatch patterns – Spacing Spacing. • Penwidth of lines for ISO hatch patterns, where 100 = 1.00mm – P enW idth PenW enWidth idth. • Whether the pattern is repeated at a 90-degree angle to create a cross-hatch – Double Double. • BlockExtent (?). ○ ○ 190 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003 <Hatch> <HatchType> 1 </HatchType> <PatternName> BRICK </PatternName> <SourceFile> %ProgramName%iso.pat </SourceFile> <Angle> 0 </Angle> <Scale> 1 </Scale> <Spacing> 1 </Spacing> <PenWidth> 100 </PenWidth> <Double> 0 </Double> <BlockExtent> 1 </BlockExtent> </Hatch> XTP Section 3: Palette Data The PaletteUI (user interface) section describes the tool palette itself: • Style of palette (value seems to have no effect, perhaps reserved dUiP alette for future use) – CA CAdUiP dUiPalette alette. • Size of the preview image, either 32 or 64 pixels – Image. • Style (perhaps a bitcode).. • Order in which the tool palettes appear – ToolOrder oolOrder.. dUiDockControlBar • Whether the palette is allowed to dock – CA CAdUiDockControlBar dUiDockControlBar.. • The position of a floating palette – FloatInfo. • The position of a docked palette – DockInfo . dUiP aletteSet. • Properties of the palette – CA CAdUiP dUiPaletteSet. </Data> </Tool> </Palette> </PaletteContent> <PaletteUI> <CAdUiPalette PaletteStyle=”1"/> <CAcTcUiToolPalette> <CatalogView ID=”{184C56D6-62F7-42FB-9087-28BA130ABFA1}”> <ToolSource> <Palette ID=”{184C56D6-62F7-42FB-9087-28BA130ABFA1}”> Space Plan </Palette> </ToolSource> <Image SizeCX=”32" SizeCY=”32"/> ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ tailoring AutoCAD 2004 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ chapter 12 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ cad management • 191 <Style> 491522 </Style> <ToolOrder> <Tool ID=”{1541B604-B9D1-4D56-A755-8BF1EF921A9A}”/> <Tool ID=”{67D3B8AB-7D80-4079-A230-B3760B71157D}”/> <Tool ID=”{B8E8FDCD-E0FB-4BDD-9D46-1EFEFE0C1055}”/> <Tool ID=”{D757A727-53A1-4532-A4A5-D7F4AB5F9362}”/> <Tool ID=”{F18F7848-0358-4CDE-B666-7419335215FF}”/> <Tool ID=”{97C2916C-E0E5-4DE0-90DD-92F83BEF2C80}”/> <Tool ID=”{32F72D23-80D9-4819-B1E7-B4D14C230D46}”/> </ToolOrder> </CatalogView> </CAcTcUiToolPalette> </PaletteUI> </PaletteData> </Palettes> </PaletteSetContent> <PaletteSetUI> <CAdUiDockControlBar Orientation=”-1" AllowDocking=”1"> <FloatInfo Left=”49" Top=”96" Width=”231" Height=”493"/> <DockInfo Left=”6120" Top=”576" Width=”262" Height=”552"MRUDockID=”59421"/> </CAdUiDockControlBar> <CAdUiPaletteSet ActivePaletteIndex=”2" TitleBarLocation=”0" AuoRollup=”0" Name=”Tool Palettes” Style=”126" Opacity=”100" Visible=”1"/> </PaletteSetUI> </PaletteSetData> </PaletteSets> </ToolPaletteExport> Feedback I welcome your feedback for correcting and improving the text. Send your email to [email protected] . Visit the Tailoring AutoCAD 2004 e-book Web site at www.upfrontezine.com/tailor2004. For other CAD e-books, visit the eBooks.onLine Web site at www.upfrontezine.com/ebooks. ○ ○ 192 ○ ○ ○ ○ ○ • v2.0 ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ 1 may 2003