home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / textinfo / autolisp.arj / AUTOLISP.TXT
Encoding:
Text File  |  1988-09-17  |  32.2 KB  |  670 lines

  1. --------------------
  2.  
  3. "AutoLISP Notes"
  4. Technical notes about the AutoLISP inplementation from a lecture
  5. presented at AutoCAD Expo '88 by Greg Lutz, Senior Programmer, Autodesk,
  6. Inc.
  7.  
  8. AutoLISP is logically a separate application, communicating with AutoCAD
  9. through a rigidly defined protocol.
  10.  
  11. Communication linkage is called the "far call" mechanism, largely for
  12. historical reasons.
  13.  
  14. *    Strictly synchronous, each end waiting on the other.
  15. *    A packet-passing protocol.
  16. -      Packets normally 512 bytes, smaller for some message types.
  17. -      Packets have a function code in a fixed location.
  18. -      Remainder of packet format is defined by function code.
  19. *    The means for passing the packets is different on different machine
  20.      implementations.
  21.  
  22. -    On MS-DOS and Macintosh, true coroutines, with each party actually
  23.      calling the other.
  24.  
  25. -    On Unix, the two parties are separate processes and pass the
  26.      packets through a pipe.
  27.  
  28. -    On Unix, packet passing is augmented by signalling for efficiency
  29.      in some cases.
  30.  
  31. Memory usage:
  32.  
  33. *    Classic LISP:  all objects are stored in fixed-size "nodes".
  34. *    AutoLISP nodes are 10 bytes in size.  Node storage is acquired from
  35. *    Storage for strings is the only other significant drain on heap space.
  36. *    Nodes are never explicitly returned to the heap.  When an attempt
  37.      to obtain new node or string space from the heap fails, "garbage
  38.      collection" is performed.  This is a process which returns all
  39.      "inaccessible" nodes to the free list.
  40. *    Each data type listed in the AutoLISP Programmer's Reference
  41.      corresponds to a different node type, as represented by a 1-byte field
  42.      in the node itself.  Lists are the commonest type.
  43.  
  44. *    All heap storage, including that for built-in symbols, is released
  45.      and re-initialized upon entry to the Drawing Editor.
  46.  
  47. The "atom list":
  48. *    "Symbols" are just another data type.
  49. *    Symbols distinguished by the fact that anytime one is created, it
  50.      is added to the list called "ATOMLIST".
  51. *    All built-in symbols come first on the atomlist.
  52. *    All symbols referenced in LISP expressions are looked up on the atomlist.
  53.      They can never be removed.  But you can redefine atomlist (at your own
  54.      risk) to get rid of symbol definitions.
  55. *    A new symbol is created by appearing as the first argument to the
  56.      QUOTE or DEFUN function.  SETQ implicitly invokes QUOTE.
  57.  
  58. --------------------
  59.  
  60.            AutoLISP Extensions  Releases 9 and 10
  61.           (notes from a lecture presented at AutoCAD Expo '88)
  62.           by Duff Kurland, Autodesk, Inc., Sausalito, California
  63.  
  64. "Tools For The Golden Age Of Engineering"
  65.  
  66. AutoLISP Release 9
  67. *    (command) pause for user input
  68. *    (ssget "x") filters
  69. *    Support for huge selection sets
  70. *    Quiet function exit via (princ)
  71.  
  72. AutoLISP Release 10
  73. *    New (getenv "varname") function returns string value of environment
  74.      variable
  75. *    New (findfile "name") function searches path (the current, drawing
  76.      and ACAD directories), returns full file name
  77. *    (load "name" [onfailure]) is now recursive, searches path, returns
  78.      new "onfailure" argument upon failure
  79. *    New S::STARTUP function (if defined) executes automatically at
  80.      editor startup
  81. *    (equal num num [fuzz]) provides optional fuzz factor for equality
  82.      tests between reals
  83. *    (tblnext) and (tblsearch) extended to support new VPORT and UCS
  84.      symbol tables
  85. *    (redraw), (grclear), and (grdraw) operate on the current viewport
  86. *    New (vports) function returns IDs and locations of active viewports
  87. *    Many functions, including (distance) and (inters), now support 3D
  88. *    New FLATLAND system variable selects 2D (compatible) mode
  89. *    (entget) returns new entity fields, including handles
  90. *    (handent "handle") returns entity name
  91. *    Points are normally in UCS, but (entget) and (entmod) work in ECS
  92. *    (trans) translates between User, World and Entity coordinates
  93.  
  94. --------------------
  95.  
  96. From a paper presented at the "AutoLISP: Ask The Experts" conference at
  97. AutoCAD Expo '88, May 3, 1988 by Brad Zehring et. al., Autodesk, Inc.,
  98. Training Department.
  99.  
  100. Ten Of The Most Commonly Asked Questions About AutoLISP
  101.  
  102. 1.   Can AutoLISP programs be compiled?
  103.  
  104. No, AutoLISP is an interpretive language.  It reads source code directly
  105. and creates lists of tokens from expressions and function definitions as
  106. it reads them.  Creating a compiler for AutoLISP would be a major
  107. undertaking, and Autodesk has not committed to doing so at this time.
  108. However, we are constantly exploring ways to enhance the speed and
  109. flexibility of our applications interface.
  110.  
  111. 2.   Can AutoCAD use any LISP interpreter/compiler other than AutoLISP?
  112.  
  113. AutoCAD and AutoLISP are designed specifically to work with one another.
  114. Autodesk does not currently support any other LISP interpreters and/or
  115. compilers.
  116.  
  117. 3.   What is "Insufficient Node Space?"
  118.  
  119. This message appears when there is not enough space in the AutoLISP heap
  120. to store all of the required functions and variables.  The size of the
  121. heap can be adjusted with the environment variable LISPHEAP.  See
  122. Chapter 6 of your AutoLISP Programmer's Reference for details.
  123.  
  124. 4.   What can be done when AutoLISP programs become too large to fit in
  125. the available node space, even if the size of the LISPHEAP has been
  126. increased to the maximum?
  127.  
  128. AutoLISP supports Virtual Memory Paging, which allows AutoLISP to open a
  129. temporary file and swap functions in and out of memory.  In many cases,
  130. this can effectively increase the size of the heap far beyond its normal
  131. boundary in conventional memory.  See the function VMON in your AutoLISP
  132. Programmer's Reference.
  133.  
  134. 5.   What causes the "LISPSTACK overflow" message?
  135.  
  136. There is not enough space in the AutoLISP stack to store the required
  137. function arguments and partial results.  The size of the stack can be
  138. adjusted with the environment variable LISPSTACK.  See your  AutoLISP
  139. Programmer's Reference for details.
  140.  
  141. NOTE:  This error usually occurs because of a program error resulting in
  142. a self-recursive function call, an example of which would be:
  143.  
  144. (defun a () (B))
  145. (defun b () (A))
  146. (A)
  147.  
  148. 6.   What causes the "Out of RAM" message?
  149.  
  150. The setting for ACADFREERAM is too low.  This is a stack space in memory
  151. that AutoCAD uses for working storage.  By default, the setting is 14
  152. kilobytes.  Use the environment variable ACADFREERAM to increase its
  153. size (up to its maximum of between 20 and 24 kilobytes).  See your
  154. AutoCAD Installation and Performance Guide for more details.
  155.  
  156. NOTE: In Release 10, the default setting for ACADFREERAM will be its
  157. maximum value of 24 kilobytes.  You will still be able to adjust the
  158. size of ACADFREERAM via its environment variable, should you so desire.
  159.  
  160. 7.   Why did Autodesk choose LISP rather than some other language as the
  161. first AutoCAD Applications Interface?
  162.  
  163. LISP excels at working with collections of heterogeneous objects in
  164. various sized groups, which is typically what a CAD program is used for.
  165. It is ideally suited to the unstructured interaction that characterizes
  166. the design process.  It is among the easiest of all programming
  167. languages to learn and to master.  It is the chosen language for
  168. research and development of artificial intelligence and expert systems.
  169. And because of LISP's exceedingly simple syntax, a LISP interpreter is
  170. easy to implement and quite small!
  171.  
  172. 8.   Will Autodesk ever replace AutoLISP with a different language?
  173.  
  174. In the future, Autodesk may supplement the AutoLISP language with other
  175. application interfaces.  However, Autodesk is committed to long-term
  176. support for AutoLISP, and any new applications will be introduced as
  177. enhancements to AutoLISP, not replacements.
  178.  
  179. 9.   What is AutoLISP based on?
  180.  
  181. AutoLISP is a superset of a subset of Common LISP, the most popular LISP
  182. implementation currently in use.  Many unique functions and features
  183. specific to AutoCAD have been included in AutoLISP.  The interpreter
  184. itself is based on XLISP, a program developed by David Betz.  Autodesk
  185. gratefully acknowledges the contribution his work made to the
  186. development of AutoLISP.  Information on XLISP is available from David
  187. Betz, 127 Taylor Road, Peterborough, NH 03458.
  188.  
  189. 10.  What books are available on AutoLISP and Common LISP?
  190.  
  191. AutoLISP specific:
  192.  
  193. Customizing AutoCAD
  194.      by R. Gesner and J. Smith
  195.  
  196. AutoLISP In Plain English
  197.      by George O. Head
  198.  
  199. Common LISP and other dialects:
  200.  
  201. Common LISP: The Language
  202.      by Guy L. Steele, Jr.
  203.  
  204. LISP
  205.      by Winston and Horn
  206.  
  207. Looking At LISP
  208.      by Tony Hasemer
  209.  
  210. LISPcraft
  211.      by Robert Wilensky
  212.  
  213. A Gentle Introduction To Symbolic Computation
  214.      by David Touretzky
  215.  
  216. --------------------
  217.  
  218. From a paper presented at the "AutoLISP: Ask The Experts" conference at
  219. AutoCAD Expo '88, May 3, 1988, by John Lynch, Senior Programmer,
  220. Autodesk, Inc.
  221.  
  222. Extended AutoLISP
  223. by John Lynch
  224. April 25, 1988
  225.  
  226. What is Extended AutoLISP?
  227.  
  228. Extended AutoLISP is a special version of AutoLISP that has been
  229. modified to take advantage of extended memory.  This version actually
  230. runs in the native ``protected'' mode of the Intel 80286 and 80386, and
  231. allows your programs to access large amounts of memory.  In simpler
  232. terms, Extended AutoLISP gives you access to practically unlimited node
  233. space on an IBM AT or compatible machine while maintaining DOS
  234. compatibility.
  235.  
  236. We say practically unlimited node space because in a real sense you are
  237. limited to the amount of extended memory available in your machine, but
  238. you may access as much as fourteen megabytes.  In terms of what AutoLISP
  239. can do with this memory, a megabyte of memory gives you approximately
  240. 105000 nodes.  A far cry from the 3072 nodes most applications have
  241. under the current lisp implementation.
  242.  
  243. Other than this, there is no difference in features between Extended
  244. AutoLISP and regular AutoLISP.  The function definitions remain the
  245. same, and existing applications should run the same as before.
  246.  
  247. We expect to release Extended AutoLISP concurrently with AutoCAD Release
  248. 10. A price has not yet been established for Extended AutoLISP.
  249.  
  250. Why do we need Extended AutoLISP?
  251.  
  252. The need for additional memory has been an issue with AutoCAD since the
  253. early releases.  AutoCAD uses memory as conservatively as any
  254. application on the market, but with the number of features added to
  255. Release 10, we have finally run out of memory resources below the 640k
  256. barrier.
  257.  
  258. AutoLISP currently uses some of this precious memory resource for its
  259. purposes.  AutoLISP is a ``small model'' program which means that it
  260. uses a single code segment and data segment of 64k each, for a combined
  261. use of 128k of memory.  AutoLISP, however, gets its memory from AutoCAD,
  262. and is generally the first thing that loses memory when there is a
  263. shortage.  This means that if you rely on network or device drivers, or
  264. have numerous terminate and stay resident  programs (like Sidekick)
  265. installed, you generally would get the message that ``AutoLISP is
  266. disabled.''
  267.  
  268. By removing AutoLISP from ``low'' memory (memory below 640k), we
  269. eliminate many of these concerns.  In fact, AutoCAD gets the benefit of
  270. having more I/O page space to use, and can run a little faster because
  271. of it.
  272.  
  273. AutoLISP was also pushing another barrier.  The 64k code segment size
  274. prevented us from implementing any new features in AutoLISP.  As users
  275. become more familiar with Release 10's new features, new AutoLISP
  276. capabilities to access many of these features may be requested.
  277. Extended AutoLISP will allow us to add new features, which would not
  278. otherwise be feasible because of the code size barrier.
  279.  
  280. How do I install Extended AutoLISP?
  281.  
  282. Extended AutoLISP will come as an installable option for AutoCAD Release
  283. 10.  There are several files provided, one of which is a Terminate and
  284. Stay Resident executable (extlisp.exe) and the other is a replacement
  285. for acadl.ovl (regular AutoLISP), which communicates with Extended
  286. AutoLISP.
  287.  
  288. To install it, you simply copy the files onto your hard disk, and make
  289. sure that extlisp.exe is loaded (executed) before entering AutoCAD.
  290. This may be done by placing it in your autoexec.bat file so that it is
  291. installed each time you start your machine.  Then you simply copy
  292. acadl.ovl supplied with Extended AutoLISP to the same place as the rest
  293. of your AutoCAD executables.  You may want to save your copy of the
  294. regular AutoLISP overlay first by copying it to another file (e.g. copy
  295. acadl.ovl acadl.sav).
  296.  
  297.  
  298. What are the hardware requirements?
  299.  
  300. Extended AutoLISP will run on 80286 and 80386 based machines that
  301. support AutoCAD and also have extended memory available.  The minimum
  302. amount of extended memory is about 200k, but we would recommend about
  303. 500k for a comfortable operating environment and to get the most benefit
  304. from ExtLISP.
  305.  
  306. Extended AutoLISP will not run on 8086 and 8088 (XT) based machines.
  307.  
  308. Not all of your extended memory needs to be set aside for Extended
  309. AutoLISP.  ExtLISP will recognize vdisk which uses extended memory, and
  310. can also be configured to allow AutoCAD to use what is left for page
  311. space.  A typical installation with 3 megabytes of extended memory (4
  312. megs total) might set up a 1 megabyte vdisk, use a megabyte for Extended
  313. AutoLISP, and let AutoCAD use the remaining megabyte for page space.
  314.  
  315. Extended AutoLISP will not work with expanded memory.  This is an
  316. important distinction.  It will also not work with device drivers that
  317. are installed to make extended memory look like expanded memory.  These
  318. include CEMM (Compaq Expanded Memory Manager) and QEMM (Quarterdeck
  319. Expanded Memory Manager).  This limitation stems from the fact that we
  320. are placing code in extended memory which must be executed.  The
  321. expanded memory schemes provide a paging mechanism for swapping data in
  322. and out of low memory.  Although such a scheme could be used to
  323. alleviate data size problems, it will not address the code size
  324. limitations experienced with AutoLISP.
  325.  
  326. We have studied the Lotus-Intel-Microsoft (LIM) specification version
  327. 4.0 of expanded memory usage, and determined that it would not be
  328. feasible to deliver the performance needed for AutoLISP.
  329.  
  330. How do I tell if I have Extended or Expanded Memory?
  331.  
  332. Generally your system configuration or diagnostics will tell you how
  333. much memory you have installed.  If there is an entry for memory
  334. installed above one megabyte (1M), it is likely to be the amount of
  335. extended memory installed.  If not, you will need to add it to your
  336. configuration to support Extended AutoLISP.
  337.  
  338. If you are in doubt, contact the dealer who sold you the system for an
  339. idea of which type of memory is installed.  Extended memory is ``AT
  340. type'' memory while expanded memory is used in PCs and XTs.
  341.  
  342. Perhaps the simplest method is to watch the memory test at power up. If
  343. the numbers in the upper left corner of the screen go beyond 640k, then
  344. there is Extended memory installed in your machine.
  345.  
  346. How is Extended AutoLISP created?
  347.  
  348. To create Extended AutoLISP we used a special software product known as
  349. a ``DOS Extender''.  These products have become popular over the last
  350. year or so, and have matured in features and stability.  The product we
  351. used is DOS/16M created by Rational Systems, Inc. and was chosen for its
  352. support of both the 80286 and 80386.  Other DOS extenders support only
  353. the 80386, and are therefore more restrictive.
  354.  
  355. DOS/16M converts a DOS executable into an application that runs in the
  356. ``protected'' mode on the 80286 (386).  It also provides a library of
  357. routines that allow the application to maintain a very high degree of
  358. DOS compatibility.
  359.  
  360. How does Extended AutoLISP work?
  361.  
  362. From its inception, AutoLISP has been a ``stand-alone'', on-line program
  363. with which AutoCAD communicates in a very special way.  Because of this
  364. design, AutoLISP is easily separated from AutoCAD, and placed in
  365. extended memory with the same communication channel between it and
  366. AutoCAD.
  367.  
  368. Because ExtLISP lives in extended memory, it must run while the
  369. processor is in its native ``protected'' mode.  AutoCAD, of course, runs
  370. in ``real'' mode (as do all DOS applications), and the processor must
  371. therefore be switched from real to protected mode and back again when
  372. AutoCAD calls AutoLISP.
  373.  
  374. A typical cycle would be when AutoCAD signals AutoLISP to evaluate an
  375. expression.  The expression is passed to the overlay (acadl.ovl) which
  376. in turn signals Extended AutoLISP which switches the processor to
  377. protected mode.  AutoLISP evaluates the expression, places the result in
  378. a buffer, switches the processor back to real mode where  AutoCAD
  379. resumes operation where it left off.
  380.  
  381. Is Extended AutoLISP faster or slower than regular AutoLISP?
  382.  
  383. As mentioned, there is a certain amount of overhead associated with
  384. switching the processor from real to protected mode and back again.  In
  385. addition, there is some overhead associated with
  386. changing AutoLISP to multiple code segments.  On the positive side,
  387. additional node space makes memory management (garbage collecting) less
  388. critical.  Requests for more node space can usually be handled by
  389. allocating an additional node segment.  This causes less memory
  390. thrashing, and substantial time savings in execution of large functions.
  391. Function paging, enabled by (vmon) is also eliminated, which saves a
  392. considerable amount of processing.
  393.  
  394. Total performance is dependent on the activity and functions being
  395. called. From our limited testing thus far, it appears as though Extended
  396. AutoLISP runs at approximately the same speed as regular AutoLISP.  In
  397. addition, there are some optimization steps that may be taken to improve
  398. the performance of Extended AutoLISP (and regular AutoLISP for that
  399. matter).
  400. AutoLISP: Ask the Experts
  401. AutoCAD (r) EXPO '88
  402.  
  403. Techniques in Integrating AutoLISP
  404. B. Rustin Gesner
  405.  
  406. I was asked to join this panel from the perspective of the AutoLISP
  407. power user or even developer doing system customization. I'm probably
  408. no more expert than many of you, some of whom I've enjoyed the
  409. pleasure of exchanging ideas with on the Compuserve forum. If you
  410. don't use CompuServe, and you want to ask the experts, get online --
  411. that's where the experts meet every day.
  412.  
  413. AutoCAD without AutoLISP is like a Model T Ford -- a lot better than
  414. walking, but no Formula 1 race car. And, frankly a lot of users are
  415. still driving Model T class systems. We all keep asking for more
  416. "wishlist" new features, but most of us don't use 50% of what AutoCAD
  417. and AutoLISP can do already. And, while AutoLISP is certainly a key
  418. element in a high performance application system, you really should
  419. consider the whole vehicle.
  420.  
  421. Most parts of the AutoCAD environment have flexibility that
  422. customization can drive to greater productivity. In our Model T
  423. analogy:
  424.  
  425. AutoLISP, and often an external program, is the engine; and
  426.  
  427. AutoLISP is the Drive Train; while
  428.  
  429. Custom Menus Steer and control your application;
  430.  
  431. Hardware and memory management are the accelerators; and
  432.  
  433. Good Error Control and system management are your Brakes.
  434.  
  435. To comprehensively cover these topics would take a couple of weeks,
  436. or a couple of thick books, but we'll  touch on several key points.
  437. The examples I'll use are contained in this handout, so you can look
  438. at them more closely later. They are from the book, Customizing
  439. AutoCAD, which I'd like to point out is by no means all my own work.
  440. Joe Smith, who's showing structural software in his ACUWARE booth,
  441. co-authored the book, and Pat Haessly, who works for New Riders,
  442. contributed a lot. Remember, these examples may be out of context and
  443. you may need additional functions or instructions from the book to
  444. actually run them. Don't try to read all of these transparencies --
  445. they're just to focus attention on key items.
  446.  
  447. Let's look at the steering first. Menus provide most of the look and
  448. feel of your LISP programs. Controlling the MENUECHO and CMDECHO
  449. system variables can make very clean, professional applications. Menu
  450. design, and mixing menus and LISP can be controversial issues, but
  451. there are several key techniques. Menus control when and how choices
  452. are presented to the user. By using the MENUCMD function to call menu
  453. pages, and GRTEXT to present status labels in screen menu boxes, you
  454. can control and simplify the users choices. But don't overlook the
  455. use of the menu page change itself as a control point to load
  456. functions, or reset the environment. It is often easier and cleaner
  457. to provide this control in a menu than in AutoLISP. One caution -- if
  458. you integrate your menu with the standard AutoCAD menu, the user can
  459. destroy this control with tablet picks. The last chapter of
  460. Customizing AutoCAD tells how to deal with this and integrate menus.
  461.  
  462. NOTE: The parenthetical numbers like (1) refer to the pages of the
  463. handout material for this talk, which is material extracted from the
  464. book CUSTOMIZING AutoCAD. If you would like a copy of the handout,
  465. send an 8.5x11 envelope (4 stamps please), marked "HANDOUT" to New
  466. Riders Publishing, POB 4846, Thousand Oaks, CA 91360.
  467.  
  468. (1) A consistent and controlled user interface is also important on
  469. the AutoLISP input side. In the front of the handout is the UDIST
  470. User-getDIST function. UDIST is example of a function to present a
  471. consistent user input interface, and to simplify programming. It
  472. incorporates INITGET into the GET function, and handles displaying
  473. and returning a default value automatically. You just call it with
  474. the same values you would feed INITGET and GETDIST, plus a default if
  475. any.
  476.  
  477. That AutoLISP can be your application's engine is pretty obvious, so
  478. we won't dwell on that. What can get a bit trickier is integrating
  479. external programs. This is very dear to many developers, because the
  480. engines of their systems can be turbocharged compiled programs, which
  481. are easier to protect form theft, as well as a lot faster. This is
  482. also important to average users, whether you want to link in Lotus or
  483. dBASE, or an engineering program. Whether your engine is an external
  484. program or AutoLISP, AutoLISP is your drivetrain. It gets selection
  485. sets with SSGET, user input with the GET functions, system status
  486. with GETVAR and entity and table data with the entity and table
  487. functions.
  488.  
  489. To drive your external programs from AutoLISP, don't overlook the PGP
  490. link. You can define your own external commands in the ACAD.PGP file,
  491. and call them with the COMMAND function, like any other command. You
  492. can even call DOS batch files (or UNIX shells) via PGP. For simple
  493. data passing to your external program, consider command line
  494. parameters, which can even invoke replaceable parameters in a batch
  495. file. If you really get carried away, and nest your batch files,
  496. remember to use the COMMAND /C DOS call, or the CALL command in DOS
  497. 3.3 (see your DOS manual).
  498.  
  499. To output larger amounts of data, you currently have to OPEN a file,
  500. write or append to it with WRITE-LINE or WRITE-CHAR, or the print
  501. functions, and CLOSE it. This is all pretty straightforward, but the
  502. greater problem with linking your AutoLISP drive train up with
  503. external programs is getting data back in.
  504.  
  505. (2) While we hope to see direct data passing and random file access
  506. in the future, present techniques require a little planning for
  507. efficiency. Customizing AutoCAD covers several formats and
  508. techniques, and page 2 of the handout shows one of my favorites. For
  509. tabular data, consider your data file to be an array. Put each row of
  510. data on a separate line, enclosed as a list in the file by a pair of
  511. parentheses. Then, with the READ-LINE function you can quickly read
  512. it in, then convert it to a LIST with the READ function. Carrying it
  513. one step further, you can preface each line with a key code to search
  514. on, like the example's PIPE-1. Then you can quickly test the CAR of
  515. each READ READ-LINE, continuing to read in lines until you find the
  516. line you need.
  517.  
  518. Notice the use of the SET (instead of SETQ) function to set the read
  519. in PIPE-1 code to one of the data values. While SETQ sets a symbol to
  520. a value, SET evaluates it's first argument and sets its contents to a
  521. value. The ATTPIPE example uses the powerful but often overlooked
  522. MAPCAR function to take this one more step. By mapping the SET
  523. function to a list of symbols (PDIAM R FDIAM etc.) and a list of
  524. data, ARGLIST, you can simultaneously set an entire list of
  525. variables. MAPCAR is fast and efficient. The APPLY function can be
  526. similarly used on a data list read in in this manner. A case came up
  527. on CompuServe the other day. A user wanted to find the MAX of a
  528. number of values that were in the form of a list. The most efficient
  529. way is to use the APPLY function to apply the MAX function to the
  530. list. Other examples of MAPCAR and APPLY, some 3-D tools, are on
  531. pages 17 and 18 (sorry about the lack of page numbers). MAPCAR and
  532. APPLY are great for efficient handling of 2-D and 3-D points.
  533.  
  534. (3) While not for data I/O, the VFFILE, BACKUP, and MERGEF functions
  535. provide examples of AutoLISP file access, the use of AutoLISP to
  536. drive the AutoCAD FILES utility, and driving a SHell PGP operation.
  537. VFFILE verifies a file's existence (and it could use rewriting to
  538. take advantage of RELEASE 10's FINDFILE function. BACKUP backs up a
  539. file, and MERGEF merges or appends files through DOS. If you append
  540. to a file that has a <CTRL-Z> End-Of-File character, your appended
  541. data will be ignored by many programs. SHelling out and using DOS
  542. COPY handles the <CTRL-Z>. Other examples of DOS and AutoLISP
  543. integration in Customizing AutoCAD get much more involved, including
  544. programs to generate HATCH patterns, create SCRIPT programs, and
  545. automate Block updating. Which reminds me, our pattern generator
  546. doesn't currntly work with UNIX -- you've gotta watch out for the
  547. difference between back and forward slashes in SHELL processes. For
  548. portability, your application should check to see if it's on a UNIX
  549. or DOS system, and initialize a slash handling function accordingly.
  550.  
  551. (4) (5) Another important link between the user and AutoLISP, and/or
  552. external programs is a text screen help and input screen system. For
  553. professional 3rd party programs, you should call an external menu
  554. screen system through SHELL, but for in-house user programs the
  555. ANSI.SYS and AutoLISP format codes can do a lot. I won't go into
  556. detail, but pages 4 and 5 provide some food for thought.
  557.  
  558. If you are a professional C programmer and really want to get carried
  559. away, I suggest you read the ADI specification. It looks to me as if
  560. its applicability isn't limited to hardware device manufacturers, and
  561. you could develop some interesting linkages between AutoCAD, AutoLISP
  562. and external or TSR programs.
  563.  
  564. (6) A lot of AutoLISP's power comes from its selection set, entity
  565. access, table access and device access functions. They aren't really
  566. hard to use, so if you've not tried yet, give them a try.
  567.  
  568. SSGET with the "X" options is very efficient for selecting groups of
  569. entities by common attributes such as Entity type, Layer, Block name
  570. and others. Sometimes you want to further filter selection sets like
  571. these.
  572.  
  573. (7) For example, if you want to select all Circles on layer GREEN
  574. except those with linetype DASHED, pages 6 and 7 provide some
  575. functions for adding, subtracting and finding common entities in
  576. selection sets. The SSUNION and SSDIFF examples show the use of the
  577. SELECT AutoCAD  command to quickly merge or subtract two sets, rather
  578. than slowly stepping through them with AutoLISP and SSMEMB, which
  579. SSINTER must do. Notice the controlling of the HIGHLIGHT system
  580. variable to speed up selection on screen. The book also has functions
  581. to step backwards with LASTN, and to gather newly created entities
  582. with CATCH. CATCH allows you to easily select all entities created by
  583. Explode, for example.
  584.  
  585. (8) Although Extended AutoLISP takes some pressure off, Since
  586. everybody else is talking about memory management, good memory
  587. management can still accelerate your AutoLISP applications
  588. performance. I included page 8 with some suggested practices and
  589. alternatives. I also recently thought of a good technique, as yet
  590. untested, which I'll briefly outline. It's efficient to standardize
  591. and reuse variable names. Some users like to go further and use the
  592. same name for all substantial functions. Perhaps you call it ROUTINE.
  593. You control and execute it with a menu page for each program. Each
  594. time you call another major function, it wipes clean and redefines
  595. the previous one by LOADing the new one over top the old one. Each
  596. initial execution is slowed while it loads, a drawback. Subsequent
  597. executions of the new function are fast, since it is already loaded,
  598. until the next major function is called. Besides memory management,
  599. another advantage of this load-and-use technique is that your
  600. ACAD.LSP load is faster and you only load what you use.
  601.  
  602. Consider taking this one step further. Create a stack of five or six
  603. such function names, like ROUTINE1, ROUTINE2, ROUTINE3, and so on.
  604. Write a function to manage the stack and map the names to the menu
  605. calls. When the stack fills, the next function to load would
  606. overwrite the first, and the next the second, and so on. In this
  607. manner, you can have the advantages of self-cleaning load-and-use
  608. while having several of your most recently used functions quickly
  609. available. This idea should be effective whether you use CLEAN of
  610. VMON, current or future AutoLISP. (NOTE: I have since programmed this,
  611. and it will be included in a future edition of Customizing AutoCAD.)
  612.  
  613. Another simple, effective LOAD and management technique, which could
  614. be combined with the above, is the self-loading self defining
  615. function. This is in the last chapter of Customizing AutoCAD, and is
  616. credited to Phil Kreiker, of Looking Glass MicroProducts. Quite
  617. simply, in your ACAD.LSP file, major functions are DEFUNned as LOAD
  618. functions to load themselves. Then the first time they are called,
  619. whether by menu or keyboard, they load themselves. In the function
  620. file itself, you put a call to the function itself as the last line.
  621. Be sure to call it with a C: if it is a command function. Then for
  622. subsequent executions, it is already loaded and available.
  623.  
  624. (9) (10) Your brakes are a good set of error handling functions to
  625. keep the environment clean and consistent. AutoLISP's standard
  626. *ERROR* function is designed to be user redefinable, and pages 9
  627. through 12 of my handout show such a system. It's fairly self
  628. explanatory, so I won't go into detail, but the key points are:
  629. Resetting of system variables and Layers; Undoing lost entities and
  630. unfinished tasks; Prompts to the user; and printing of messages.
  631.  
  632. This error system allows a program to interactively add and remove
  633. items from its error recovery task list. The subroutines can also be
  634. used for general management and  resetting of the environment and
  635. Setvars.
  636.  
  637. (13) Like the earlier UDIST function, it's often useful to use  small
  638. standard functions for frequent tasks. For example, the DXF
  639. extraction function, on page (13) extracts a piece of entity data
  640. from an entity data list. I suppose it might be a tad less efficient
  641. executing than putting the code in line in every program that needs
  642. it, but it reduces code size and makes programs easier to read and
  643. write. It's slightly simpler to use (dxf 10 elist) to get a
  644. coordinate than (cdr (assoc 10 elist))
  645.  
  646. The BSCALE program, also on page 13, uses DXF and the UREAL (a
  647. similar GET function to UDIST). It is an example of entity access and
  648. modification, and does what AutoCAD cannot directly do: rescale an
  649. existing Block with independent X, Y and Z values. It's a simple
  650. example of the use of ENTSEL, to select an entity, ENTGET, to get its
  651. data, and our DXF and UREAL functions. Then it uses CONS to build the
  652. new new entity data scale values, SUBST to substitute them in the
  653. entity data list for the original values, and ENTMOD to redefine the
  654. entity in the database.
  655.  
  656. By the way, you could actually substitute UDIST for UREAL in BSCALE.
  657. Using GETDIST to get REAL values lets you "show" AutoCAD the value.
  658.  
  659. (14) As you get into more complex entity and table data access, you
  660. might find our DXF codes table on pages 14 and 15 useful. They gather
  661. together material otherwise somewhat scattered in the AutoCAD manual.
  662. Of course RELEASE 10 will require some changes to this table.
  663.  
  664. (19) Lastly, since we're all looking forward to RELEASE 10's full
  665. 3-D, I threw some examples of 3-D utility functions, formulas and
  666. diagrams in at the end. I'll leave you to peruse them on your own.
  667. Most aren't obsoleted by RELEASE 10.
  668.  
  669. If I get this far, I'm finished.
  670.