AutoCAD 2000 Visual LISP - Developer's Guide.pdf

(6524 KB) Pobierz
83598735 UNPDF
VISUAL LISP™ DEVELOPER’S GUIDE
00120-010000-5160
March 01, 1999
83598735.025.png 83598735.026.png 83598735.027.png 83598735.028.png 83598735.001.png 83598735.002.png 83598735.003.png 83598735.004.png 83598735.005.png 83598735.006.png 83598735.007.png 83598735.008.png 83598735.009.png 83598735.010.png 83598735.011.png 83598735.012.png 83598735.013.png 83598735.014.png 83598735.015.png 83598735.016.png 83598735.017.png 83598735.018.png 83598735.019.png 83598735.020.png 83598735.021.png 83598735.022.png
Copyright © 1999 Autodesk, Inc.
All Rights Reserved
AUTODESK, INC. MAKES NO WARRANTY, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY
IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, REGARDING THESE MATERIALS
AND MAKES SUCH MATERIALS AVAILABLE SOLELY ON AN “AS-IS” BASIS.
IN NO EVENT SHALL AUTODESK, INC. BE LIABLE TO ANYONE FOR SPECIAL, COLLATERAL, INCIDENTAL, OR
CONSEQUENTIAL DAMAGES IN CONNECTION WITH OR ARISING OUT OF PURCHASE OR USE OF THESE MATERIALS. THE
SOLE AND EXCLUSIVE LIABILITY TO AUTODESK, INC., REGARDLESS OF THE FORM OF ACTION, SHALL NOT EXCEED THE
PURCHASE PRICE OF THE MATERIALS DESCRIBED HEREIN.
Autodesk, Inc. reserves the right to revise and improve its products as it sees fit. This publication describes the state of this product
at the time of its publication, and may not reflect the product at all times in the future.
Autodesk Trademarks
The following are registered trademarks of Autodesk, Inc., in the USA and/or other countries: 3D Plan, 3D Props, 3D Studio, 3D
Studio MAX, 3D Studio VIZ, 3D Surfer, ADE, ADI, Advanced Modeling Extension, AEC Authority (logo), AEC-X, AME, Animator
Pro, Animator Studio, ATC, AUGI, AutoCAD, AutoCAD Data Extension, AutoCAD Development System, AutoCAD LT, AutoCAD
Map, Autodesk, Autodesk Animator, Autodesk (logo), Autodesk MapGuide, Autodesk University, Autodesk View, Autodesk
WalkThrough, Autodesk World, AutoLISP, AutoShade, AutoSketch, AutoSolid, AutoSurf, AutoVision, Biped, bringing information
down to earth, CAD Overlay, Character Studio, Design Companion, Drafix, Education by Design, Generic, Generic 3D Drafting,
Gen e ri c CADD, Ge ne ri c S o ftw ar e, Ge odys s e y, He idi , H OOPS , H ype rw ire , In s i de T rac k, Ki n eti x , Ma ter ia lS pe c, Me ch an i cal De s kto p,
Multimedia Explorer, NAAUG, Office Series, Opus, PeopleTracker, Physique, Planix, Rastation, Softdesk, Softdesk (logo), Solution
3000, Tech Talk, Texture Universe, The AEC Authority, The Auto Architect, TinkerTech, WHIP!, WHIP! (logo), Woodbourne,
WorkCenter, and World-Creating Toolkit.
The following are trademarks of Autodesk, Inc., in the USA and/or other countries: 3D on the PC, ACAD, ActiveShapes, Actrix,
Advanced User Interface, AEC Office, AME Link, Animation Partner, Animation Player, Animation Pro Player, A Studio in Every
Computer, ATLAST, Auto-Architect, AutoCAD Architectural Desktop, AutoCAD Architectural Desktop Learning Assistance,
AutoCAD DesignCenter, Learning Assistance, AutoCAD LT Learning Assistance, AutoCAD Simulator, AutoCAD SQL Extension,
AutoCAD SQL Interface, AutoCDM, Autodesk Animator Clips, Autodesk Animator Theatre, Autodesk Device Interface, Autodesk
PhotoEDIT, Autodesk Software Developer’s Kit, Autodesk View DwgX, AutoEDM, AutoFlix, AutoLathe, AutoSnap, AutoTrack, Built
with ObjectARX (logo), ClearScale, Concept Studio, Content Explorer, cornerStone Toolkit, Dancing Baby (image), Design Your
World, Design Your World (logo), Designer’s Toolkit, DWG Linking, DWG Unplugged, DXF, Exegis, FLI, FLIC, GDX Driver, Generic
3D, Heads-up Design, Home Series, Kinetix (logo), MAX DWG, ObjectARX, ObjectDBX, Ooga-Chaka, Photo Landscape,
Photoscape, Plugs and Sockets, PolarSnap, Powered with Autodesk Technology, Powered with Autodesk Technology (logo),
ProConnect, ProjectPoint, Pro Landscape, QuickCAD, RadioRay, SchoolBox, SketchTools, Suddenly Everything Clicks,
Supportdesk, The Dancing Baby, Transforms Ideas Into Reality, Visual LISP, and Volo.
Third Party Trademarks
Élan License Manager is a trademark of Élan Computer Group, Inc.
Microsoft, Visual Basic, Visual C++, and Windows are registered trademarks and Visual FoxPro and the Microsoft Visual Basic
Technology logo are trademarks of Microsoft Corporation in the United States and other countries.
All other brand names, product names or trademarks belong to their respective holders.
Third Party Software Program Credits
ACIS® Copyright © 1994, 1997, 1999 Spatial Technology, Inc., Three-Space Ltd., and Applied Geometry Corp. All rights reserved.
Copyright © 1997 Microsoft Corporation. All rights reserved.
International CorrectSpell™ Spelling Correction System © 1995 by Lernout & Hauspie Speech Products, N.V. All rights reserved.
InstallShield™ 3.0. Copyright © 1997 InstallShield Software Corporation. All rights reserved.
Portions Copyright © 1991-1996 Arthur D. Applegate. All rights reserved.
Portions of this software are based on the work of the Independent JPEG Group.
Typefaces from the Bitstream® typeface library copyright 1992.
Typefaces from Payne Loving Trust © 1996. All rights reserved.
The license management portion of this product is based on Élan License Manager © 1989, 1990, 1998 Élan Computer Group,
Inc. All rights reserved.
Autodesk would like to acknowledge and thank Perceptual Multimedia, Inc., for the creative and technical design and the
development of the Visual LISP Garden Path tutorial.
GOVERNMENT USE
Use, duplication, or disclosure by the U. S. Government is subject to restrictions as set forth in FAR 12.212 (Commercial Computer
Software-Restricted Rights) and DFAR 227.7202 (Rights in Technical Data and Computer Software), as applicable.
12345678910
83598735.023.png
Contents
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
AutoLISP and Visual LISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
What Visual LISP Offers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Working with Visual LISP and AutoCAD . . . . . . . . . . . . . . . . . . . . . . 3
Using Visual LISP Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Document Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Related Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Part I
Using the Visual LISP Environment . . . . . . . . . . . . . . . . 9
Chapter 1
Getting Started. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Starting Visual LISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Exploring the Visual LISP User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Introducing the Visual LISP Text Editor . . . . . . . . . . . . . . . . . . . . . . 14
Other Visual LISP Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Touring the Visual LISP Menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Variable Menu Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Visual LISP Menu Summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Understanding the Console Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Understanding the Visual LISP Text Editor . . . . . . . . . . . . . . . . . . . . . . . . 19
Loading and Running AutoLISP Programs . . . . . . . . . . . . . . . . . . . . . . . . . 20
Running Selected Lines of Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
Using Extended AutoLISP Functions . . . . . . . . . . . . . . . . . . . . . . . . . 22
Exiting Visual LISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
iii
83598735.024.png
Chapter 2
Developing Programs with Visual LISP. . . . . . . . . . . . . . . . . . . . . . 23
Getting Organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Using the Console Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Understanding Console Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Using the Console Window with Multiple Drawings. . . . . . . . . . . . 28
Using the Console Shortcut Menu . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Logging Console Window Activity . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Using the Text Editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Editing a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
Using the Text Editor Shortcut Menu . . . . . . . . . . . . . . . . . . . . . . . . 32
Using Keyboard Shortcuts in the Text Editor . . . . . . . . . . . . . . . . . . 33
Moving and Copying Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Searching for Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
Bookmarking Text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Using Console and Editor Coding Aids . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Understanding Visual LISP Color Coding. . . . . . . . . . . . . . . . . . . . . 42
Using the Apropos Feature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Letting Visual LISP Help You Complete Words . . . . . . . . . . . . . . . . 47
Getting Help for AutoLISP Functions . . . . . . . . . . . . . . . . . . . . . . . . 50
Formatting Code with Visual LISP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Understanding Visual LISP Formatting Styles . . . . . . . . . . . . . . . . . 51
Applying Formatting Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
Applying Visual LISP Comment Styles . . . . . . . . . . . . . . . . . . . . . . . 58
Saving and Restoring Formatting Options . . . . . . . . . . . . . . . . . . . . 58
Formatter Restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Formatting Shortcut Keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
Checking for Syntax Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Checking the Balance of Parentheses . . . . . . . . . . . . . . . . . . . . . . . . 61
Using Color Coding to Detect Syntax Errors . . . . . . . . . . . . . . . . . . 63
Using the Check Command to Look for Syntax Errors . . . . . . . . . . 64
Chapter 3
Debugging Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
Introducing Visual LISP Debugging Features . . . . . . . . . . . . . . . . . . . . . . . 68
Learning by Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Stepping through the Debugging Example. . . . . . . . . . . . . . . . . . . . 69
Using the Visual LISP Debugging Features . . . . . . . . . . . . . . . . . . . . . . . . . 75
Starting a Debugging Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Understanding Break Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
Using Breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
Using Visual LISP Data Inspection Tools . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Using the Watch Window. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
Understanding the Trace Stack Window . . . . . . . . . . . . . . . . . . . . . 85
Using the Symbol Service Dialog Box . . . . . . . . . . . . . . . . . . . . . . . . 92
Using Inspect Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
iv | Contents
 
