home *** CD-ROM | disk | FTP | other *** search
/ ftp.pasteur.org/FAQ/ / ftp-pasteur-org-FAQ.zip / FAQ / CAD / autolisp-faq / part1 next >
Encoding:
Internet Message Format  |  2004-05-01  |  53.8 KB

  1. From: rurban@x-ray.at (Reini Urban)
  2. Newsgroups: comp.cad.autocad,alt.cad.autocad,alt.answers,comp.answers,news.answers
  3. Subject: comp.cad.autocad AutoLISP FAQ (part 1/2) - general
  4. Reply-To: rurban@xarch.tu-graz.ac.at (Reini Urban)
  5. Followup-To: comp.cad.autocad
  6. Distribution: world
  7. Organization: TU Graz-Fac.of Architecture & X-RAY Graz
  8. Approved: news-answers-request@mit.edu
  9. Keywords: FAQ, AutoLISP, AutoCAD
  10. Summary: AutoLISP is a scripting language for AutoCAD, a wellknown CAD 
  11.   package. This AutoLISP FAQ is posted to comp.cad.autocad, alt.cad.autocad 
  12.   and *.answers monthly.
  13. NNTP-Posting-Host: oma.graz.inode.at
  14. Message-ID: <40936e25@e-post.inode.at>
  15. Date: 1 May 2004 11:30:13 +0200
  16. X-Trace: e-post.inode.at 1083403813 195.58.172.138 (1 May 2004 11:30:13 +0200)
  17. Lines: 1269
  18. Path: senator-bedfellow.mit.edu!bloom-beacon.mit.edu!news2.telebyte.nl!newsfeed.stueberl.de!newsfeed.utanet.at!newscore.univie.ac.at!e-post.inode.at!not-for-mail
  19. Xref: senator-bedfellow.mit.edu comp.cad.autocad:164733 alt.cad.autocad:148002 alt.answers:72708 comp.answers:57013 news.answers:270654
  20.  
  21. Posted-By: auto-faq 3.2.1.5
  22. Archive-name: CAD/autolisp-faq/part1
  23. URL: http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
  24. Version: 2.28
  25. Last-modified: 2002-06-25
  26. Posted-By: Reini Urban <rurban@x-ray.at>
  27. Posting-Frequency: monthly
  28. Copyright: see Appendix [A]
  29.  
  30.         Welcome to the comp.cad.autocad AutoLISP FAQ
  31.           by Reini Urban <rurban@x-ray.at>
  32.  
  33. Autolisp is a scripting language for AutoCAD, a well known CAD package. 
  34. This AutoLISP FAQ is posted to comp.cad.autocad, alt.cad.autocad and
  35. the *.answers groups monthly. Some AutoCAD FAQ's are at
  36. http://www.autodesk.com/support/autocad/ but not posted to
  37. comp.cad.autocad. The contents and the samples apply to all
  38. releases of AutoLISP since Release 10, including Visual Lisp, Vital Lisp
  39. and ACOMP. There's no special AutoLISP newsgroup.
  40. Best are comp.cad.autocad and autodesk.autocad.customization,
  41. but please don't bother comp.lang.lisp.
  42. Source code of all functions in this FAQ is in FAQ-CODE.LSP
  43. (for location see [A.1]), there's also a Winhelp file.
  44. Thanks to all who have contributed. Corrections and contributions
  45. always welcome. 
  46. Please see http://xarch.tu-graz.ac.at/acadwiki/RulesToLiveBy
  47.  
  48. This is part 1/2 of the AutoLISP FAQ v2.28, which consists of:
  49.  
  50.     AutoLISP FAQ (part 1/2) - General
  51.     AutoLISP FAQ (part 2/2) - Samples, code
  52.  
  53. | changes, + new in items from this version to the last posted version,
  54. intermediate personal comments and uncertainties in <..>
  55.  
  56.   -----------------
  57.   Table of Contents
  58.   -----------------
  59.   part 1:   General
  60.      [0] The Future of AutoLISP? Should I learn it or VB instead?
  61.        [0.1] What changed with AutoCAD 2000?
  62.        [0.2] We cannot create ARX anymore?
  63.      [1] Where can I find AutoLISP routines on the Internet?
  64.        [1.1] Are the comp.cad.autocad articles stored somewhere?
  65.        [1.2] Autodesk's SDK
  66.      [2] What are the best books to learn AutoLISP?
  67.        [2.1] Online AutoLISP documents, Winhelp [deleted]
  68.        [2.2] AutoLISP Coding Style
  69.      [3] How do I debug AutoLISP programs?
  70.         [3.1] Native AutoLISP debuggers
  71.         [3.2] Modular style, TRACE
  72.         [3.3] BREAK function, debug-print
  73.      [4] How can I protect my AutoLISP programs? Security
  74.        [4.1] Kelvinate
  75.        [4.2] Protect
  76.        [4.3] Kelvinate and Protect
  77.        [4.4] Convert
  78.        [4.5] ACOMP
  79.        [4.7] Lisp2C
  80.        [4.6] Vital LISP Professional
  81.        [4.8] Visual Lisp by Autodesk
  82.      [5] AutoLISP compilers
  83.        [5.1] ACOMP
  84.        [5.2] Vital LISP Professional
  85.        [5.3] Visual Lisp by Autodesk
  86.        [5.4] Better ones: Common Lisp and Scheme
  87.      [6] AutoLISP editors and other tools
  88.        [6.1] AutoLISP editors
  89.        [6.2] Analyzers, Packager and Parenthesis checkers
  90.        [6.3] Pretty Printers
  91.      [7] AutoLISP problems and bugs
  92.      [8] Sorting with AutoLISP
  93.      [9] Recursion
  94.      [10] Iteration with MAPCAR,...
  95. +    [11] S::STARTUP, My LISPs aren't loading at startup anymore
  96.      [12] How to AUTOLOAD my programs?
  97.      [13] How can I pass a variable number of
  98.           arguments to a LISP function?
  99.      [14] How can I avoid stack overflows?
  100.      [15] (command "ROTATE3D") does not work! Why?
  101.      [16] Lisp programs operating over multiple drawings
  102.      [17] How to export Visual Lisp functions to AutoLISP/AutoCAD?
  103.      --
  104.      [A] Disclaimer, Notes from the authors
  105.        [A.1] FAQ Locations
  106.  
  107.   part 2:   Samples, code
  108.      [20] General Helper functions
  109.        [20.1] List manipulation
  110.        [20.2] String manipulation
  111.        [20.3] symbol->string
  112.        [20.4] AutoCAD entity access
  113.      [21] Sample Lisp programs
  114.        [21.1] Globally change text, polylines, layer utils, date stamp
  115.        [21.2] Plot dialog from within LISP. Using DDE or ActiveX
  116.        [21.3] (entmod),(entmake) Layers, without (command "_LAYER"...)
  117.        [21.4] How to select multiple files in LISP? (as in FILES-Unlock)
  118.        [21.5] Replace multiple blocks
  119.        [21.6] (vports), VIEWPORT entity, pixel conversion
  120.        [21.7] Select all visible objects: zoom coordinates
  121.        [21.8] How to write XYZ data of selected objects to a file?
  122.      [22] Block Attributes
  123.        [22.1] How to access block attributes?
  124.        [22.2] How to MODIFY block attributes? DATESTAMP.LSP
  125.        [22.3] How to UPDATE block attributes?
  126.        [22.4] How to ENTMAKE a Block Complex Entity in AutoLISP
  127.      [23] Polylines
  128.        [23.1] How to access polyline VERTICES?
  129.        [23.2] How to JOIN multiple lines to polylines?
  130.        [23.3] Change WIDTH of multiple polylines
  131.        [23.4] Create a polyline or spline: with (ENTMAKE) or (COMMAND)
  132.        [23.5] How to calculate the LENGTH of polylines?
  133.        [23.6] How to revert the polyline direction?
  134.        [23.7] How to get the CENTER of a polyline?
  135.      [24] Circle/Arc Geometry:  BULGE conversion, some trigonometry
  136.      [25] DCL: listboxes with tabs or monotext font
  137.      [26] EED Extended Entity Data: Get and Store
  138.        [26.1] Select objects on their EED with (ssget "X")
  139.        [26.2] Get EED from an object
  140.      [27] How to break a command in LISP?
  141.        [27.1] How to do an unlimited number user prompts?
  142.      [28] How to decode ACIS internal geometry with LISP
  143.      --
  144.      [A] Disclaimer, Notes from the author
  145. +      [A.1] FAQ Locations
  146.      [B] Acknowledgements
  147.      [C] Recent Changes
  148.  
  149. ----------------------------------------------------------------------
  150. Subject: [0] The Future of AutoLISP? Should I learn it or VB instead?
  151.  
  152.   AutoLISP will be definitely supported in future releases.
  153.   VB was introduced to simplify Office Automation: ACAD <-> Excel/Access
  154.   Both languages have advantages and disadvantages. You should take a look
  155.   at both. VB seems to be more graphical and AutoLISP more logical. The
  156.   object concept of VBA seems to be easier to learn, but you cannot run
  157.   commands like in AutoLISP. The new VBA (>= R14.01) is extremely fast.
  158.   See also [5.2]
  159.   The future of AutoLISP already is Visual Lisp. For VLISP see [5.3]
  160.   URL's: http://www.autodesk.com/vlisp, 
  161.   http://www.autodesk.com/develop/devres/visual/faq.htm, also [0.1] below.
  162.  
  163.   [0.1] What changed with AutoCAD 2000?
  164.  
  165.   The name :) No, there's much more, but you may call it Release 2000, R15
  166.   (though 15 is the version number and not the release number),  A2000 or
  167.   abbrevated A2K.
  168.   The new Visual Lisp kernel (formerly "Vital Lisp") replaced the old 
  169.   xlisp-based AutoLISP kernel.
  170.  
  171.   What problems should you expect with Visual Lisp in R2000? (only the bad
  172.   news). At http://xarch.tu-graz.ac.at/autocad/docs/r2000-news.txt
  173.   I compiled a white paper. The major points are:
  174.   Stricter error checking on loading, ACAD.LSP vs ACADDOC.LSP,
  175.   You cannot/need not compile to ARX anymore, Incompatibilities
  176.   AutoLISP - Visual LISP: Lisp functions are atoms no lists anymore,
  177.   Protected symbols,
  178.   Better exception handling, Pathname of the loaded VLX?,
  179.   vl-export-symbol -> vl-doc-set, long acad symbol table names: EXTNAMES
  180.   ActiveX automation, Variants and SAFEARRAYs, FAS4 cannot be loaded on R14.
  181.  
  182.   [0.2] Why cannot I create ARX anymore?
  183.  
  184.   With AutoCAD 2000 you cannot do that anymore as with ViLL or VLISP 4.
  185.   Instead you compile to VLX (Visual Lisp Extension), which has basically
  186.   the same functionality as the old Visual Lisp/Vital Lisp ARX, with the
  187.   following differences:
  188.  
  189. * You'll have to (load) the app. Before you had to (arxload) it.
  190. - Pro: Initialization is easier. The VLX doesn't abort completely on any
  191.   error while loading. Before the whole ARX crashed with mysterious
  192.   errors.
  193. - Pro: VLX are much smaller because they don't carry the whole Lisp
  194.   environment, the VLRTS, along. Instead there's only one environment,
  195.   VL.ARX, distributed with acad itself. So you can ship much smaller
  196.   applications.
  197. - Contra: With loaded VLX there's no easy way to get the pathname of the
  198.   app. Before it was possible with (arx) or (vl-exe-filename)
  199.  
  200. * VLX has the option of seperate or common namespaces. With seperate
  201.   ARX you had only the option of seperate namespaces (in fact completely
  202.   seperate lisp environments).
  203. - Pro: This means that you can now choose the fastest and most secure
  204.   compilation mode (LINK, DROP) and still keep common namespaces. (most of
  205.   my apps benefit from this. I seperated my apps into one main module and
  206.   several smaller ones)
  207. - Pro: ARX is only compatible per release, thus completely incompatible!
  208.   VLX is new and therefore compatible only to newer releases (R16,...) but
  209.   as lisp application it is by far more compatible than a ARX app.
  210.  
  211. * Loaded ARX apps with (arx) return the pathname, loaded VLX apps with
  212.   (vl-list-loaded-vlx) only a symbol, no path. This is a design flaw.
  213.  
  214.   You don't need ARX modules anymore. This is a feature, no bug.
  215.  
  216. ------------------------------
  217.  
  218. Subject: [1] Where can I find AutoLISP routines on the Internet?
  219.  
  220.   The big AutoCAD tools sites with LISPs are:
  221.  
  222.   "AutoCAD Plugin Store" by beyond.com
  223.      http://www.cadplugins.com/
  224.      This is the by AutoDESK "officially recommended" tools site.
  225.   "CADalog" - The AutoCAD Shareware Clearinghouse (Mike Clark)
  226.     http://www.cadalog.com/
  227.   "The CAD Depot", formerly known as "cadsyst" or "Rolling Stock Software",
  228.     (David Whynot) recently bought by TenLinks.com 
  229.     http://www.caddepot.com/
  230.  
  231.   They are specialized in AutoCAD related software and have a very
  232.   good AutoLISP collection. Other professional AutoLISP shareware
  233.   sites post their URL's to the newsgroup too. 
  234.  
  235.   Other relevant sites are:
  236.   TenLinks (www.tenlinks.com) and the UpFront (www.upfrontezine.com) ezine
  237.   are the best CAD news services. Autodesk also started their portal site 
  238.   "Point A" at http://www.autodesk.com/pointa
  239.  
  240.   Some more sites with AutoLISP collections are:
  241.  
  242.   The CAD Users Webring
  243.     http://nav.webring.org/hub?ring=caduser&list
  244.   xarch AutoCAD Info & Tools (Reini Urban)
  245.     http://xarch.tu-graz.ac.at/autocad/    (with search)
  246.   CADalyst magazine code (compiled by "Hot Tip Harry" Art Liddle)
  247.     http://www.cadonline.com/code/   (with search)
  248.   Owen Wengerd
  249.     http://www.manusoft.com/
  250.   Terry Dotson
  251.     http://www.dotsoft.com/
  252. + AcadX
  253. +   http://www.acadx.com/
  254. + Paul Turvill
  255. +   http://www.turvill.com/t2/
  256.   Vladimir Nesterovsky
  257. |   http://vnestr.tripod.com/
  258.   Theo L.A. Groenenberg
  259.     http://members.xoom.com/acadvice/autolisp.htm
  260.   The CADshack (Jeff Foster)
  261. |   http://www.cadshack.com/
  262.   Lisp Factory (Jay Garnett)
  263.     http://www.enteract.com/~jgarnett/
  264.   Rakesh Rao - AutoCAD Tech Center
  265.     http://www.4d-technologies.com/techcenter
  266.  
  267.   Older or broken links:
  268.   AutoCAD Tech Journal code (Peter Sheerin)
  269.     http://www.atj.com/ (old)
  270.   CADENCE magazine code (Peter Sheerin)
  271. |   http://www.cadence-mag.com/ (fixed)
  272.   UCCB AutoCAD and AutoLISP page (Paul Standing)
  273.     http://ucad1.uccb.ns.ca/acad/cad.htm (broken)
  274.   McNeel's old lisp archive 
  275. |   ftp://ftp.mcneel.com/pub/lisp/ (fixed)
  276.   Dr.Lisp Utilities (Alexander Medwedew)
  277.     http://idt.net/~compvent/ (fixed)
  278.   SimTel - Coast To Coast - Archive (fixed, really very old stuff)
  279. |   http://www.simtel.net/pub/msdos/autocad.html
  280.  
  281. | At http://support.autodesk.com/ (moved) were documents from the 
  282.   Autodesk Product Support answering technical questions. (Their FAQ's)
  283. + The ASA (Support Assistance, some kind of FAQ) was once at 
  284. + http://www.autodesk.com/support/autocad/asa2000.htm, an improved but 
  285. + slow tool is now at http://support.autodesk.com/KnowledgeBase.asp.
  286.  
  287. [1.1] Are the comp.cad.autocad articles stored somewhere?
  288.  
  289.   There is no comp.cad.autocad archive or such a thing, but there
  290.   are some search machines which store news articles. In
  291.   particular:
  292.  
  293. | * http://groups.google.com/       - The biggest news archive
  294. |     formerly known as http://deja.com/usenet
  295.   * http://www.altavista.com/
  296.       http://www.altavista.com/cgi-bin/query?pg=aq&what=news
  297.   * http://www.excite.com/
  298.       http://www.excite.com/search.gw?collection=news
  299.   * Phoaks - People Helping One Another Know Stuff - Automatic Links Extractor
  300.       http://www.phoaks.com/phoaks2/newsgroups/comp/cad/autocad/index.html
  301.  
  302.   The Autodesk discussion forums have also a search feature at
  303. | http://discussion.autodesk.com
  304.  
  305.   Some specific older news postings are also stored at
  306.   http://xarch.tu-graz.ac.at/autocad/news/contents.html
  307.  
  308. [1.2] Autodesk's SDK
  309.  
  310.   Up to Release 12 a Software Development Kit was available directly
  311.   at Autodesk. The SDK1-2 was shipped with the international R12 for
  312.   free. It included a lot of ADS and AutoLISP source code and libraries.
  313.  
  314.   From R13 on Autodesk provides a special developers network, comparable
  315.   to Microsoft's, the ADN. The CD's are comparable to the old SDK but
  316.   are more targeted to ObjectARX developers.
  317.   Contact your nearest Autodesk headquarter for becoming a member.
  318.  
  319.   Some LISPs are at http://xarch.tu-graz.ac.at/autocad/code/adesk/SDK2
  320.  
  321.   In the US, ADN membership costs $600.00 per year.  The CDs don't include
  322.   any SDK per se, but most of the stuff in the original SDKs is included
  323.   in one form or another. (Owen)
  324.  
  325. ------------------------------
  326.  
  327. Subject: [2] What are the best books to learn AutoLISP?
  328.  
  329.   AutoLISP to Visual LISP
  330.     Kevin Standiford, Autodesk Press, ISBN 0-7668-1517
  331.   AutoLISP: Programming for Productivity,
  332.     William Kramer, Autodesk Press, ISBN 0-8273-5832-6
  333.   Essential AutoLISP,
  334.     Roy Harkow, Springer-Verlag, ISBN 0-387-94571-7
  335.   AutoLISP in Plain English, A Practical Guide for Non-Programmers,
  336.     George O. Head, Ventana Press, ISBN 1-566-04140-6
  337.   AutoLISP Reference Manual
  338.     Autodesk Press.
  339.     Up to R12 there was a separate AutoLISP Reference book. Then AutoLISP
  340.     became a part of the Customization Guide for R13. From R14 on this
  341.     guide is compiled as Winhelp.
  342.   Maximizing AutoLISP
  343.     Rusty Gesner, Tony and Mark Middlebrook, Tony Tanzillo.
  344.     A new Maximizing AutoLISP R13/R14 will be published hopefully
  345.     sooner or later. But the R12 book is still worth buying, though it's
  346.     difficult to find. More at http://www.group-a.com/~rusty
  347.  
  348.   There is a lot more AutoLISP books around.
  349.   Recommended general LISP books (not AutoLISP!) are:
  350.   ANSI Common Lisp, (Common Lisp primer)
  351.     Paul Graham, Prentice Hall, ISBN 0-13-370875-6
  352.   Structure and Interpretation of Computer Programs, (high-level Scheme)
  353.     H.Abelson, GJ. Sussman, J. Sussman, MIT Press, ISBN 0-262-01153-0
  354.     "This undoubtedly one of the best general computer books ever written."
  355.   LISP, 3rd Edition,
  356.     Patrick Henry Winston and Berthold Klaus Paul Horn,
  357.     Addison-Wesley Publishing Company, ISBN 0-201-08319-1
  358.   Looking at LISP,
  359.     Tony Hasemer, Addison-Wesley Publishing Company, ISBN 0-201-12080-1
  360.  
  361.  
  362. [2.1] Online AutoLISP documents, Winhelp [deleted]
  363.  
  364. [2.2] AutoLISP Coding Style
  365.  
  366.   Most of the samples being published by magazines or at various
  367.   websites are written badly making the AutoLISP learning process even
  368.   harder for newbies. LISP is hard to read anyway because of it's
  369.   briefness and countless parentheses. Everybody is enforced to
  370.   write clear, readable code. Autodesk's samples are quite well written
  371.   but sometimes overdone. :)
  372.  
  373.   Automatic pretty printers, or so called beautifiers (see
  374.   [6.3]) automatically format the code according to some kind of standard.
  375.  
  376.   On the R12 CD-ROM in the SDK2 ACG.DOC or at
  377.   http://xarch.tu-graz.ac.at/autocad/docs/acg.txt is an excellent
  378.   Autodesk documentation about coding, commenting and intentation standards
  379.   to keep lisp code readable.
  380.  
  381.   The most important points are:
  382.   * Comment your code using ";;;" at row 1, ";;" inside the code
  383.     (indented) and ";" for trailing comments (at row 39)
  384.   * Follow the indenting standards as given by the pretty printers
  385.     to be able to write better structured code, which is more readable.
  386.       esp. for SETQ, DEFUN, IF, COND, PROGN
  387.   * Try to avoid global variables. If you use them (for efficiency), to
  388.     clarify, place asterics around them in uppercase, i.e: *GLOBAL*
  389.   * Don't forget to localize your variables (behind "/" in the DEFUN
  390.     parameter list). Only for debugging purposes you may want to
  391.     undefine them temporarly.
  392.   * Name protection: Since AutoLISP provides no protected name space,
  393.     it's easy to overwrite even system functions. Use unique
  394.     short prefixes at least when you publish or give away your code.
  395.     I use UR- for functions and UR: for variables. The ADGE and Autodesk
  396.     forces even 4 letter prefixes. Then your names are safe
  397.     from being overwritten by other kamikaze functions.
  398.   * Always use the leading underscore with any string (commands and
  399.     options) given to COMMAND and OSNAP. There are even enough
  400.     commercial programs which do not work on international versions.
  401.     (command "_PEDIT" ss "_J") is better than (command "PEDIT" ss "J")
  402.   * Don't do too much SETQ's: LISP was originally a functional language,
  403.     without any variables. There are enough constructs which work
  404.     efficiently with lists without the need of storing values
  405.     intermediatly in symbols. (see code samples [22]...)
  406.     But for readability and debugging purposes you should always set
  407.     symbols.
  408.   * An old LISP rule is: Any good function is not longer than 6 lines :)
  409.     (LISP is the second oldest computer language, invented by John
  410.     McCarthy at the MIT in 1958)
  411.   * Prefer CONS over APPEND: three CONS and one REVERSE is better than
  412.     one APPEND. For tricks with APPEND (omitting NIL) see esp. Serge's
  413.     samples: i.e. REMOVE at [11] or the style comparison at [23.1])
  414.   * Try to use English symbols and comments
  415.   * Don't use T, MIN, MAX or LAST as symbols! These are system functions!
  416.  
  417. ------------------------------
  418.  
  419. Subject: [3] How do I debug AutoLISP programs?
  420.  
  421. [3.1] There are some native AutoLISP debuggers:
  422.  
  423.   * Visual Lisp by Autodesk and Vital Lisp Professional support
  424.     it in the IDE (the best),
  425.   * ACOMP for R10 had one, (free)
  426.      you can still use it with R12 DOS, but then you've got only the R10
  427.      LISP functions, i.e. no WCMATCH function,
  428.   * Ld, AutoLISP Debugger for R14, R13c4 and R12/DOS from CZ,
  429.     (free) at http://www.cadstudio.cz/ftp.htm
  430.  
  431.   See "[5] AutoLISP compilers"
  432.  
  433. [3.2] Modular style, TRACE
  434.  
  435.   The best support you can have for debugging is write your
  436.   code in a well designed, modular style, pulling out distinct
  437.   tasks into separate functions and then liberally using
  438.   nested function calls. This will allow you to use the
  439.   TRACE function as needed to locate any errors.
  440.  
  441. [3.3] You may include BREAK functions and debug-print into your source
  442.   code.
  443.  
  444.   Examples:
  445.  
  446.   ;;; Debugging functions
  447.   (defun break (s)
  448.     (if *BREAK*
  449.       (progn
  450.         (princ "BREAK>> (stop with <Enter>)\nBREAK>> ")(princ s)
  451.         (while (/= (setq s (getstring "\nBREAK>> ")) "")
  452.           (print (eval (read s)))))))
  453.   (defun dbg-print (s)  ;accepts atoms and lists
  454.     (if *DEBUG*
  455.       (if (listp s)
  456.         (MAPCAR 'print s)
  457.         (print s))))
  458.   (defun C:DEBUG () (setq *DEBUG* (not *DEBUG*)))  ;switch it on and off
  459.   (defun C:BREAK () (setq *BREAK* (not *BREAK*)))
  460.   (defun CONT () (setq *BREAK* nil))    ;cont. without any interruption
  461.  
  462.   For a usage example see:
  463.     http://xarch.tu-graz.ac.at/autocad/news/break_ex.lsp
  464.  
  465. ------------------------------
  466.  
  467. Subject: [4] How can I protect my AutoLISP programs?
  468.  
  469.   "You really have to protect it? If you just want to share routines
  470.   with friends, why not give them the code? Working with others
  471.   can be a great way to get new ideas and lead to a better
  472.   application. Some of the best utilities were improved by my friends
  473.   or I have improved some of my friends utilities." (Dennis)
  474.  
  475. [4.1] Kelvinate
  476.     with KELV.EXE (on the R12 CD-ROM or at the AutoLISP sites "[1]").
  477.     Free. De-Kelvinate LISP's with any pretty printer, see [6.3].
  478.     Symbol names (functions and variables) will stay garbled and comments
  479.     are lost.
  480. [4.2] Protect
  481.     with PROTECT.EXE (on the R12 CD-ROM or at the AutoLISP sites "[1]")
  482.     Note that unprotectors exist. Free.
  483. [4.3] Kelvinate and Protect
  484.     First kelvinate, to make it unreadable, then protect. Free.
  485. [4.4] Convert
  486.     Shareware LISP En-/Decryptor by Maciej Lukasiewicz, Sweden.
  487.     With Convert encrypted "Protected Lisps" cannot be decrypted by other
  488.     programs, but by Convert it can.
  489. [4.5] ACOMP
  490.     AutoLISP compiler ACOMP.EXE, on the R12 international release or
  491.     at the AutoLISP sites. Free. More docs about ACOMP are at
  492.     http://xarch.tu-graz.ac.at/autocad/bi4/  See also [5.1]
  493. [4.6] Vital LISP Professional
  494.     Formerly at http://www.basissoftware.com/vill.htm [broken]
  495.     Say "ViLL". Outdated. See also [5.2]
  496. [4.7] Lisp2C
  497.     LISP to C converter, for R12/R13/R14 Dos/Win (Watcom, Metaware,
  498.     MSVC Libs). You need to own such a C/C++ compiler. Quite expensive.
  499.     http://www.basic.si
  500. [4.8] Visual Lisp by Autodesk
  501.    say "VLISP". see [5.3]
  502.  
  503.  
  504.   FAS Security:
  505.     There was recently a lengthy discussion about FAS security at both
  506.     newsgroups. Apparently FAS can be decompiled to readable source code,
  507.     but this tool is not available on the net yet. Rumors say that MNC
  508.     files can also be decompiled for years now but this doesn't exist the
  509.     net either.
  510.     Linked and dropped FAS/VLX (compiled with Optimized/Internal) is
  511.     similar to Kelvination.
  512.     Symbol names, strings and numbers are more insecure than algorithms.
  513.   Summary:
  514.     Serious encryption is only done with Vital LISP and its successors.
  515.     Kelvinating makes LISP files unreadable and load faster.
  516.     Protected lisp files can be easily decrypted. With
  517.     Convert -e$GUARD encrypted LISPs can be unprotected only with Convert.
  518.  
  519. ------------------------------
  520.  
  521. Subject: [5] AutoLISP compilers
  522.  
  523.   There are three AutoLISP compilers, better ones could maybe used in the
  524.   future. Some Lisp and Scheme platforms already do or will support ActiveX
  525.   or just a simple FFI.
  526.  
  527. [5.1] ACOMP
  528.     ACOMP was supported up to R12 for the international releases only.
  529.     It is free, and doesn't work with R13 nor with domestic R12/Win.
  530.     It produces .BI4 files and needs special ACADL.EXP supplied as
  531.     ACADLC.EXP     See http://xarch.tu-graz.ac.at/autocad/bi4/
  532. [5.2] Vital LISP Professional
  533.     by Basis Software Inc. USA.
  534.     Basis doesn't continue developing Vital Lisp anymore.
  535.     License-free runtime modules for R12/R13/R14 DOS/Windows/NT
  536.       See http://www.basissoftware.com/vill.htm
  537.     Some dealers still have it on stock. The latest version was 3.2. The
  538.     R14 version (ViLL 3.x) includes ActiveX (like VB) and reactor
  539.     support. See also [6.1] and [4.6]
  540. [5.3] Visual Lisp by Autodesk
  541.     VLISP 4 (for R14), the successor of Vital Lisp, is basically the same
  542.     as ViLL 3.2, only the GUI, some function names and the docs changed:
  543.       vill- => vlisp-, the vlx- => vl- prefixes.
  544.       Some vlax- funcs have more hyphens.
  545.     With AutoCAD 2000 VLISP replaced the old AutoLISP engine. See [0.1]
  546.     VLX files are packaged FAS files with optional DCL resources, used
  547.     by R14/R15.
  548.     AutoCAD 2000 FAS/VLX are incompatible with previous releases
  549.     (FAS2 -> FAS4) because of added language features (seperate namespaces)
  550. [5.4] Better ones: Common Lisp and Scheme
  551.     Native ARX exists for Corman Common Lisp (a simple console),
  552.     COM support for Allegro Common Lisp 5, Lisp Works for Windows and in
  553.     the future for GambitC.
  554.     Via a FFI ("Foreign Function Interface") almost every lisp or scheme
  555.     can communicate with AutoCAD.
  556.     See http://xarch.tu-graz.ac.at/autocad/lisp/ffis.html
  557.     Little work is done with Corman Lisp and ACL5, one commercial product
  558.     uses ACL5 ("Design++" by Design Power http://www.dp.com/)
  559.     See http://xarch.tu-graz.ac.at/autocad/bi4/ for more.
  560.  
  561.   Summary:
  562.     AutoLISP compilers are bytecode compilers needing a runtime system.
  563.     AutoCAD 2000 uses VLISP now, so the runtime system is included.
  564.     You cannot create standalone programs, though ViLL/Vlisp (<=R14)
  565.     creates a stand-alone ARX. The symbols are encrypted.
  566.  
  567. ------------------------------
  568.  
  569. Subject: [6] AutoLISP editors and other tools
  570.  
  571. [6.1] AutoLISP editors
  572.   Visual Lisp by Autodesk
  573.     see [5.3]. The best and most recommended tool. With AutoCAD 2000 it
  574.     is included for free.
  575.   Emacs for NT
  576.     Huge editor and quite hard to learn but it's written and
  577.     customizable in LISP. Free, for all platforms. Comes in two flavors,
  578.     www.xemacs.org or the GNU emacs for NT.
  579.     Check out http://xarch.tu-graz.ac.at/autocad/lsp_tools/ntemacs.html
  580.   Vital LISP 
  581.     outdated by Visual Lisp. Not available anymore
  582.   LispLink 2000
  583.     Commercial AutoLISP Editor with Syntax Highlight, Parenthesis 
  584.     Checking, Project Manager, Dialog Preview, and Support for Visual 
  585.     LISP Functions and FAS Compilation. http://www.caelink.com/
  586.   CodeMagic
  587.     Shareware text editor with AutoLISP syntax highlighting.
  588.  
  589. Old stuff:
  590.   LispPad
  591.     AutoLISP Editor by Tony Tanzillo.
  592.   Visual LISP by WSSW
  593.     Old small Windows LISP Editor, Version 1.0 was even free. See [1]
  594.   WCEDIT 2.02
  595.     Old ADS editor for DOS R12, can evaluate lisp code from within the
  596.     editor, free.  See [1]
  597.   CODEKEY
  598.     Old commercial DOS IDE, internal pretty printer, protect, unprotect,
  599.     kelvinator. Still available?
  600.   ALLY 3.0 and CADET
  601.     Shareware LISP Analyzer and Editor. See [6.2]
  602.   pred
  603.     free, small dos editor which provides parenthesis highlighting.
  604.     At ftp://xarch.tu-graz.ac.at/pub/autocad/lsp_tools/pred.zip
  605.     A similar editor is ADE.
  606.   LSPEDIT from xlisp-stat
  607.     A simple free Windows Lisp editor that supports parenthesis matching and
  608.     code indentation.
  609.     Check out http://www.stat.umn.edu/~luke/xls/xlsinfo/xlsinfo.html
  610.  
  611.   General customizable programming editors like MultiEdit Pro,
  612.     WinEdit, E!, PFE, TextPad, UltraEdit or PFE are widely used also.
  613.     They usually don't provide Lisp syntax checking or pretty printing,
  614.     but (some even regular expression) multi-file search/replace and
  615.     customizable syntax highlighting.
  616.  
  617.   There are others not that good (ADE) nor I don't have a description
  618.   yet.
  619.  
  620. [6.2] Analyzers, Packagers and Parenthesis checkers
  621.   Parenthesis checkers should not be used anymore. Editors should do the
  622.   job. Analyzers generate a function cross-reference, the calling and the
  623.   reverse callers tree. Packagers are used to generate libraries from
  624.   various source files, copying all the needed functions.
  625.   There's currently no code-walker which can internationalize command
  626.   strings, but with R15 came a lisp analyzer (LCA).
  627.  
  628.   VLISP's [5.3] compiler analyses (compile with full messages) and
  629.     checks parens <Ctrl-Alt-C>
  630.   Reini's AutoLISP Packager
  631.     http://xarch.tu-graz.ac.at/autocad/lsp_tools/#Packager
  632.     Browsable function cross-referencer, reverse calling tree, creates a
  633.     library from source files. ("Packaging" or "Function Shaker")
  634.   PEI Findvars
  635.     Similar to the Packager above, but not only functions, additionally
  636.     detects symbols to be localized. http://www.perceptual-eng.com
  637.     I personally use this.
  638.   RapidLisp v1.0c [new]
  639.     Shareware Lisp analyser fⁿr R14. http://www.cps.de/cad/rapidlisp/
  640.   AVC - AutoLISP Variable Collector [new]
  641.     Freeware, finds all variables to be declared per function.
  642.     http://users.actcom.co.il/sysoft/vc.htm
  643.   LCA - Autodesk's AutoLISP Compatibility Analyzer
  644.     On the Migration CD. Details AutoCAD 2000 compatibility issues found 
  645.     in specified AutoLISP (LSP) or Menu LISP (MNL) files. (simple "Code Walker")
  646.  
  647.   ALLY30.ZIP (old)
  648.     Shareware LISP analyser. Checks syntax and prints statistics, function
  649.     dependence tree and used symbols, but no packaging. At [1]
  650.   lck21b.zip (old)
  651.     LCK LISP Checker 2.1b (graphical)
  652.   paran.zip  (old)
  653.     Simple
  654.   PARNCH.ZIP (old)
  655.     Simple
  656.   There are also some AutoLISP programs which count parenthesis.
  657.  
  658. [6.3] Pretty Printers
  659.   External:
  660.     FMT202S.ZIP
  661.       LISP, DCL and FRM source code formatter. Not checked yet.
  662.     LB.EXE
  663.       Autodesk's source code beautifier.
  664.       In the SDK2 or at [1]. Has problems with longer strings,
  665.       and new-style in-line comments.
  666.     PPRINT.LSP
  667.       In the SDK2, see [1.2], or at [1]
  668.   Internal:
  669.     Visual Lisp, Vital LISP, Emacs and Codekey provide internal
  670.     beautifiers as I'm aware of it.
  671.  
  672. ------------------------------
  673.  
  674. Subject: [7] AutoLISP problems and bugs
  675.  
  676.   For AutoCAD 2000 and unexperienced VLISP users see [0.1].
  677.   There are almost no known serious AutoLISP bugs. The language
  678.   interpreter itself (ACADL.EXE/.EXP, VLISP) works undoubtedly well.
  679.   Some restrictions are based on the AutoCAD, ActiveX or the Proteus
  680.   (DCL) engine. Some support LISP programs (i.e. DDMODIFY.LSP) are
  681.   faulty sometimes.
  682.   For Visual Lisp see the README.txt which lists all known bugs and
  683.   limitations. Crashes with reactors are ACAD bugs.
  684.  
  685.   Two inofficial buglists are at:
  686.   http://www.cadonline.com/exclusive/bugs/bugwatchlist.htm (the big one)
  687.   http://www.dotsoft.com/buglist.htm (a private and short one)
  688.  
  689.   * LDATA  by Tom Berger     (VLISP for R14 and A2000)
  690.     In short: Don't use LDATA at all. It may destroy DXF and DWG's 
  691.     in A2000. It is also VERY hard to get rid of them.
  692.  
  693.   * List Arguments with DOTTED PAIRS Passed from AutoLISP to
  694.     Visual LISP or back may loose the outer parens.
  695.     See the Visual Lisp README (undocumented in Vital Lisp)
  696.  
  697.   * SINGLE ATOM LISTS returned incorrectly from EXTERNAL APPS
  698.     Visual LISP can not distinguish between a LIST of a single
  699.     atom (element), and a single atom returned from an external
  700.     ObjectARX or ADS application.
  701.  
  702.   * ENTGET used with LWPOLYLINE, HATCH  (R14 only)
  703.     The Z coordinate (caddr (getval 10 ele)) is a random number and
  704.     often causes a floating point exception because it may too low or
  705.     too high. Workaround: see part 2, Subject [23.1]
  706.  
  707.   * ENTMAKE VERTEX  by Terry Dotson     (R14 only)
  708.     A problem can occur during the process of using (entmake) to create
  709.     polylines, you must assign the layer to each of the VERTEX 
  710.     definitions (which Autodesk has told us), but you must also assign 
  711.     the layer to the ending SEQEND. Absence of this will cause the SEQEND 
  712.     to end up on the current layer, which can be later frozen. Attempts to
  713.     move this piece of geometry will then cause a EREGEN error and crash 
  714.     in R14 (only).
  715.  
  716.   * ACAD_STRLSORT: Strange sort order in Windows.
  717.     The chars in Windows are not sorted on its ASCII representation!
  718.  
  719.       Windows: (acad_strlsort '("-1" "+1")) -> ("-1" "+1"),
  720.       DOS:     (acad_strlsort '("-1" "+1")) -> ("+1" "-1")
  721.       Both:    (mapcar 'ascii  ("-" "+"))   -> (45 43)
  722.     More at http://xarch.tu-graz.ac.at/autocad/docs/strlsort-bug.html
  723.  
  724.   * AI_PROPCHK
  725.     (ai_propchk) was renamed to (C:AI_PROP) in the R13c3 update
  726.     patch. "The AutoLISP function ai_propchk has been changed to c:ai_prop
  727.     so that it behaves similarly to other commands. This allows pressing
  728.     return to bring back DDMODIFY if selected from the toolbar."
  729.  
  730.   * Faulty action callbacks in R13 DCL code crash AutoCAD
  731.     There is a bug in R13 where AutoCAD crashes with a Fatal Error if
  732.     an error occurs in AutoLISP code during an action callback from a
  733.     scroll bar in a dialog box.  For instance, if you try to evaluate a
  734.     null function during the callback, AutoCAD crashes instantly.
  735.     Technically, this isn't a bug in the AutoLISP interpreter, but we
  736.     would still call it an AutoLISP bug.
  737.  
  738.   * You cannot rely on bitvalue 64 in flag 70 in symbol tables anymore
  739.     since R13, but in all previous releases. Inserted blocks may have 
  740.     64 not set.
  741.  
  742.   What else? See the unofficial AutoCAD buglist compiled by Steve
  743.   Johnson for more faulty AutoLISP programs and behaviours, at
  744.   http://www.cadonline.com/exclusive/bugs/bugwatchlist.htm
  745.  
  746.   * Protected LISP Files
  747.     In pre-c4a R13 protected LISP files didn't stay protected in
  748.     memory. In our opinion, this problem needs to be made known to all, so
  749.     developers don't inadvertently assume their protected code is
  750.     safe from prying eyes. This FAQ topic caused a major problem in
  751.     moderated CompuServe's AutoCAD Forum.
  752.  
  753.   * Limited number of open selection sets
  754.     They are intermediatly stored in temporary files. Get rid of not
  755.     needed selection sets with setting the symbols to nil and run (gc),
  756.     the garbage collector, which actually closes those files then.
  757.     The maximal number depends on the operating system, i.e. in DOS
  758.     of the FILES= value in CONFIG.SYS. R13 improved the number.
  759.  
  760.   * Numbers: range, accuracy, numerical precision
  761.     Integer numbers are internal long fixnums (signed, 32-bit), but the
  762.     communication from AutoLISP to AutoCAD accepts only 16-bit short
  763.     fixnums, in the range -32768 .. +32767, because AutoCAD needs only
  764.     short fixnums.
  765.     Floating point numbers are doubles (64-bit IEEE). All internal
  766.     AutoLISP and AutoCAD numerical calculations work with this double
  767.     format, which should be sufficient. At least the first 14 decimal
  768.     places are exact.
  769.     A common problem is the confusion betwen the actual number (exact)
  770.     and the rounded string representation. The number which is shown on
  771.     the command-line is always the rounded string which takes care of
  772.     LUPREC and DIMZIN.
  773.     However with geometric comparisons there often occur round off errors,
  774.     so that it's wise to compare points with a small fuzz factor 
  775.     [1e-12..1e-6].
  776.       (equal pt1 pt2 1e-6)      ; 0.000001 rounding error tolerance
  777.     instead of (equal pt1 pt2), esp. with angles.
  778.     See also http://www.autodesk.com/support/techdocs/td30/td301207.htm
  779.  
  780.     VB: It was also reported lately, that with certain automation
  781.     controllers loaded, numerical accuracy and locale issues (`,┤ vs `.┤)
  782.     had undesirable sideeffects. A solution and explanation of this 
  783.     problem is pending. (Mostly in `,┤ as decimal delimiter countries 
  784.     such as Germany)
  785.  
  786.   * ACOMP's (EQ) strictness
  787.     With [5.1] ACOMP's compiled code you have to take care that the
  788.     (EQ) behaviour in BI4's is much stricter than in plain AutoLISP. In
  789.     AutoLISP (eq "1" "1") is T where in ACOMP's compiled code it's nil.
  790.  
  791.   The following are not real bugs, that make AutoLISP crash or return
  792.   false results. They are just bad language implementations.
  793.  
  794.   * AND and OR should return the value of the not-NIL argument
  795.     instead of T. See http://xarch.tu-graz.ac.at/autocad/docs/and-bug.html
  796.   * MAX and MIN should handle string types too, because < and >
  797.     accept and process strings types too.
  798.   * see ACAD_STRLSORT above.
  799.   * for stack overflow errors see [14]
  800.  
  801. ------------------------------
  802.  
  803. Subject: [8] Sorting with AutoLISP
  804.  
  805.   In short: use VL-SORT (generic) or ACAD_STRLSORT (strings only),
  806.   but beware: VL-SORT removes duplicate entries (which are EQ)!
  807.   
  808.   I've set up a AutoLISP sort overview at
  809.     http://xarch.tu-graz.ac.at/autocad/lisp/#sort
  810.   In LISP the mostly used sort method is merge sort (also used in
  811.   (str-sort) in AutoDesk's TABLES.LSP sample) because that's a natural
  812.   method for linked lists. Normally (e.g. in C) you use heap sort (for 
  813.   any data) or qsort (for random data) and insertion sort for the small
  814.   lists (< 7) or sublists within the algorithm.
  815.  
  816.   There is a LISP code for shell-sort, bubble-sort, insertion-sort,
  817.   quick-sort available for any data, lists of lists and indeces to
  818.   lists. In LISP you can pass the predicate function to sort which is
  819.   evaluated at run-time (here called 'method'). That's why you need
  820.   only one sort function for multiple data types (i.e. numbers,
  821.   points on x or y, strings, ...)
  822.  
  823.   (sort data method)    ;method: less-than-predicate
  824.                         ;default for numbers: '<
  825.  
  826.   Some sample timings from
  827.   http://xarch.tu-graz.ac.at/autocad/lisp/sort/ur_sort.lsp
  828.   sorting 100 elements:
  829.     bubble sort   : 13.639008 sec/ 30.08%
  830.     insertion sort: 13.368042 sec/ 29.48%  (fast for sorted lists)
  831.     shell sort    : 13.478973 sec/ 29.73%  (poor implementation)
  832.     merge sort    :  2.232971 sec/  4.92%
  833.     quick sort    :  2.433960 sec/  5.37%
  834.     vl-sort       :  0.099976 sec/  0.22%  (Visual/Vital LISP internal)
  835.     acad_strlsort :  0.089996 sec/  0.20%  (AutoLISP internal, strings)
  836.  
  837. ------------------------------
  838.  
  839. Subject: [9] Recursion
  840.  
  841.   This is not an often asked question but a very interesting one,
  842.   because LISP itself is defined recursively and it's often the
  843.   easiest way to articulate hard problems.
  844.  
  845.   There some fine documents about recursion at
  846.   http://xarch.tu-graz.ac.at/autocad/lisp/ especially the
  847.   http://xarch.tu-graz.ac.at/autocad/lisp/recursive.html tutorial by
  848.   Dennis Shinn.
  849.  
  850.   It explains in great detail:
  851.  
  852.   (defun fact (n)
  853.     (cond
  854.       ((zerop n) 1)
  855.       (T (* n (fact (1- n))))))
  856.  
  857.   Note: There's also a self-modifying example of this function
  858.   explained at http://xarch.tu-graz.ac.at/autocad/lisp/self-mod.lsp
  859.  
  860. ------------------------------
  861.  
  862. Subject: [10] Iteration with MAPCAR,...
  863.  
  864.   Same as with recursion this is not a often asked question, but it's
  865.   quite hard to understand too.
  866.   Iterative statements in AutoLISP are: WHILE, REPEAT, FOREACH and
  867.   MAPCAR. We use them widely in this FAQ code because they allow
  868.   brief code.
  869.  
  870.   There's a short course in LAMBDA, QUOTE, MAPCAR... by Vladimir
  871.   Nesterowsky:
  872.  
  873.   >>         "There are 14 paths and 12 pigs.
  874.   >>         How can there be 24 ducks?"
  875.   >> Is there a lisp command that will allow me to pick these
  876.   >> lines of text, and recognize the number(s) in each line,
  877.   >> in order to, say, raise each number by two?
  878.   >> Leaving the sentence structure, etc, intact?
  879.   This is one way. (I am sure there are many other ways)
  880.  
  881.   (defun mult2 (strng)          ; by Vladimir Nesterowsky
  882.     (strlgather
  883.       (mapcar
  884.        '(lambda (s / n)
  885.           (if (zerop (setq n (atof s)))
  886.             s
  887.             (rtos (* n 2))))
  888.         (strlparse strng " "))  ; parse by spaces
  889.       " "))                     ; gather back with spaces
  890.  
  891.  is explained at http://members.tripod.com/~vnestr/mapcar.txt
  892.  
  893.   ;;; flip rows and columns in a matrix
  894.   (defun transpose(l)           ; by Doug Wilson
  895.     (apply 'mapcar (cons 'list l)))
  896.  
  897. is explained at http://xarch.tu-graz.ac.at/autocad/lisp/transpose.002.html
  898.  
  899. ------------------------------
  900.  
  901. Subject: [11] S::STARTUP, My LISPs aren't loaded at startup anymore
  902.  
  903.   LISP files can be loaded at the startup using LOAD in ACAD.LSP.
  904.   Some LISPs, required with a menu to work, should be loaded from
  905.   the corresponding <menu>.MNL file. The <menu>.MNL file - if different -
  906.   should load ACAD.MNL
  907.  
  908.   LISP functions calling commands at the startup should be defined in
  909.   S::STARTUP of ACAD.LSP. This function is called at the startup
  910.   after the initialization automatically. Otherwise you'll get the
  911.   "Command list interruption (6 . 2)" errors.
  912.   Note: (command) may be safely called from within MNL files. 
  913.   (S::STARTUP) is mainly used to check for partial menus now.
  914.  
  915.   If the file name was provided without an extension the LOAD function
  916.   assumes .LSP. If - without a path prefix, the usual AutoCAD library path
  917.   is used, which is
  918.     1) The current directory
  919.     2) The directory containing the current drawing file
  920.     3) The directories defined in the ACAD environment variable
  921.        (setup in the Preferences box, SUPPORT paths)
  922.     4) The acad.exe directory
  923.   If your program isn't loaded anymore automatically, check your AutoCAD
  924.   library path settings.
  925.  
  926.   With ACADLC (of ACOMP) and the domestic release of AutoCAD R12 ACAD.LSP
  927.   is not loaded automatically. Therefore you must append (load "ACAD" -1)
  928.   to your ACAD.MNL.
  929.  
  930.   Sample ACAD.LSP:
  931.   ;;;ACAD.LSP
  932.   ;;; Fred the Beaver, 12/12/94
  933.   (load "init" -1)                ; this loads some tools of mine
  934.   (defun S::STARTUP ()
  935.     (load "new-end" -1)           ; this redefines the END command
  936.   )
  937.  
  938.   The -1 argument provides LOAD from interrupting the startup process, if
  939.   any LOAD failure (causing an AutoLISP error). If a failure at the
  940.   load-time occurs, -1 is returned, but the evaluation does not stop.
  941.   -1 can be any expression as well.
  942.  
  943.   Sample code to enhance S::STARTUP in your code. With Visual LISP
  944.   compiled code this will not work, it must be defined with DEFUN-Q
  945.   instead. Functions are generally no lists anymore! Better than to
  946.   use DEFUN-Q for S::STARTUP is to check for known hooks, a list of
  947.   user-defined functions which are inserted and evaluated at run-time.
  948.  
  949.   (defun MY::STARTUP ()         ;your startup code goes here
  950.     ;..
  951.     (princ))
  952.  
  953.   (setq S::STARTUP
  954.     (if (and S::STARTUP (listp S::STARTUP))     ;already defined in
  955.                                                 ; ACAD.LSP or elsewhere
  956.       (append S::STARTUP (cdr MY::STARTUP))     ;append your code
  957.       MY:STARTUP))                              ;just your code
  958.  
  959.   or a simple one:
  960.  
  961.   (if (and S::STARTUP (listp S::STARTUP))       ;usually called consp
  962.      (setq S::STARTUP (append S::STARTUP (list func '(princ))))
  963.      (setq S::STARTUP (list nil func '(princ))))
  964.  
  965. + Vladimir Nesterovsky:
  966.   The main difference now in A2K+ versions is that functions defined 
  967.   with DEFUN are now a new datatype, USUBRs, and not lists as before. 
  968.   But when the function is defined with DEFUN-Q, it is a list still, 
  969.   like in previous versions. 
  970.  
  971.   Here's the utility function to use that works in both cases: 
  972.  
  973.   (defun plug-into-startup (funcname) ;by VladimirNesterovsky
  974.     "to be called with quoted function name"
  975.     (eval (list
  976.       'defun 's::startup ()
  977.       (if s::startup (list (list 'quote s::startup)))
  978.       (list funcname))))
  979.  
  980.   So if you have all your startup code packed into one routine 
  981.  
  982.   (defun my-startup ()
  983.     (alert "My Startup"))
  984.  
  985.   You make it work with the call 
  986.  
  987.   (plug-into-startup 'my-startup)
  988.  
  989.   Inside your code that is executed on startup, e.g. acaddoc.lsp 
  990.   or whatever.
  991.  
  992.   See also  "[12] How to Autoload my programs?"
  993.  
  994. ------------------------------
  995.  
  996. Subject: [12] How to Autoload my programs?
  997.  
  998.   How to load my programs automatically? You can either load your
  999.   whole program at startup (see  "[11] My LISP doesn't
  1000.   load at startup anymore") which needs more time and memory at
  1001.   startup time, or you can define them via the autoloading mechanism.
  1002.   From R14 on ARX programs use a new autoloading scheme (called
  1003.   "demand loading") with some registry settings and not from ACADRxx.LSP
  1004.   anymore.
  1005.  
  1006.   Look at the end of your ACADRxx.LSP how AutoCAD autoloads its programs.
  1007.  
  1008.   ;;;===== AutoLoad LISP Applications =====
  1009.   ...
  1010.   (autoload "dline" '("dline" "dl"))
  1011.   ...
  1012.  
  1013.   This defines the commands DLINE and DL in the list to be loaded
  1014.   from the file DLINE.LSP when the user first calls the command DLINE
  1015.   or DL. Before that the function is simply defined like this one:
  1016.  
  1017.   (defun C:DL () (load "DLINE")(C:DL))
  1018.  
  1019.   In fact the definition is more complicated because of error
  1020.   handling.
  1021.   After the first call the function is overwritten with the
  1022.   definition in the program.
  1023.  
  1024.   Advantages of autoloading:
  1025.   * Startup is faster, because you dont have to load all your lisp
  1026.     files. You just define the simple *wrapper* definition as above.
  1027.     This is done by the (autoload) function.
  1028.   * You need less memory.
  1029.  
  1030.   Disadvantages:
  1031.   * On errors in your program you will fall into a never ending
  1032.     loop, which will only stop after a stack overflow or Ctrl-C
  1033.     Note: with ACOMP compiled code even Ctrl-C is impossible.
  1034.       Insert then a call to an uncompiled (princ) somewhere.
  1035.   * You have to define and maintain all command names from your
  1036.     program in the autoloader definition. Changes to the lisp
  1037.     filename or the command name will cause the above error.
  1038.  
  1039.   Where to put your (autoload) definitions?
  1040.  
  1041.   * Not to ACADR13.LSP.
  1042.   * Well we recommend putting it to an initialization file of yours
  1043.     and not to ACAD.LSP because this is often changed by different
  1044.     applications and ACAD.LSP should be kept rather small.
  1045.       I.e. put it to a AUTOLOAD.LSP or INIT.LSP, which is loaded from
  1046.     ACAD.LSP. See "[11] My LISP doesn't load at startup anymore"
  1047.   * It should be mentioned that users should *not* modify ACADRxx.LSP.
  1048.     Since ACAD.LSP is not overwritten during upgrades, it is guaranteed
  1049.     to remain safe. In addition (as we saw with the R13c4a patch) if the
  1050.     ACADR13.LSP file has been  modified, then the patch process may
  1051.     refuse to update it, thus resulting in program malfunctions.
  1052.  
  1053. ------------------------------
  1054.  
  1055. Subject: [13] How can I pass a variable number of arguments to a lisp
  1056. function?
  1057.  
  1058.   With plain AutoLISP this is not possible.
  1059.   You can either pass all your arguments in a list like this:
  1060.  
  1061.   ;;; print a variable number of arguments (of any type)
  1062.   (defun my-princ (x)
  1063.     ;; simple version, for better stuff look at the SDK2: PRINTF.LLB
  1064.     (if (listp x)
  1065.       (mapcar 'princ x)
  1066.       (princ x)))
  1067.  
  1068.   Or you have to define the function in ADS and export it to
  1069.   AutoLISP.
  1070.   Then you are free to write:
  1071.     (ads-print "Hello " "World " 1 2 3)
  1072.   or even
  1073.     (ads-printf "Hello %s %i %i" "World" 2 3)
  1074.  
  1075.   Look at Reini Urban's and Vladimir Nesterovsky's ADS samples at
  1076.   http://xarch.tu-graz.ac.at/autocad/ads for implementations of the
  1077.   above examples.
  1078.  
  1079.   Official wishes were pointed to Autodesk regarding &optional as
  1080.   AutoLISP language enhancement, but it was not implemented in R14.
  1081.  
  1082. ------------------------------
  1083. Subject: [14] How can I avoid stack overflows?
  1084.  
  1085.   In old AutoLISP the stack size was hardcoded. It couldn't be extended,
  1086.   but its size should be sufficient for most purposes. In the Visual
  1087.   Lisp IDE the stack overflow is simulated at 984 recursions, on the 
  1088.   A2000 commandline or loaded programs outside the IDE there's no 
  1089.   overflow anymore. This is dangerous on recursion errors of yours,
  1090.   see [9]. Most stack overflow errors occur on a program error of
  1091.   yours, preventing the system from falling into an endless loop, or
  1092.   from using recursive functions on large lists. Therefore you are
  1093.   limited to quite short lists with recursive functions and old versions.
  1094.  
  1095.   You cannot decrease your used stack size with using less local
  1096.   parameters in your recursive function! However do not use APPLY, EVAL
  1097.   or MAPCAR to call your function recursively, because they eat up the
  1098.   stack. Using tail recursion doesn't help either.
  1099.   You have to convert your recursive function to a iterative one.
  1100.   (There is a mathematical theorem that says, that every recursive
  1101.   function can be converted to a iterative one, tail-recursive ones
  1102.   even automatically.) Iterative versions may use stack-like functions
  1103.   like (push) and (pop), but those versions store the stack on the heap
  1104.   (autolisp node space), which size is only limited by your amount of
  1105.   virtual memory available.
  1106.  
  1107.   You can test the stack overflow with this simple function:
  1108.  
  1109.   ;;; create a list of n numbers (zero based)
  1110.   (defun intlst (l n)
  1111.     (cond ((zerop n) l)
  1112.           (T (intlst (cons (1- n) l) (1- n)))))
  1113.   and try:
  1114.   (setq n 100)(while (intlst nil (setq n (+ 10 n)))(print n))
  1115.  
  1116.   In AutoLISP of R12/DOS you reach the stack limit with
  1117.   (intlst nil 138), in A13/Win with (intlst nil 240), in ACOMP bi4's
  1118.   with (intlst nil 1240), in Vital LISP/Visual Lisp IDE with 
  1119.   (intlst nil 984). With R10c10, the first dos extended lisp version, 
  1120.   you could enhance the lisp stack size with the environment variable 
  1121.   LISPSTACK. ACOMP for R10 had COMPSTACK.
  1122.   With Vital LISP or Visual LISP RTS or A2000 (outside the IDE) the 
  1123.   stack size is unlimited.
  1124.  
  1125.   Conversion to an iterative version yields the required results:
  1126.  
  1127.   (defun intlst (n / l)
  1128.     (repeat n
  1129.       (setq l (cons (setq n (1- n)) l)))) ;this looks ugly but it works
  1130.  
  1131. ------------------------------
  1132.  
  1133. Subject: [15] (command "ROTATE3D") does not work! Why?
  1134.  
  1135.   Some commands are no internal AutoCAD commands, they are simple
  1136.   AutoLISP programs beginning with C: even if they are defined in ADS
  1137.   programs. Only native Rx applications (or now with vlax-add-cmd)
  1138.   export true commands.
  1139.  
  1140.   A list of all these commands are found in ACADRxx.LSP in the
  1141.   AUTOLOAD section.  (see also "[12]")
  1142.   All these commands have to be called with (C:ROTATE3D) instead of
  1143.   (command "ROTATE3D").
  1144.   However ADS functions may take optional arguments. See the
  1145.   customization manual for more.
  1146.   i.e. (c:rotate3d ss p1 p2 angle) is also valid, even (rotate3d ...)
  1147.  
  1148. ------------------------------
  1149.  
  1150. Subject: [16] LISP programs operating over multiple drawings
  1151.  
  1152.   "I am having trouble getting a lisp file that will open a drawing and
  1153.   continue running. Once the new drawing is opened the LISP file ceases
  1154.   to exist in the Autocads memory. It has to be reloaded to recognise
  1155.   the commands."
  1156.  
  1157.   LISP memory is reloaded on a per drawing basis.  There are some
  1158.   ways to execute a LISP on multiple drawings:
  1159.   1) via a script that executes on multiple files.
  1160.      MYSCRIPT.SCR:
  1161.      (load "mylisp")
  1162.      _QSAVE _OPEN !nextdwg
  1163.      (load "mylisp")
  1164.      _QSAVE _OPEN !nextdwg
  1165.      ...
  1166.    2) External 3rd party software such as RunLisp, ScriptPro or DDSCRIPT automate
  1167.       step 1.
  1168.    3) R14 has a new feature, called 'Persistent LISP'.
  1169.       Set it in Preferences-Compatibility-Persistent LISP
  1170.    4) Vital LISP has a built-in variable to act as Persistent LISP:
  1171.       (setq *VILL-NEW-FULL-INIT* nil)   ;keep symbols between sessions
  1172.    5) same with Visual LISP: (setq *VLISP-NEW-FULL-INIT* nil)
  1173.  
  1174. ------------------------------
  1175.  
  1176. Subject: [17] How to export Visual Lisp functions to AutoLISP/AutoCAD?
  1177.  
  1178. C: functions are automatically exported to AutoLISP. Plain vlisp/vill
  1179. lisp functions must be exported either with (vl-acad-defun funcname) or
  1180. their symbols may be exported with a special compiler pragma, defined
  1181. either in the LSP file or in the GLD (global declarations) file. Better
  1182. use special prefixes for such functions.
  1183.  
  1184. .GLD:
  1185. (AUTOEXPORT-to-ACAD-PREFIX
  1186.   ;| name prefixes for functions to be autoexported to AutoCAD: (strings) |;
  1187.   "myx-*"
  1188.   )
  1189. or one by one
  1190. .LSP:
  1191. (pragma '((export-to-acad myx-func1 myx-func2)))
  1192.  
  1193. Note: There may exist known bugs in vlisp and vill with lists of atomic
  1194. symbols and dotted pair lists in such functions arguments and return
  1195. values. See [7].
  1196.  
  1197. Functions exported by external apps which are used in your application
  1198. must be defined via XDF.
  1199.  
  1200. Symbols (variables) whose values are updated in Visual Lisp and which
  1201. values are also used in AutoLISP or AutoCAD (the menu e.g.), first may
  1202. be marked for the compiler to be external with:
  1203.   (pragma '((not-localize myx:symbol)))
  1204. but the value must be exported with
  1205.   (vlisp-export-symbol 'myx:symbol)
  1206. each time the value is changed in Visual Lisp and control is returned
  1207. to AutoCAD to be able to get the latest value in AutoLISP or in AutoCAD
  1208. with !myx:symbol
  1209.  
  1210. You may forget this whole chapter with AutoCAD 2000, however you might
  1211. need to export your function from the protected namespace then with
  1212. VL-DOC-SET.
  1213. See also http://www.autodesk.com/support/techdocs/td17/td175363.htm
  1214.  
  1215. ------------------------------
  1216.  
  1217. Subject: [A] Disclaimer, Notes from the authors
  1218.  
  1219.   If you think of questions that are appropriate for this FAQ, or
  1220.   would like to improve an answer, please send email to Reini Urban
  1221.   <rurban@x-ray.at> but don't expect an reply.
  1222.  
  1223.   This AutoLISP FAQ is Copyright (c) 1996,97,98,99,2000 by Reini Urban.
  1224.  
  1225.   This FAQ may be freely redistributed in its entirety without
  1226.   modification provided that this copyright notice is not removed. It
  1227.   may not be sold for profit or incorporated in commercial documents
  1228.   (e.g. published for sale on CD-ROM, floppy disks, books, magazines,
  1229.   or other print form) without the prior written permission of the
  1230.   copyright holder. Permission is expressly granted for this document
  1231.   to be made available for file transfer from installations offering
  1232.   unrestricted anonymous file transfer on the Internet and esp. to be
  1233.   included into the official AutoCAD FAQ.
  1234.  
  1235.   The sample code is, if not otherwise stated, (c) 1996,97
  1236.   by Reini Urban and may be freely used, but not sold.
  1237.   The basic functions in [20] are, if not otherwise stated, (c) 1991-97
  1238.   by Reini Urban and may/should be freely used.
  1239.  
  1240.   If this FAQ is reproduced in offline media (e.g., CD-ROM, print
  1241.   form, etc.), a complimentary copy should be sent to Reini Urban,
  1242.   X-RAY, Nibelungeng. 3, 8010 Graz, Austria
  1243.  
  1244.   This article, the contents and the sample code, is provided AS IS
  1245.   without any expressed or implied warranty.
  1246.  
  1247. [A.1] FAQ Locations
  1248.  
  1249.   Homepage of the HTML'ified version:
  1250.     http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html
  1251. + Annotated AcadWiki version:
  1252. +   http://xarch.tu-graz.ac.at/acadwiki/AutoLispFaq
  1253.   The posted ascii versions (and always latest versions) are at
  1254.     http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.1 and
  1255.     http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.2
  1256.   The Winhelp version (zipped with faq and code) is at
  1257.     ftp://xarch.tu-graz.ac.at/pub/autocad/news/faq/autolisp.zip
  1258.   The FAQ usenet archive is at
  1259.     http://www.faqs.org/faqs/CAD/autolisp-faq/ resp.
  1260.     ftp://rtfm.mit.edu/pub/usenet-by-hierarchy/comp/cad/autocad/
  1261.   The LISP code from this FAQ is at
  1262.     ftp://xarch.tu-graz.ac.at/pub/autocad/news/faq/FAQ-CODE.LSP
  1263.   See also the cca glossary for common abbrevations at
  1264.     http://xarch.tu-graz.ac.at/autocad/news/faq/glossary.html
  1265.   Submissions for a new AutoCAD FAQ are stored at
  1266.     http://xarch.tu-graz.ac.at/autocad/news/faq/new-acad
  1267.   A french translation of the FAQ was made by Roger Rosec
  1268.     http://www.newz.net/acadplus/page5101.htm
  1269.   A japanese translation of the FAQ was made by MASAMI Chikahiro
  1270.     http://www.page.sannet.ne.jp/chestnutsburr/autolisp-j.html
  1271.   A russian translation by Igor Orellana at
  1272.     http://www.cad.dp.ua/stats/alfaq_ru.htm
  1273.   A german translation by myself at
  1274.     http://xarch.tu-graz.ac.at/autocad/news/faq/autolisp.html.de
  1275. + A new spanish translation by Eduardo Magdalena
  1276. +   http://www.peletash.com/mecanicad/articulos/art02_0002.htm
  1277.  
  1278.   A greek translation is in progress.
  1279.   Relevant AutoDesk FAQ's and TechSupport
  1280.     http://www.autodesk.com/support/autocad/
  1281.     http://search.autodesk.com/query.html?qt=autocad+faq
  1282.     http://www.autodesk.com/support/autocad/asa2000.htm
  1283.   AutoDesk news groups
  1284.     news://discussion.autodesk.com/autodesk.autocad.customization
  1285.     New WebX interface at http://discussion.autodesk.com
  1286.     http://groups.google.com/groups?oi=djq&as_ugroup=autodesk.autocad.customization
  1287.  
  1288. --
  1289. Reini Urban, Jun 25, 2002
  1290.