59070_8101_CHFM
Transcript of 59070_8101_CHFM
Introduction 1
AutoCAD®
2007 Visual LISP Programming
Visual LISP Programming
Principles and TechniquesPrinciples and Techniquesby
Rod R. RawlsCAD Administrator
Isothermal Systems Research, Inc.Liberty Lake, Washington
Mark A. HagenInstructor
Portland Community CollegePortland, Oregon
Paul F. RichardInstructor
Autodesk Premier Training CenterClackamas Community College
Portland, Oregon
Publisher
The Goodheart-Willcox Company, Inc.Tinley Park, Illinois
www.g-w.com2 Visual LISP Programming
Copyright © 2007
by
The Goodheart-Willcox Company, Inc.
All rights reserved. No part of this work may be reproduced, stored, or transmitted in any form or by any electronic or mechanical means including information storage and retrieval systems, without the prior
written permission of The Goodheart-Willcox Company, Inc.
Manufactured in the United States of America.
ISBN 978-1-59070-810-1
1 2 3 4 5 6 7 8 9 – 07 – 12 11 10 09 08 07
The Goodheart-Willcox Company, Inc., Brand Disclaimer: Brand names, company names, and illustrations for products and services included in this text are provided for educational purposes only, and do not represent or imply endorsement or recommendation by the author or the publisher.
The Goodheart-Willcox Company, Inc., Safety Notice: The reader is expressly advised to carefully read, understand, and apply all safety precau-tions and warnings described in this book or that might also be indicated in undertaking the activities and exercises described herein to minimize risk of personal injury or injury to others. Common sense and good judgment should also be exercised and applied to help avoid all potential hazards. The reader should always refer to the appropriate manufacturer’s technical information, directions, and recommendations; then proceed with care to follow specifi c equipment operating instructions. The reader should understand these notices and cautions are not exhaustive.
The publisher makes no warranty or representation whatsoever, either expressed or implied, including but not limited to equipment, procedures, and applications described or referred to herein, their quality, performance, merchantability, or fi tness for a particular purpose. The publisher assumes no responsibility for any changes, errors, or omissions in this book. The publisher specifi cally disclaims any liability whatsoever, including any direct, indirect, incidental, consequential, special, or exemplary damages resulting, in whole or in part, from the reader’s use or reliance upon the information, instructions, procedures, warnings, cautions, applications or other matter contained in this book. The publisher assumes no responsibility for the activities of the reader.
Library of Congress Cataloging-in-Publication
Rawis, Rod R.Visual LISP programming: principles and techniques / by Rod R. Rawls, Mark A. Hagen,
Paul F. Richard. p. cm. Includes index. ISBN 978-1-59070-810-1 1. AutoLISP (Computer program language)I. Hagen, Mark A. II. Title.
This sample chapter is for review purposes only. Copyright © The Goodheart-Willcox Co., Inc. All rights reserved.
Introduction 3
Visual LISP Programming provides practical and easy-to-follow instruction in mastering the AutoLISP programming language. A step-by-step approach is followed throughout the text to allow progressive learning, ranging from basic to advanced programming techniques. Many examples of AutoLISP applications are incorporated into this text to provide instruction both in learning the language and using it productively in a work environment.
You do not need to be an expert in AutoCAD to use this text. However, a basic under-standing is assumed. No previous knowledge of AutoLISP or any other programming language is required. Visual LISP Programming:
• Begins at a level that can be understood by a novice AutoCAD user.
• Progresses in a step-by-step manner describing how to create useful and productive routines and programs with AutoLISP.
• Provides professional tips that offer information, insights, and guidelines on effective and effi cient programming techniques.
• Includes exercises in the chapters to reinforce the topics covered.
• Is designed to give you a strong understanding of how AutoLISP works and how to build your skills in designing, writing, and debugging programs.
• Includes chapter tests and end-of-chapter problems that allow you to apply functions and key AutoLISP concepts.
AutoLISP and Visual LISP are versions of a widely used programming language known as LISP. LISP is an acronym for list processing. AutoLISP is used within AutoCAD and has a tool set that includes many functions specifi cally designed for use in AutoCAD’s graphic environment. Understanding AutoLISP will provide you with the knowledge to develop programs and functions that optimize your productivity.
One of the most fascinating things about AutoLISP is that you do not need to be an experienced programmer to master its use. In fact, AutoLISP is among the easiest of all programming languages to learn. Since this language works within AutoCAD, a good understanding of AutoCAD will provide you with a distinct advantage in learning to use AutoLISP.
Introduction
4 Visual LISP Programming
Many repetitive tasks can be handled by menu macros, which string individual commands one after another. However, this approach is merely accelerated command entry and may not be suitable for custom applications. On the other hand, AutoLISP can test for required circumstances and vary results accordingly, reset system vari-ables, access and use AutoCAD entity defi nition data, and even request user input to determine how to perform a given task.
Another common use for AutoLISP routines is to reduce your most frequently used command sequences to one or two keystrokes. For example, instead of typing OFFSET, you could defi ne a command named O that invokes the OFFSET command within AutoCAD. In addition, macro style routines can be defi ned to walk through several prompts within a single command or even process multiple commands. This can minimize the number of keystrokes as well as keyboard entry errors, thus reducing duplication of effort and increasing productivity.
Fonts Used in This Text
Different typefaces are used throughout each chapter to defi ne terms, identify AutoCAD commands, and identify AutoLISP functions. AutoLISP functions are printed in bold-face, sans serif type and are placed inside of parentheses within the text. Variables appear within the body of the text in UPPERCASE, SANS SERIF type. Important terms (defi ned terms) appear in bold-italic face, serif type.
Code examples are set off from the body of the text. These are clearly identifi ed by the vertical bar shown here. All type in code examples is Roman, sans serif. Code examples also appear with the correct indents and line spacing, as accepted by programming conventions.
AutoCAD menus, commands, variables, dialog box names, and toolbar button names are printed in bold-face, sans serif type. File names, folder names, paths, and keyboard-entry items appear in the body of the text in Roman, sans serif type. Keyboard keys are shown inside of [square brackets] and appear in Roman, sans serif type. For example, [Enter] means to press the enter (return) key.
Textbook Features
There are a variety of features in Visual LISP Programming designed to help you learn AutoLISP programming. These include professional tips, notes, cautions, and review sections that help you develop your AutoCAD and AutoLISP skills.
PROFESSIONAL TIP
A professional tip is designed to provide tips, ideas, and suggestions that will improve your productivity and streamline your code.
When AutoCAD is configured to display a screen menu, the commands appear in a separate screen.
Introduction 5
Note
A note alerts you to important aspects of a command, function, menu, or activity that is being discussed. These aspects should be kept in mind while you are working through the text.
Caution
A caution alerts you to potential problems or errors that may be introduced into your code. A caution may also point out a programming practice that should be avoided.
• The Let’s Review… feature provides a quick reference to the material just presented.
• Each chapter may have multiple Let’s Review… sections throughout the chapter.
• Each Let’s Review… section is presented as a bulleted list, as shown here, for quick review.
Student CD
Included with this text is a Student CD that contains the appendix material. In addition, the chapter tests are available on the Student CD in either PDF or DOC format. When you insert the Student CD into your CD drive, the menu is automatically launched. If your CD drive is not set up to autoplay, you will need to manually launch the menu program. The menu interface is similar to a web page. Use the buttons to navigate through the menu and activate the feature you want to view.
Measuring Progress
Visual LISP Programming provides three ways for you to evaluate your progress in learning VBA:
• Exercises. Most chapters contain in-text exercises. These exercises allow you to perform tasks that reinforce the material just presented. You can work through the exercises at your own pace, but you should complete each exercise before moving on to the next topic.
• Chapter Test. Each chapter includes a written test at the end of the chapter. Ques-tions require you to give the proper defi nition, object, method, property, or option.
• Programming Problems. There are a variety of problems at the end of each chapter. These are presented as real-world applications for which you must develop AutoLISP programs or provide information related to an AutoLISP application. The problems are designed to make you think, solve problems, use proper programming techniques, research AutoLISP using the online docu-mentation, and produce a correctly functioning, user-friendly program that contains appropriate error correction.
Let’sReview…Let’sReview…
6 Visual LISP Programming
About the Authors
Rod Rawls is the CAD Administrator for the commercial division of Isothermal Systems Research, Inc. ISR is the developer of SprayCool™ advanced thermal manage-ment technology for consumer electronics. Prior to joining the team at ISR, Rod served for sixteen years as an Autodesk Certifi ed Instructor in the Autodesk Premier Training Center at Clackamas Community College in Oregon City, Oregon. Rod taught basic through advanced AutoCAD classes, including AutoCAD menu design and AutoLISP programming. During this time, Rod also provided contract programming, devel-opment, and instructional services for CAD departments throughout the Pacifi c Northwest. His expertise in writing Visual LISP Programming draws directly from his professional programming experience combined with extensive classroom experience in teaching AutoLISP.
Mark Hagen is currently an instructor in the Drafting Technology Department at Portland Community College. He teaches a wide variety of AutoCAD-related courses including beginning, intermediate, and advanced courses, as well as AutoLISP programming courses.
Prior to working at Portland Community College, Mark worked as an Applications Consultant for KETIV Technologies, Inc., in Portland, Oregon. His responsibilities at KETIV included serving as an AutoCAD trainer\programmer\consultant for a large Pacifi c Northwest AutoCAD dealer and CAD\CAM\CAE company.
Mark also has extensive experience in the drafting and design fi eld. Before working for KETIV, Mark worked as a CAD Specialist for the Silver Eagle Manufacturing Company. His responsibilities primarily dealt with the design and drafting of steel fabrication weldments and assemblies.
Mark has an Applied Arts and Sciences degree in Engineering Technology from Clark College in Vancouver, Washington. In addition, he has a Bachelor of Arts degree in Sciences and Humanities from Iowa State University. Mark is also certifi ed in geometric dimensioning and tolerancing applications.
Paul Richard is an instructor at the Autodesk Premier Training Center at Clackamas Community College in Portland, Oregon, where he teaches AutoCAD, AutoCAD customization, AutoLISP programming, and VBA programming. He is the author of VBA for AutoCAD. Paul started his career as a CAD drafter in 1985 and has since held positions as CAD designer, CAD manager, CAD software developer, and, most recently, certifi ed Autodesk instructor and author. Paul has been a registered Autodesk devel-oper since 1996 and was a speaker at Autodesk University in 2002 where he presented the tutorial Zen and the Art of VBA Programming. When not teaching or writing code, Paul likes to ride and work on motorcycles.
Introduction 7
Chapter 1Fundamentals of AutoLISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Chapter 2AutoLISP Program Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Chapter 3List Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
Chapter 4Requesting User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Chapter 5Identifying Distances and Angles . . . . . . . . . . . . . . . . . . . . . . .87
Chapter 6Advanced Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Chapter 7Conversions and String Manipulations . . . . . . . . . . . . . . . . . 117
Chapter 8Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Chapter 9Looping Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Brief Table of Contents
8 Visual LISP Programming
Chapter 10Advanced List Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Chapter 11Entity Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Chapter 12Selection Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Chapter 13Entity-Manipulation Techniques . . . . . . . . . . . . . . . . . . . . . . .227
Chapter 14File Handling and Environmental Variables . . . . . . . . . . . . . .257
Chapter 15Symbol Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .271
Chapter 16Graphics Screen and Input Device Functions . . . . . . . . . . . . 311
Chapter 17Programmable Dialog Boxes. . . . . . . . . . . . . . . . . . . . . . . . . .321
Chapter 18Programmable Dialog Box Functions. . . . . . . . . . . . . . . . . . .355
Chapter 19Programming and Debugging Techniques. . . . . . . . . . . . . . .395
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419
Introduction 9
Chapter 1Fundamentals of AutoLISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Building an AutoLISP Expression. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15Entering an Expression for Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17Possible Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
The + Function, The – Function, The * Function, The / Function
Solving Complex Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .21AutoLISP Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Setting Variables, Returned Values, Setting Multiple Variables, Using Variables, Using Variables on the Command Line
Rules and Hints for Variable Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .27Visual LISP Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .28
Chapter 2AutoLISP Program Files. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Introduction to AutoLISP Program Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .31Creating a Program File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .32
Visual LISP Editor, Parentheses, AutoLISP File Format, Quotation Marks
Writing Your First AutoLISP Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36Using an AutoLISP File. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .37
Loading from the AutoCAD Command Line, Loading from the Load/Unload Applications Dialog Box, Displaying a Variable Value
Importance of Documentation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42Defi ning Custom Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Getting User Input, Using Data Storage Lists, Getpoint Arguments, Printing Messages to the Screen, Using AutoCAD Commands in AutoLISP, Other Command Examples, Putting It All Together, Defi ning New Functions, Defi ning New AutoCAD Commands
Expanded Table of Contents
10 Visual LISP Programming
Chapter 3List Processing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59
Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .59Creating Lists, Point Coordinate Lists
Basic List Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .62Car Function, Cdr Function
Linking the Car and Cdr Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .65Cadr Function, Caddr Function, Other Cxxxxr Combinations
Getcorner Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69Additional Basic List Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
Last Function, Length Function
Chapter 4Requesting User Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73
Requesting Data. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .73Requesting Numerical Input, Requesting Text Strings, Non-Nil Arguments, Controlling Numerical and Text Input, Initget and Getkword Functions
AutoLISP and System Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81Color Selection Dialog Box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .83
Chapter 5Identifying Distances and Angles . . . . . . . . . . . . . . . . . . . . . . .87
AutoCAD Inquiry Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .87Pi and AutoLISP Angles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .88
Cvunit Function; Angle Function; Distance Function; Polar Function; Combining the Angle, Distance, and Polar Functions; Getangle Function; Applying Angdir and Angbase; Getorient Function; Getdist Function
Object Snap and Intersection Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98Osnap Function, Finding Intersection Points
Chapter 6Advanced Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Applications of Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105Numerical Format Controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .105
Fix Function, Float Function, Abs Function
Miscellaneous Math Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107Rem Function, Applying the Fix and Rem Functions, Gcd Function, Max Function, Min Function
Trigonometric Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109Sin Function, Cos Function, Atan Function
Exponents, Roots, and Logs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112Expt Function, Sqrt Function, Log Function, Exp Function, Applying the Log and Exp Functions
Introduction 11
Chapter 7Conversions and String Manipulations . . . . . . . . . . . . . . . . . 117
AutoLISP Data Conversion and String Manipulation . . . . . . . . . . . . . . . . 117Converting Text Strings into Numerical Data and Numerical Data into Text Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Atof Function, Distof Function, Atoi Function, Rtos Function, Itoa Function, Angtos Function, Angtof Function, ASCII Function, Chr Function, Read Function
Functions That Print Text Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126Prin1 Function, Princ Function, Print Function, Selecting a “Print” Function
Manipulating String Data with AutoLISP . . . . . . . . . . . . . . . . . . . . . . . . . .129Strcase Function, Strcat Function, Strlen Function, Substr Function, Acad_Strlsort Function, Getcname Function
Chapter 8Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
Program Flow and Problem-Solving Techniques . . . . . . . . . . . . . . . . . . . .139Test Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
Relational Predicates, Testing Data Types with Predicates, Predicate Review
Creating Simple Branches with If . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .146Expanding Possible Applications with the Progn Function . . . . . . . . . . .148Logical Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .149
And Function, Or Function, Not Function, Applications of Logical Functions
Integrated Testing Procedures with the Type Function . . . . . . . . . . . . . . .154Creating Complex Branches with the Cond Function . . . . . . . . . . . . . . . .155Branching Function Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159
Chapter 9Looping Techniques. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Looping Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161Basic Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Repeat Function, While Function
Append Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165Counting Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .165
1+ Function, 1– Function, Applying the Counting Functions
Processing Each Element of a List. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .167Foreach Function, Set Function, Eval Function
Variable Names from Text Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
Chapter 10Advanced List Manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Advanced Level List Manipulation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .173Review of Basic List-Handling Functions . . . . . . . . . . . . . . . . . . . . . . . . . .173Data Storage List Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Assoc Function, Cons Function, Member Function, Reverse Function, Nth Function
12 Visual LISP Programming
Using List Arguments for Non-List Functions . . . . . . . . . . . . . . . . . . . . . .182Apply Function, Mapcar Functio
Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .184Sample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .186
Chapter 11Entity Database. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 191
Database Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191AutoLISP and the Entity Database . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
Chapter 12Selection Sets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Basic AutoLISP Selection Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .195Ssget Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .196
Ssget Filter Lists, Ssget Function-Relational Tests, Ssget Function-Logical Grouping TestsUsing Grip Selection Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213Selection Set Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214Ssname Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .215Ssnamex Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217Adding, Deleting, and Testing Entities within Selection Sets. . . . . . . . . .220
Ssadd Function, Ssdel Function, Ssmemb Function
Chapter 13Entity-Manipulation Techniques . . . . . . . . . . . . . . . . . . . . . . .227
AutoCAD Entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .227Retrieving Entity Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .227
Entnext Function, Entget Function, Subentity Access, Entlast FunctionHandles and the Handent Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .235Interactive Entity Selections. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .236
Entsel Function, Nentsel FunctionNentselp Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .242Modifying Entity Data Records. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .244
Subst Function, Entmod Function, Entupd FunctionSample Program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248Entity Creation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .249
Entmake Function, Sample Program
Specialized Entity Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
Chapter 14File Handling and Environmental Variables . . . . . . . . . . . . . .257
File-Handling Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .257Locating Files, Prompting the User to Find a File, Reading from Files, Writing to Files, Additional Read and Write Functions
Accessing Environmental Information. . . . . . . . . . . . . . . . . . . . . . . . . . . . .267Ver Function, Environmental Variables
Introduction 13
Chapter 15Symbol Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .271
AutoCAD Symbol Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .271Introduction to Symbol Table Functions . . . . . . . . . . . . . . . . . . . . . . . . . . .272
Tblnext Function, Tblsearch Function, Tblobjname Function, Snvalid Function, Wcmatch Function
AutoCAD Object Dictionary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .287Namedobjdict Function, Dictnext Function, Dictsearch Function, Dictrename Function, Dictadd Function, Dictremove Function
Viewports as Confi gurations and Entities . . . . . . . . . . . . . . . . . . . . . . . . . .300Setview Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305
Chapter 16Graphics Screen and Input Device Functions . . . . . . . . . . . . 311
Drawing Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311Textscr Function, Textpage Function, Graphscr Function
Redrawing Single AutoCAD Entities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .313Controlling the AutoCAD Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
Menucmd Function, Menugroup Function
Chapter 17Programmable Dialog Boxes. . . . . . . . . . . . . . . . . . . . . . . . . .321
DCL File Formats. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322Dialog Box Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323Dialog Defi nition Tree Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .325Defi ning Tiles in DCL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .326DCL Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .329
Predefi ned Active Tiles, Tile Clusters, Informative Tiles, Error and Exit Tiles
Tile Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .342Action Attribute, Alignment Attribute, Allow Accept Attribute, Aspect Ratio Attribute, Big Increment Attribute, Children Alignment Attribute, Children Fixed Height and Fixed Width Attributes, Color Attribute, Edit Limit Attribute, Edit Width Attribute, Fixed Height and Width Attributes, Fixed Width Font Attribute, Height Attribute, Initial Focus Attribute, Is Bold Attribute, Is Cancel Attribute, Is Default Attribute, Is Enabled Attribute, Is Tab Stop Attribute, Key Attribute, Label Attribute, Layout Attribute, List Attribute, Max and Min Value Attributes, Mnemonic Attribute, Multiple Select Attribute, Password Character Attribute, Small Increment Attribute, Tabs Attribute, Tab Truncate Attribute, Value Attribute, Width Attribute
Using Dialog Control Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .349Defi ning a Tile, DCL File Format and Syntax
14 Visual LISP Programming
Chapter 18Programmable Dialog Box Functions. . . . . . . . . . . . . . . . . . .355
Dialog Box Control Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .356Load_Dialog Function, New_Dialog Function, Start_Dialog Function,Done_Dialog Function, Term_Dialog Function, Unload_Dialog Function
Starting Your First Dialog Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .359Working with Tiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .361
Initializing Tiles, Action_Tile Function, Mode_Tile Function, Get_Tile Function
List Boxes and Pop-Up Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .371Start_List Function, Add_List Function, End_List Function
Images and Image Buttons. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .375Start_Image Function, Fill_Image Function
Using Sliders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385Dialog Design Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .388
Mnemonic Keyboard Characters, Tab Stops, Error Control, Basic Layout Considerations, Ending a Dialog Session, Providing Help, Programming Considerations, Understanding DCL Errors, Run Time Symbol Checking
Final Word Regarding Dialog Boxes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .392
Chapter 19Programming and Debugging Techniques. . . . . . . . . . . . . . .395
Programming and Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .395Debugging Effectively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .396
Indentation, Uppercase and Lowercase Characters, Recognizing Error Messages
Locating Programming Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .399Function Design Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .401Using a Function Tracer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .403
Trace Function, Untrace Function
Using Alert as a Debugging Tool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .404Displaying Changing Variable Values, Creating Run-time Checkpoints Using the Alert Function
Visual LISP Debugging Tools and Features. . . . . . . . . . . . . . . . . . . . . . . . .408Stepping through Code, Using Program Breakpoints to Stop Program Execution, Displaying Variable Values Using the Watch Window, Animating Code, Advanced Debugging Tools and Features
Overall Program Appearance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414Error Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 414
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 419