Acknowledgments
I have to give a very special thanks to all the great folks at Sybex, especially Willem Knibbe, for working on and helping to get this project off the ground after a few years of talking about it. The next two people I would like to thank are Mary Ellen Schutz and Dassi Zeidel, the development and production editors on this book; you two made sure I stayed on track and delivered a high-quality book. I also want to thank Liz Welch (copyeditor), Candace Cunningham (proofreader), and Ted Laux (indexer) for the work you all did on this book.
Thanks to all the folks at Autodesk, who put in the long hours and are dedicated to the work they do on the Autodesk® AutoCAD® product. I cannot forget some of the most important individuals on this book, my technical editors: Rebecca Afshar, Craig Black, and Richard Lawrence. Rebecca Afshar performed the technical edit for Part I, “AutoCAD Platform Customization: User Interface and Beyond.” Rebecca has spent many years as both an instructor and user of AutoCAD; all of this experience helped to make this book even better.
Craig Black performed the technical edit for Part II, “AutoCAD Platform Customization: AutoLISP. ” I have known Craig for nearly 20 years and first met him while attending an AutoLISP® session at the local Autodesk Training Center, where he was an instructor. Craig is a excellent AutoLISP programmer and was a great asset as a technical editor on this book. It is always a pleasure to collaborate with Craig and this book was no different.
Last but not least, Richard Lawrence performed the technical edit for Part III, “AutoCAD Platform Customization: VBA.” Richard is a great friend who I met many years ago at Autodesk University. He is a passionate and driven user of AutoCAD and is always looking to improve the way he uses AutoCAD. Being a technical editor is never the easiest job, but it is one of the most important and I appreciate what you all did to make this book better.
About the Author
Lee Ambrosius first started working with AutoCAD R12 for DOS in 1994. As a drafter, he quickly discovered that every project included lots of repetition. Lee, not being one to just settle for “this is just the way things are,” set out on a path that would redefine his career. This new path would lead him into the wondrous world of customization and programming which you might catch him referring to as “the rabbit hole.”
In 1996, Lee began learning the core concepts of customizing the AutoCAD user interface and AutoLISP. The introduction of VBA in AutoCAD R14 would once again redefine how Lee approached programming solutions for AutoCAD. VBA made it much easier to communicate with external databases and other applications that supported VBA. It transformed the way information could be moved between project management and manufacturing systems.
Not being content with VBA, in 1999 Lee attended his first Autodesk University and began to learn ObjectARX®. Autodesk University had a lasting impression on him. In 2001, he started helping as a lab assistant. He began presenting on customizing and programming AutoCAD at the event in 2004. Along the way he learned how to use the AutoCAD Managed.NET API.
In 2005, Lee decided cubicle life was no longer for him, so he ventured off into the CAD industry as an independent consultant and programmer with his own company, HyperPics, LLC. After he spent a couple of years as a consultant, Autodesk invited him to work on the AutoCAD team; he has been on the AutoCAD team since 2007. For most of his career at Autodesk, Lee has worked primarily on the customization and end-user documentation. Recently, he has been working on the AutoLISP, VBA, ObjectARX,.NET, and JavaScript programming documentation.
In addition to working on documentation, Lee has been involved as a technical editor or author for various editions of AutoCAD and AutoCAD LT Bible, AutoCAD for Dummies, AutoCAD & AutoCAD LT All-in-One Desk Reference for Dummies, AutoCAD 3D Modeling Workbook for Dummies, and Mastering AutoCAD for Mac. He has also written white papers on customization for Autodesk and a variety of articles on customization and programming for AUGIWorld, published by AUGI®.
Introduction
Welcome to AutoCAD Platform Customization: User Interface, AutoLISP, VBA, and Beyond. Have you ever thought about customizing AutoCAD only to think it is not for you because you’re not a programmer? If so, you are not alone, as there are many people that connect customization with programming. However, customization is not the same as programming, but programming can be considered a form of customization.
While using one of the supported programming languages can be useful in implementing custom workflows and new commands, there are many simpler ways to increase your drafting efficiency in a shorter period of time. AutoCAD supports a wide range of customization features that you can learn and begin to leverage in minutes, which can led to improved CAD standards and a decrease in the amount of time it takes to complete a task.
I, like many others, even yourself most likely, have customized AutoCAD without even realizing it. Have you ever created a new layer, text style, or block? Chances are pretty great that you have created one or more of those items before. You might have even stored those items in a drawing template (DWT) file so they would be available each time a new drawing was created. While you might not have thought about these as forms of customization, they are indeed a few of the basic drawing customization features that can be used to enhance the out-of-box AutoCAD experience.
Drawing customization affects the appearance of and settings in a drawing file or drawing template (DWT) file, and should form the cornerstone of your company’s CAD standards. Often when people think of customization though, they commonly think of application customization, which contains the support files that AutoCAD uses as well as the tools in the application’s user interface. Application customization is not dependent on which drawing is currently open, but which user profile or workspace might be current.
About This Book
The AutoCAD Platform Customization: User Interface, AutoLISP, VBA, and Beyond book covers many of the customization and programming features that can be found in AutoCAD on Windows and Mac OS X. This book covers most of the customization features available along with two of the easier to learn programming languages that AutoCAD supports. If any of the following are true, this book will be useful to you:
- Want to learn about which customization and programming options are available in AutoCAD.
- Want to customize the user interface or support files, such as linetypes and hatch patterns, that AutoCAD utilizes.
- Want to automate repetitive tasks.
- Want to create and manage CAD standards for your company.
- Want to learn how to create custom programs with AutoLISP or Visual Basic for Applications (VBA).
Table of Contents
- Chapter 1: Establishing the Foundation for Drawing Standards Naming Standards for Projects and Files Managing Standards with Drawing Templates Choosing a File Format for Your Drawings Defining Plotter Configurations and Plot Styles Enforcing CAD Standards
- Chapter 2: Working with Nongraphical Objects Standardizing the Names of Nongraphical Objects Managing Object Properties with Layers Creating and Managing Annotation Styles Defining and Managing Other Nongraphical Objects Removing Unused Nongraphical Objects
- Chapter 3: Building the Real World One Block at a Time Defining and Editing a Block Definition Using and Managing Block Definitions Embedding Information in a Block Definition with Attributes Adding Dynamic Properties to a Block Definition Extracting Properties and Values from a Block Reference
- Chapter 4: Manipulating the Drawing Environment Getting Started with Drawing Environment Customization Customizing the AutoCAD Startup Process Specifying Application Preferences Customizing the Elements in the Drawing Window Configuring Command and Dynamic Input Creating and Modifying Command Aliases Working with System and Environment Variables
- Chapter 5: Customizing the AutoCAD User Interface for Windows Getting Started with the CUI Editor Creating Commands and Defining Command Macros Customizing User-Interface Elements Setting Up Rollover Tooltips and the Quick Properties Palette Organizing the User Interface with Workspaces Working with Customization Files Controlling the Tools on the Status Bars
- Chapter 6: Customizing the AutoCAD User Interface for Mac Getting Started with the Customize Dialog Box Creating Commands and Defining Command Macros Customizing User-Interface Elements Controlling the Tools on the Status Bar
- Chapter 7: Creating Tools and Tool Palettes What Is a Tool Palette? Using the Tool Palettes Window Defining Tool Palettes Adding and Modifying Tools Organizing Tool Palettes with Tool-Palette Groups Sharing Tool Palettes and ToolPalette Groups
- Chapter 8: Automating Repetitive Tasks Creating and Running Scripts Recording Action Macros (Windows Only)
- Chapter 9: Defining Shapes, Linetypes, and Hatch Patterns Creating and Compiling Shapes Creating and Using Custom Linetypes Creating and Applying Custom Hatch Patterns
- Chapter 10: Using, Loading, and Managing Custom Files Deploying Your Custom Files Using and Loading Custom Programs Backing Up and Migrating Customization
- Chapter 11: Quick Start for New AutoLISP Programmers Working with AutoLISP Expressions Storing and Loading AutoLISP Expressions
- Chapter 12: Understanding AutoLISP Getting Started with AutoLISP Storing and Retrieving Values Exploring Data Types Leveraging AutoCAD and Third-Party Commands Defining and Using Custom Functions Example: Drawing a Rectangle
- Chapter 13: Calculating and Working with Values Calculating Values with Math Functions Manipulating Strings Converting Data Types Returning a Value from a Custom Function Exercise: Drawing a Rectangle (Revisited)
- Chapter 14: Working with Lists What Are Lists? Creating a List Getting an Element from a List Appending, Substituting, and Removing Elements Determining Whether an Item Exists in a List Sorting the Elements of a List Using Point Lists to Calculate Geometric Values Converting Lists to Strings and Strings to Lists Exercise: Adding Holes to the Plate
- Chapter 15: Requesting Input and Using Conditional and Looping Expressions
- Interacting with the User Conditionalizing and Branching Expressions Repeating and Looping Expressions Exercise: Getting Input from the User to Draw the Plate
- Chapter 16: Creating and Modifying Graphical Objects Working with Entity Names and Dotted Pairs Adding Objects to a Drawing