AutoLISP

From Wikipedia, the free encyclopedia
  (Redirected from Visual Lisp)
Jump to: navigation, search

AutoLISP is a dialect of Lisp programming language built specifically for use with the full version of AutoCAD and its derivatives, which include AutoCAD Map 3D, AutoCAD Architecture and AutoCAD Mechanical.[1] Neither the application programming interface nor the interpreter to execute AutoLISP code are included in the AutoCAD LT product line.[2]

Features[edit]

AutoLISP is a small, dynamically scoped, dynamically typed LISP dialect with garbage collection, immutable list structure and settable symbols, lacking in such regular LISP features as macro system, records definition facilities, arrays, functions with variable number of arguments or let bindings. Aside from the core language, most of the primitive functions are for geometry, accessing AutoCAD's internal DWG database, or manipulation of graphical entities in AutoCAD. The properties of these graphical entities are revealed to AutoLISP as association lists in which values are paired with AutoCAD "group codes" that indicate properties such as definitional points, radii, colors, layers, linetypes, etc. AutoCAD loads AutoLISP code from .LSP files.[3]

AutoLISP code can interact with the user through Autocad's graphical editor by use of primitive functions that allow user to pick points, choose objects on screen, input numbers and other data. AutoLisp also has a built-in GUI mini-language, the Dialog Control Language, for creating modal dialog boxes with automated layout, within AutoCAD.[3]

History[edit]

AutoLISP was derived from an early version of XLISP, which was created by David Betz.[4] The language was introduced in AutoCAD Version 2.18 in January 1986, and continued to be enhanced in successive releases up to Release 13 in February 1995. After that, its development was neglected by Autodesk in favor of more fashionable development environments like VBA, .NET and ObjectARX. However, it has remained AutoCAD's primary user customization language.

Vital-LISP, a considerably enhanced version of AutoLISP including an IDE, debugger and compiler, and ActiveX support, was developed and sold by third party developer Basis Software. Vital LISP was a superset of the existing AutoLISP language that added VBA-like access to the AutoCAD object model, reactors (event handling for AutoCAD objects), general ActiveX support, and some other general Lisp functions. Autodesk purchased this, renamed it Visual LISP, and briefly sold it as an add-on to AutoCAD 14 released in May 1997. It was incorporated into AutoCAD 2000 released in March 1999, as a replacement for AutoLISP. Since then Autodesk has chosen to halt major enhancements to Visual LISP in favor of focusing more effort on VBA and .NET and C++. As of January 31, 2014, Autodesk no longer supports versions of VBA older than 7.1. This is part of a long-term process of switching over from VBA to .NET for customization. [5] [6]

AutoLISP has such a strong following that other CAD application vendors add it to their own products. Bricscad, IntelliCAD and others have AutoLISP functionality, so that AutoLISP users can consider using them as an alternative to AutoCAD. Most development involving AutoLISP since AutoCAD 2000 is actually performed within Visual LISP since the original AutoLISP engine was replaced with the Visual LISP engine. There are thousands of utilities and applications that have been developed using AutoLISP or Visual LISP (distributed as LSP, FAS and VLX files).[7] [8]

Examples[edit]

A simple Hello world program in AutoLisp would be:

  1. (defun hello ()
    
  2.    (princ "\nHello World!")
    
  3. )
    


A more complex example might be:

  1. (defun C:POINTLABEL ( / pt)
    
  2.    (setq pt (getpoint "\nPick point: "))
    
  3.    (command "POINT" pt)
    
  4.    (command "TEXT" (polar pt 0 0.6) 0 (strcat "X:" (rtos (car pt)) " Y:" (rtos (cadr pt))))
    
  5.    (princ)
    
  6. )
    

The above code defines a new function which places a point in the current drawing and writes the X and Y coordinates next to it. The name of the function includes a special prefix 'C:', which causes AutoCAD to recognize the function as a regular command. The user, upon typing 'POINTLABEL' at the AutoCAD Command Prompt, would be prompted to pick a point, either by typing in the X and Y coordinates, or clicking a location in the drawing. The function would then place a marker at that point, and create a text object next to it, containing the x and y coordinates. The function requires no parameters, and contains one private variable ('pt'). This example also demonstrates AutoLisp's ability to use built-in AutoCAD commands to achieve the desired results; making two calls to the function 'command', while passing on the information necessary to complete the commands without further user input.

References[edit]

  1. ^ "AutoLISP". Retrieved 14 April 2014. 
  2. ^ "AutoCAD LT vs. AutoCAD". Retrieved 14 April 2014. 
  3. ^ a b "AutoLISP Developer's Guide". Retrieved 14 April 2014. 
  4. ^ History of AutoLISP
  5. ^ "Microsoft Visual Basic for Applications Module FAQ". Retrieved 14 April 2014. 
  6. ^ "VBA support in AutoCAD 2011". Retrieved 14 April 2014. 
  7. ^ "BricsCAD Compare versions". Retrieved 14 April 2014. 
  8. ^ "IntelliCAD CAD Platform — Features and Benefits". Retrieved 14 April 2014. 

External links[edit]