logo资料库

AutoCAD 2013 autolisp开发指南.pdf

第1页 / 共178页
第2页 / 共178页
第3页 / 共178页
第4页 / 共178页
第5页 / 共178页
第6页 / 共178页
第7页 / 共178页
第8页 / 共178页
资料共178页,剩余部分请下载后查看
Contents
Introduction
Introduction
AutoLISP
About Related AutoLISP Documents
Using the AutoLISP Language
AutoLISP Basics
AutoLISP Expressions
AutoLISP Function Syntax
AutoLISP Data Types
Integers
Reals
Strings
Lists
Selection Sets
Entity Names
File Descriptors
Symbols and Variables
AutoLISP Program Files
Formatting AutoLISP Code
Spaces in AutoLISP Code
Comments in AutoLISP Program Files
AutoLISP Variables
Displaying the Value of a Variable
Nil Variables
Predefined Variables
Number Handling
String Handling
Basic Output Functions
Displaying Messages
Exiting Quietly
Control Characters in Strings
Wild-Card Matching
Equality and Conditional
List Handling
Point Lists
Dotted Pairs
Symbol and Function Handling
Using defun to Define a Function
Compatibility of defun with Previous Versions of AutoCAD
C:XXX Functions
Adding Commands
Redefining AutoCAD Commands
Local Variables in Functions
Local Variables versus Global Variables
Example Using Local Variables
Functions with Arguments
Special Forms
Error Handling in AutoLISP
Using the *error* Function
Catching Errors and Continuing Program Execution
Using AutoLISP to Communicate with AutoCAD
Accessing Commands and Services
Command Submission
Foreign Language Support
Pausing for User Input
Passing Pick Points to AutoCAD Commands
Undoing Commands Issued with the command Function
System and Environment Variables
Configuration Control
Display Control
Control of Graphics and Text Windows
Control of Low-Level Graphics
Getting User Input
The getxxx Functions
Control of User-Input Function Conditions
Input Options for User-Input Functions
Keyword Options
Arbitrary Keyboard Input
Input Validation
Geometric Utilities
Object Snap
Text Extents
Conversions
String Conversions
Angular Conversion
ASCII Code Conversion
Unit Conversion
Converting from Inches to Meters
The Unit Definition File
Coordinate System Transformations
Point Transformations
File Handling
File Search
Device Access and Control
Accessing User Input
Using AutoLISP to Manipulate AutoCAD Objects
Selection Set Handling
Selection Set Filter Lists
Wild-Card Patterns in Filter Lists
Filtering for Extended Data
Relational Tests
Logical Grouping of Filter Tests
Selection Set Manipulation
Passing Selection Sets between AutoLISP and ObjectARX Applications
Object Handling
Entity Name Functions
Entity Handles and Their Uses
Entity Context and Coordinate Transform Data
Entity Access Functions
Entity Data Functions
Deleting an Entity
Obtaining Entity Information
Modifying an Entity
Adding an Entity to a Drawing
Creating Complex Entities
Working with Blocks
Anonymous Blocks
Entity Data Functions and the Graphics Screen
Old-Style Polylines and Lightweight Polylines
Processing Curve-Fit and Spline-Fit Polylines
Non-Graphic Object Handling
Symbol Table Objects
Dictionary Objects
Extended Data - xdata
Organization of Extended Data
Registration of an Application
Retrieval of Extended Data
Attachment of Extended Data to an Entity
Management of Extended Data Memory Use
Handles in Extended Data
Xrecord Objects
Symbol Table and Dictionary Access
Symbol Tables
Dictionary Entries
Accessing AutoCAD Groups
Appendixes
AutoLISP Function Synopsis
Category Summary
Basic Functions
Application-Handling Functions
Arithmetic Functions
Equality and Conditional Functions
Error-Handling Functions
Function-Handling Functions
List Manipulation Functions
String-Handling Functions
Symbol-Handling Functions
Utility Functions
Conversion Functions
Device Access Functions
Display Control Functions
File-Handling Functions
Geometric Functions
Query and Command Functions
User Input Functions
Selection Set, Object, and Symbol Table Functions
Extended Data-Handling Functions
Object-Handling Functions
Selection Set Manipulation Functions
Symbol Table and Dictionary-Handling Functions
Memory Management Functions
VLX Namespace Functions
Namespace Communication Functions
Property List (Plist) Functions
AutoLISP Error Codes
Error Codes
Index
AutoCAD 2013 AutoLISP Developer's Guide January 2012
© 2012 Autodesk, Inc. All Rights Reserved. Except as otherwise permitted by Autodesk, Inc., this publication, or parts thereof, may not be reproduced in any form, by any method, for any purpose. Certain materials included in this publication are reprinted with the permission of the copyright holder. Trademarks The following are registered trademarks or trademarks of Autodesk, Inc., and/or its subsidiaries and/or affiliates in the USA and other countries: 123D, 3ds Max, Algor, Alias, Alias (swirl design/logo), AliasStudio, ATC, AUGI, AutoCAD, AutoCAD Learning Assistance, AutoCAD LT, AutoCAD Simulator, AutoCAD SQL Extension, AutoCAD SQL Interface, Autodesk, Autodesk Homestyler, Autodesk Intent, Autodesk Inventor, Autodesk MapGuide, Autodesk Streamline, AutoLISP, AutoSketch, AutoSnap, AutoTrack, Backburner, Backdraft, Beast, Beast (design/logo) Built with ObjectARX (design/logo), Burn, Buzzsaw, CAiCE, CFdesign, Civil 3D, Cleaner, Cleaner Central, ClearScale, Colour Warper, Combustion, Communication Specification, Constructware, Content Explorer, Creative Bridge, Dancing Baby (image), DesignCenter, Design Doctor, Designer's Toolkit, DesignKids, DesignProf, DesignServer, DesignStudio, Design Web Format, Discreet, DWF, DWG, DWG (design/logo), DWG Extreme, DWG TrueConvert, DWG TrueView, DWFX, DXF, Ecotect, Evolver, Exposure, Extending the Design Team, Face Robot, FBX, Fempro, Fire, Flame, Flare, Flint, FMDesktop, Freewheel, GDX Driver, Green Building Studio, Heads-up Design, Heidi, Homestyler, HumanIK, IDEA Server, i-drop, Illuminate Labs AB (design/logo), ImageModeler, iMOUT, Incinerator, Inferno, Instructables, Instructables (stylized robot design/logo),Inventor, Inventor LT, Kynapse, Kynogon, LandXplorer, LiquidLight, LiquidLight (design/logo), Lustre, MatchMover, Maya, Mechanical Desktop, Moldflow, Moldflow Plastics Advisers, Moldflow Plastics Insight, Moldflow Plastics Xpert, Moondust, MotionBuilder, Movimento, MPA, MPA (design/logo), MPI, MPI (design/logo), MPX, MPX (design/logo), Mudbox, Multi-Master Editing, Navisworks, ObjectARX, ObjectDBX, Opticore, Pipeplus, Pixlr, Pixlr-o-matic, PolarSnap, PortfolioWall, Powered with Autodesk Technology, Productstream, ProMaterials, RasterDWG, RealDWG, Real-time Roto, Recognize, Render Queue, Retimer, Reveal, Revit, RiverCAD, Robot, Scaleform, Scaleform GFx, Showcase, Show Me, ShowMotion, SketchBook, Smoke, Softimage, Softimage|XSI (design/logo), Sparks, SteeringWheels, Stitcher, Stone, StormNET, Tinkerbox, ToolClip, Topobase, Toxik, TrustedDWG, U-Vis, ViewCube, Visual, Visual LISP, Voice Reality, Volo, Vtour, WaterNetworks, Wire, Wiretap, WiretapCentral, XSI. All other brand names, product names or trademarks belong to their respective holders. Disclaimer THIS PUBLICATION AND THE INFORMATION CONTAINED HEREIN IS MADE AVAILABLE BY AUTODESK, INC. "AS IS." AUTODESK, INC. DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE REGARDING THESE MATERIALS.
Contents Chapter 1 Chapter 2 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 AutoLISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1 About Related AutoLISP Documents . . . . . . . . . . . . . . . . . 2 Using the AutoLISP Language . . . . . . . . . . . . . . . . . . . 3 AutoLISP Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 AutoLISP Expressions . . . . . . . . . . . . . . . . . . . . . . . . . 3 AutoLISP Function Syntax . . . . . . . . . . . . . . . . . . . 5 AutoLISP Data Types . . . . . . . . . . . . . . . . . . . . . . . . . 6 Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 R e a l s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Selection Sets . . . . . . . . . . . . . . . . . . . . . . . . . . 8 Entity Names . . . . . . . . . . . . . . . . . . . . . . . . . . 8 File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . . 9 Symbols and Variables . . . . . . . . . . . . . . . . . . . . 10 AutoLISP Program Files . . . . . . . . . . . . . . . . . . . . . . . 11 Formatting AutoLISP Code . . . . . . . . . . . . . . . . . . 11 Comments in AutoLISP Program Files . . . . . . . . . . . . 11 AutoLISP Variables . . . . . . . . . . . . . . . . . . . . . . . . . 12 Displaying the Value of a Variable . . . . . . . . . . . . . . 13 iii
Nil Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 13 Predefined Variables . . . . . . . . . . . . . . . . . . . . . . 13 Number Handling . . . . . . . . . . . . . . . . . . . . . . . . . . 14 String Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 Basic Output Functions . . . . . . . . . . . . . . . . . . . . . . . 16 Displaying Messages . . . . . . . . . . . . . . . . . . . . . 17 Control Characters in Strings . . . . . . . . . . . . . . . . . 18 Wild-Card Matching . . . . . . . . . . . . . . . . . . . . . 20 Equality and Conditional . . . . . . . . . . . . . . . . . . . . . . 21 List Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 Point Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 Dotted Pairs . . . . . . . . . . . . . . . . . . . . . . . . . . 26 Symbol and Function Handling . . . . . . . . . . . . . . . . . . 28 Using defun to Define a Function . . . . . . . . . . . . . . 28 C:XXX Functions . . . . . . . . . . . . . . . . . . . . . . . 30 Local Variables in Functions . . . . . . . . . . . . . . . . . 34 Functions with Arguments . . . . . . . . . . . . . . . . . . 36 Error Handling in AutoLISP . . . . . . . . . . . . . . . . . . . . . 38 Using the *error* Function . . . . . . . . . . . . . . . . . . 39 Catching Errors and Continuing Program Execution . . . . 41 Using AutoLISP to Communicate with AutoCAD . . . . . . . . . . . . 42 Accessing Commands and Services . . . . . . . . . . . . . . . . . 42 Command Submission . . . . . . . . . . . . . . . . . . . . 43 System and Environment Variables . . . . . . . . . . . . . . 47 Configuration Control . . . . . . . . . . . . . . . . . . . . 47 Display Control . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 Control of Graphics and Text Windows . . . . . . . . . . . 48 Control of Low-Level Graphics . . . . . . . . . . . . . . . . 48 Getting User Input . . . . . . . . . . . . . . . . . . . . . . . . . 49 The getxxx Functions . . . . . . . . . . . . . . . . . . . . . 49 Control of User-Input Function Conditions . . . . . . . . . 52 Geometric Utilities . . . . . . . . . . . . . . . . . . . . . . . . . 55 Object Snap . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Text Extents . . . . . . . . . . . . . . . . . . . . . . . . . . 56 Conversions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61 String Conversions . . . . . . . . . . . . . . . . . . . . . . 61 Angular Conversion . . . . . . . . . . . . . . . . . . . . . . 64 ASCII Code Conversion . . . . . . . . . . . . . . . . . . . . 65 Unit Conversion . . . . . . . . . . . . . . . . . . . . . . . 67 Coordinate System Transformations . . . . . . . . . . . . . 70 File Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 File Search . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Device Access and Control . . . . . . . . . . . . . . . . . . . . . 74 Accessing User Input . . . . . . . . . . . . . . . . . . . . . 74 Using AutoLISP to Manipulate AutoCAD Objects . . . . . . . . . . . . 74 Selection Set Handling . . . . . . . . . . . . . . . . . . . . . . . 75 iv | Contents
Chapter 3 Selection Set Filter Lists . . . . . . . . . . . . . . . . . . . . 77 Passing Selection Sets between AutoLISP and ObjectARX Applications . . . . . . . . . . . . . . . . . . . . . . . . . 85 Object Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 Entity Name Functions . . . . . . . . . . . . . . . . . . . . 86 Entity Data Functions . . . . . . . . . . . . . . . . . . . . . 92 Entity Data Functions and the Graphics Screen . . . . . . . 102 Old-Style Polylines and Lightweight Polylines . . . . . . . 103 Non-Graphic Object Handling . . . . . . . . . . . . . . . 104 Extended Data - xdata . . . . . . . . . . . . . . . . . . . . . . . 106 Organization of Extended Data . . . . . . . . . . . . . . . 107 Registration of an Application . . . . . . . . . . . . . . . . 109 Retrieval of Extended Data . . . . . . . . . . . . . . . . . 110 Attachment of Extended Data to an Entity . . . . . . . . . 111 Management of Extended Data Memory Use . . . . . . . . 112 Handles in Extended Data . . . . . . . . . . . . . . . . . . 112 Xrecord Objects . . . . . . . . . . . . . . . . . . . . . . . . . . 113 Symbol Table and Dictionary Access . . . . . . . . . . . . . . . 114 Symbol Tables . . . . . . . . . . . . . . . . . . . . . . . . 114 Dictionary Entries . . . . . . . . . . . . . . . . . . . . . . 116 Appendixes . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119 AutoLISP Function Synopsis . . . . . . . . . . . . . . . . . . . . . . . 119 Category Summary . . . . . . . . . . . . . . . . . . . . . . . . . 119 Basic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 121 Application-Handling Functions . . . . . . . . . . . . . . 121 Arithmetic Functions . . . . . . . . . . . . . . . . . . . . 122 Equality and Conditional Functions . . . . . . . . . . . . 125 Error-Handling Functions . . . . . . . . . . . . . . . . . . 126 Function-Handling Functions . . . . . . . . . . . . . . . . 127 List Manipulation Functions . . . . . . . . . . . . . . . . 128 String-Handling Functions . . . . . . . . . . . . . . . . . 131 Symbol-Handling Functions . . . . . . . . . . . . . . . . . 133 Utility Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 134 Conversion Functions . . . . . . . . . . . . . . . . . . . . 134 Device Access Functions . . . . . . . . . . . . . . . . . . . 135 Display Control Functions . . . . . . . . . . . . . . . . . . 136 File-Handling Functions . . . . . . . . . . . . . . . . . . . 137 Geometric Functions . . . . . . . . . . . . . . . . . . . . 139 Query and Command Functions . . . . . . . . . . . . . . 139 User Input Functions . . . . . . . . . . . . . . . . . . . . 141 Selection Set, Object, and Symbol Table Functions . . . . . . . . 142 Extended Data-Handling Functions . . . . . . . . . . . . . 143 Object-Handling Functions . . . . . . . . . . . . . . . . . 143 Selection Set Manipulation Functions . . . . . . . . . . . . 145 Symbol Table and Dictionary-Handling Functions . . . . . 146 Contents | v
Memory Management Functions . . . . . . . . . . . . . . . . . 147 VLX Namespace Functions . . . . . . . . . . . . . . . . . . . . 147 Namespace Communication Functions . . . . . . . . . . . . . . 148 Property List (Plist) Functions . . . . . . . . . . . . . . . . . . . 149 AutoLISP Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Error Codes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 vi | Contents
Introduction Introduction 1 ® has set the standard for customizing AutoCAD® on For years, AutoLISP Windows®. AutoCAD also supports AutoLISP, but does not support many of ® the Visual LISP functions or the Microsoft ActiveX AutoCAD does not have an integrated development environment like AutoCAD on Windows does, so the creation and editing of LSP files must be done with text editor such as TextEdit. Automation interface. AutoLISP AutoLISP is a programming language designed for extending and customizing the functionality of AutoCAD. It is based on the LISP programming language, whose origins date back to the late 1950s. LISP was originally designed for use in Artificial Intelligence (AI) applications, and is still the basis for many AI applications. AutoLISP was introduced as an application programming interface (API) in AutoCAD Release 2.1, in the mid-1980s. LISP was chosen as the initial AutoCAD API because it was uniquely suited for the unstructured design process of AutoCAD projects, which involved repeatedly trying different solutions to design problems. Developing AutoLISP programs for AutoCAD is done by writing code in a text editor, then loading the code into AutoCAD and running it. Debugging your program is handled by adding statements to print the contents of variables at strategic points in your program. You must figure out where in your program to do this, and what variables you need to look at. If you discover you do not have enough information to determine the error, you must go back and change 1
the code by adding more debugging points. And finally, when you get the program to work correctly, you need to either comment out or remove the debugging code you added. About Related AutoLISP Documents In addition to the AutoLISP Reference, several other AutoCAD publications may be required by users building applications with AutoLISP: AutoCADCustomization Guide contains basic information on creating customized AutoCAD applications. For example, it includes information on creating customized user interface elements, linetypes, and hatch patterns. The Customization Guide is available through the AutoCAD and Help menu on the Mac OS menu bar. The DXF Reference describes drawing interchange format (DXFTM) and the DXF group codes that identify attributes of AutoCAD objects. The DXF Reference is not included when you install AutoCAD. To obtain the manual, download the DXF Reference from www.autodesk.com. ® The ObjectARX Reference contains information on using ObjectARX develop customized AutoCAD applications. AutoCAD reactor functionality is implemented through ObjectARX. If you develop AutoLISP applications that implement reactor functions, you may want to refer to this manual. The ObjectARX Reference is not included when you install AutoCAD. To obtain the manual, download the ObjectARX SDK (Software Development Kit) from www.autodesk.com. to 2 | Chapter 1 Introduction ■ ■ ■
分享到:
收藏