- •Introduction
- •Who should read this book
- •How This Book Is Organized
- •How to Use This Book
- •Where to Find the LISP Programs
- •CHAPTER 1: Introducing AutoLISP
- •Understanding the Interpreter and Evaluation
- •The Components of an Expression
- •Using Arguments and Expressions
- •Using Variables
- •Understanding Data Types
- •Integers and Real Numbers
- •Strings
- •Lists
- •File Descriptors
- •Object Names
- •Selection Sets
- •Symbols
- •Subrs
- •Atoms
- •Assigning Values to Variables with Setq
- •Preventing Evaluation of Arguments
- •Applying Variables
- •Functions for Assigning Values to Variables
- •Adding Prompts
- •CHAPTER 2: Storing and Running Programs
- •Creating an AutoLISP Program
- •What you Need
- •Creating an AutoLISP File
- •Loading an AutoLISP file
- •Running a Loaded Program
- •Understanding How a Program Works
- •Using AutoCAD Commands in AutoLISP
- •How to Create a Program
- •Local and Global Variables
- •Automatic Loading of Programs
- •Managing Large Acad.lsp files
- •Using AutoLISP in a Menu
- •Using Script Files
- •CHAPTER 3: Organizing a Program
- •Looking at a Programs Design
- •Outlining Your Programming Project
- •Using Functions
- •Adding a Function
- •Reusing Functions
- •Creating an 3D Box program
- •Creating a 3D Wedge Program
- •Making Your Code More Readable
- •Using Prettyprint
- •Using Comments
- •Using Capitals and Lower Case Letters
- •Dynamic Scoping
- •CHAPTER 4: Interacting with the Drawing Editor
- •A Sample Program Using Getdist
- •How to Get Angle Values
- •Using Getangle and Getorient
- •How to Get Text Input
- •Using Getstring
- •Using Getkword
- •How to Get Numeric Values
- •Using Getreal and Getint
- •How to Control User Input
- •Using Initget
- •Prompting for Dissimilar Variable Types
- •Using Multiple Keywords
- •How to Select Groups of Objects
- •Using Ssget
- •A Sample Program Using Ssget
- •CHAPTER 5: Making Decisions with AutoLISP
- •Making Decisions
- •How to Test for Conditions
- •Using the If function
- •How to Make Several Expressions Act like One
- •How to Test Multiple Conditions
- •Using the Cond function
- •How to Repeat parts of a Program
- •Using the While Function
- •Using the Repeat Function
- •Using Test Expressions
- •CHAPTER 6: Working With Geometry
- •How to find Angles and Distances
- •Understanding the Angle, Distance, and Polar Functions
- •Using Trigonometry to Solve a Problem
- •Gathering Information
- •Finding Points Using Trigonometry
- •Functions Useful in Geometric Transformations
- •Trans
- •Atan
- •Inters
- •CHAPTER 7: Working with Text
- •Working With String Data Types
- •Searching for Strings
- •Converting a Number to a String
- •How to read ASCII text files
- •Using a File Import Program
- •Writing ASCII Files to Disk
- •Using a Text Export Program
- •CHAPTER 8: Interacting with AutoLISP
- •Reading and Writing to the Screen
- •Reading the Cursor Dynamically
- •Writing Text to the Status and Menu Areas
- •Calling Menus from AutoLISP
- •Drawing Temporary Images on the Drawing Area
- •Using Defaults in a Program
- •Adding Default Responses to your Program
- •Dealing with Aborted Functions
- •Using the *error* Function
- •Organizing Code to Reduce Errors
- •Debugging Programs
- •Common Programming Errors
- •Using Variables as Debugging Tools
- •CHAPTER 9: Using Lists to store data
- •Getting Data from a List
- •Using Simple Lists for Data Storage
- •Evaluating Data from an Entire List at Once
- •Using Complex Lists to Store Data
- •Using Lists for Comparisons
- •Locating Elements in a List
- •Searching Through Lists
- •Finding the Properties of AutoCAD Objects
- •Using Selection Sets and Object Names
- •Understanding the structure of Property Lists
- •Changing the properties of AutoCAD objects
- •Getting an Object Name and Coordinate Together
- •CHAPTER 10: Editing AutoCAD objects
- •Editing Multiple objects
- •Improving Processing Speed
- •Using Cmdecho to Speed up Your Program
- •Improving Speed Through Direct Database Access
- •Filtering Objects for Specific Properties
- •Filtering a Selection Set
- •Selecting Objects Based on Properties
- •Accessing AutoCAD's System Tables
- •CHAPTER 11: Accessing Complex Objects
- •Accessing Polyline Vertices
- •Defining a New Polyline
- •Drawing the new Polyline
- •Testing for Polyline Types
- •How Arcs are Described in Polylines
- •Accessing Object Handles and Block Attributes
- •Using Object Handles
- •Using Object Handles
- •Extracting Attribute Data
- •Appendix A: Menu Primer
- •Appendix B: Error Messages
- •Appendix C: Group Codes
The ABC’s of AutoLISP by George Omura
Appendix A: Menu Primer
You can find comprehensive information on AutoCAD Menus in the AutoCAD help system. Here are instructions for finding the section devoted to Menus.
1.In AutoCAD, choose Help > Developer Help from the menubar
2.Click on the Contents tab in the Help Topics dialog box, then expand the Customization Guide listing
3.Expand the Custom Menus listing. You will see the list of topics. Click on the topic of your choice. You can also refer to Chapter 29 of Mastering AutoCAD for tutorials on menu customization.
259
Copyright © 2001 George Omura,,World rights reserved
The ABC’s of AutoLISP by George Omura
Appendix B: Error Messages
Error codes have been completely retooled in AutoCAD 2002. AutoCAD 2002 now offers Visual LISP which is a programming environment designed for AutoLISP. There, you'll find an environment that helps you find errors quickly, You can open Visual LISP by choosing Tools > AutoLISP > Visual LISP Editor. The Visual LISP Editor offers many of the tools you expect to find in a modern programming environment.
A discussion of Visual LISP is not currently available in this document. You can find a tutorial and reference guide built into Visual LISP by choosing Help > Developer List. Click on the Contents tab to see a listing of topics including Visual LISP Developer’s Guide and Visual LISP Tutorial.
Visual LISP is an advanced tool that expects the user to have a working knowledge of AutoLISP. You may want to work with the ABC's of AutoLISP until you feel comfortable with AutoLISP.
260
Copyright © 2001 George Omura,,World rights reserved
The ABC’s of AutoLISP by George Omura
Appendix C: Group Codes
You can find a comprehensive listing of group codes in the AutoCAD help system. Here are instructions for finding the group codes.
1.In AutoCAD, choose Help > Developer Help from the menubar
2.Click on the Contents tab of the Help Topics dialog box, then expand the DXF Reference listing
You can then expand the other options under DXF Reference for group codes pertaining to the selected topic.
261
Copyright © 2001 George Omura,,World rights reserved
The ABC’s of AutoLISP by George Omura
Appendix D: System and Dimension
Variables
You can find a comprehensive listing of dimension variables in the AutoCAD help system. Here are instructions for finding the dimension variables information.
1.In AutoCAD, choose Help > Help from the menubar
2.Click on the Contents tab in the Help dialog box then expand the Command Reference listing
3.Expand the System Variables listing
You will see a listing of system variables with a brief description to the right. You can click on the system variable name to get a more detailed description.
262
Copyright © 2001 George Omura,,World rights reserved
The ABC’s of AutoLISP by George Omura
263
Copyright © 2001 George Omura,,World rights reserved