AutoLISP

from Wikipedia, the free encyclopedia

AutoLISP [ ˈɑːtoʊˌlɪsp ] is a dialect of the LISP programming language and part of the popular CAD program AutoCAD .

AutoLisp can be used to add, delete, and change functions in an AutoCAD system. To ensure this, there are special AutoLisp routines that can directly access the AutoCAD database . These are essentially functions for handling coordinate inputs , which can be converted into CAD elements such as lines, circles, etc. With the help of AutoLISP, complex environments for handling AutoCAD, for example with regard to the use of standard parts , can be created.

Hello World

 (defun c:HelloWorld()
     (princ "\nHello World")
 )

Example: to draw a rectangle

  (defun c:recht2 ( / p1 laenge breite w p2 p3 p4)
   (setq p1 (getpoint "\nEinfügepunkt: "))
   (setq laenge (getdist p1 "\nLänge: "))
   (setq breite (getdist p1 "\nBreite: "))
   (setq w (getangle p1 "\nEinfügewinkel: "))
   (setq p2 (polar p1 w laenge))
   (setq p3 (polar p2 (+(/ pi 2)w) breite))
   (setq p4 (polar p3 (+ pi w) laenge))
   (command "linie" p1 p2 p3 p4 "s") 
   (princ)
 )

Example: Determination of a distance in Autolisp

 (defun c:Distanz()
  (setq old_osmode (getvar "osmode"))
  (setvar "osmode" 1)
  (setq P01 (getpoint    "\nErster  Punkt:"))
  (setq Distanz (getdist P01 "\nZweiter Punkt:" ))
  (princ "\nDistanzwert: ")
  (princ Distanz)
  (princ "\n , zugreifen in AutoCAD mit !DISTANZ ")
  (setvar "osmode" old_osmode)
 )

Example: Rotating objects in Autolisp

 (defun c:verdreh (/ Drehpunkt Radius Auswahl Erster_Punkt)
  (setq Drehpunkt  (getpoint "\nDrehen mit dem Kreis <Zentrum des Bezugskreis>: "))
 (if Drehpunkt 
  (progn
   (setq Radius (abs (getdist Drehpunkt "\nRadius für den <Bezugskreis>:")))
   (if Radius
    (command "Kreis" Drehpunkt Radius )
   );end if Radius
  );end progn Drehpunkt
 );end if Drehpunkt
 (if Radius  
  (setq Auswahl (ssget  )  ) ;Wählen der Elemente zum Drehen 
 );end if Radius
 (if Auswahl 
  (progn
   (setq Erster_Punkt  (getpoint Drehpunkt "\nAusgangspunkt der Drehung [Schnittpunkt] mit dem <Bezugskreis>:"))
   (if Erster_Punkt
    (progn
     (command "drehen"  (ssget "V") ""  Drehpunkt "B" Drehpunkt Erster_Punkt pause nil)
     (command "Löschen" "L" "" )
     );end progn Erster_Punkt
    );end if Erster_Punkt
   );end progn Auswahl
  ); end if Auswahl
 ); Ende der Funktion verdreh
 (princ "\nVERDREH.LSP wurde geladen.." )
 (princ "\nStarten mit verdreh \n")
 (princ)

Example: sets objects on the current layer in AutoLisp

 ; Setzt gewählte Objekte auf den aktuellen Layer
 (defun c:selayer(/ ak_layer)
 (setq ak_layer (getvar "clayer"))
 (princ "\nObjekte setzen auf: <")
 (princ ak_layer)
 (princ "> alle Eigenschaften des Layers werden übernommen.")
 (command "_change" (ssget) "" "_p"  "_LA"  ak_layer  "_LT" "_bylayer"  "_C"  "_bylayer" "_S"  "1" "")
 )

Web links