Viewing AutoCAD Drawing Entities . . . . . . . . . . . . . . . . . . . . . . . . 104
Chapter 4
Building Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Compiling and Linking Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Using the Compiler . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Compiling a Program from a File . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Walking through a Compile Example . . . . . . . . . . . . . . . . . . . . . . . 113
Loading and Running Compiled Programs . . . . . . . . . . . . . . . . . . . 114
Linking Function Calls. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Making Application Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Creating a New Application. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Loading and Running Visual LISP Applications . . . . . . . . . . . . . . . 124
Changing Application Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
Rebuilding an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Updating an Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Designing for a Multiple Document Environment. . . . . . . . . . . . . . . . . . 126
Understanding Namespaces. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Running an Application in Its Own Namespace . . . . . . . . . . . . . . . 129
Sharing Data between Namespaces . . . . . . . . . . . . . . . . . . . . . . . . . 133
Handling Errors in an MDI Environment . . . . . . . . . . . . . . . . . . . . 134
Limitations on Using AutoLISP in an MDI Environment . . . . . . . . 136
Chapter 5
Maintaining Visual LISP Applications . . . . . . . . . . . . . . . . . . . . . . 137
Managing Multiple LISP Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
Understanding Visual LISP Projects . . . . . . . . . . . . . . . . . . . . . . . . . 138
Defining a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Assigning Project Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
Using the Project Window to Work with Project Files . . . . . . . . . . 145
Working with Existing Projects. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Opening a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Finding a String in Project Source Files . . . . . . . . . . . . . . . . . . . . . . 150
Including a Project in a Visual LISP Application . . . . . . . . . . . . . . . 151
Optimizing Application Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Defining Build Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Choosing a Compilation Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Choosing a Link Mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Understanding Safe Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . 157
Chapter 6
Working with ActiveX. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
Using ActiveX Objects with AutoLISP. . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Understanding the AutoCAD Object Model. . . . . . . . . . . . . . . . . . . . . . . 162
Object Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Contents | v
Zgłoś jeśli naruszono regulamin