how to understand this lisp?

how to understand this lisp?

Anonymous
Not applicable
1,346 Views
6 Replies
Message 1 of 7

how to understand this lisp?

Anonymous
Not applicable

hi everyone

i got somewhere in this forum this doorlisp. My question is, this lisp has so many defun functions.it is really hard to understand. i am a beginner at lisp.i have marked the red color which I did not understand.i want to know briefly about this lisp for my learning purpose. could anyone tell me? 

thanks advance

 

(DEFUN C:DOOR (/ HP1 HP2 DWIDTH SP1 SP2 C-LAY BOX LIN1 LINE1 LINE2)
(MODES '("CMDECHO" "COORDS" "OSMODE" "BLIPMODE"))
(SETVAR "CMDECHO" 0)
(SETVAR "COORDS" 2)
(SETVAR "OSMODE" 256)
(SETQ HP1 (GETPOINT "\nHinge pt: ")
HP1 (OSNAP HP1 "NEAR")
SP1 (GETPOINT HP1 "\nSwing pt: ")
SP1 (OSNAP SP1 "NEAR")
DWIDTH (DISTANCE HP1 SP1)
C-LAY (GETVAR "CLAYER"))
(SETVAR "OSMODE" 0)
(SETQ BOX (SSGET "C" (LIST (- (CAR HP1) 12.0) (- (CADR HP1) 12.0))
(LIST (+ (CAR HP1) 12.0) (+ (CADR HP1) 12.0))))


(IF (AND BOX
(SETQ LIN1 (SSGET HP1))
(SETQ L_NM (SSNAME LIN1 0))
(LINE? L_NM))

(PROGN (SETQ LINE1 (ENTGET L_NM))
(SSDEL (CDR (ASSOC -1 LINE1)) BOX) ;; remove first line from box

 

(FOREACH ENT (SS2ENAMLIST BOX)
(SETQ E (ENTGET ENT))


(IF (OR (/= (CDR (ASSOC 8 E))
(CDR (ASSOC 8 LINE1)))
(/= (CDR (ASSOC 0 E)) "LINE")

(NOT (PARALLEL E LINE1)))
(SSDEL (CDR (ASSOC -1 E)) BOX)))
(SETVAR "OSMODE" 0)
(SETVAR "BLIPMODE" 0)

(IF (> (SSLENGTH BOX) 0) ;; look in the box

(PROGN (SETQ LINE2 (ENTGET (SSNAME BOX 0))

HP2 (INTERS (CDR (ASSOC 10 LINE2))
(CDR (ASSOC 11 LINE2))
HP1 (POLAR HP1 (IF (> PI (ANGLE HP1 SP1))
(- (ANGLE HP1 SP1) (/ PI 2.0))
(+ (ANGLE HP1 SP1) (/ PI 2.0)))
(DISTANCE HP1 SP1)) nil))
(COMMAND "LAYER" "S" (CDR (ASSOC 8 LINE1)) "")
(SETQ SP2 (POLAR HP2 (ANGLE HP1 SP1) DWIDTH)
P5 (POLAR HP1 (ANGLE HP2 HP1) DWIDTH))
(COMMAND "BREAK" HP1 SP1)
(COMMAND "BREAK" HP2 SP2)
(COMMAND "LINE" HP1 HP2 "")
(COMMAND "LINE" SP1 SP2 "")
(COMMAND "LINE" HP1 P5 "")
(COMMAND "ARC" SP1 "E" P5 "D" (ATOF (ANGTOS (ANGLE HP2 HP1) 0 4)))
(COMMAND "LAYER" "S" C-LAY ""))))
(PRINC "\ndoor: invalid selection set"))
;(MODER)
(PRINC))

;(princ "\rPlease wait- loading.. \\")

;; convert a selection set to a list of entity names
(DEFUN SS2ENAMLIST (SS / ENTLIST COUNTER)
(SETQ COUNTER 0)
(REPEAT (SSLENGTH SS)
(PROGN (SETQ ENTLIST (CONS (SSNAME SS COUNTER) ENTLIST))
(SETQ COUNTER (1+ COUNTER)))) ENTLIST)

;(princ "\rPlease wait- loading.. \|")

(DEFUN PARALLEL (LINE1 LINE2) ;; takes 2 e-lists as arguments-
(OR (~= (ANGLE (CDR (ASSOC 10 LINE1)) ;; allow tolerance for nearly
(CDR (ASSOC 11 LINE1))) ;; parallel lines
(ANGLE (CDR (ASSOC 10 LINE2))
(CDR (ASSOC 11 LINE2))) (/ PI 180.0)) ;; 1 rad tolerance
(~= (ANGLE (CDR (ASSOC 11 LINE1))
(CDR (ASSOC 10 LINE1)))
(ANGLE (CDR (ASSOC 10 LINE2))
(CDR (ASSOC 11 LINE2))) (/ PI 180.0))))

;(princ "\rPlease wait- loading.. \/")

(DEFUN ~= (ACT_VAL TEST_VAL TOL) ;;fuzzy equality
(AND (<= ACT_VAL (+ TEST_VAL TOL))
(>= ACT_VAL (- TEST_VAL TOL))))

;(princ "\rPlease wait- loading.. \-")

;; from AutoDesk
(DEFUN MODES (A)
(SETQ MLST '())
(REPEAT (LENGTH A)
(SETQ MLST (APPEND MLST (LIST (LIST (CAR A) (GETVAR (CAR A))))))
(SETQ A (CDR A))))

;(princ "\rPlease wait- loading.. \\")

;; from AutoDesk
;(DEFUN MODER ()
;(REPEAT (LENGTH MLST)
;(SETVAR (CAAR MLST) (CADAR MLST))
;(SETQ MLST (CDR MLST))))

(princ "\rPlease wait- loading.. \|")

(DEFUN LINE? (ENM) ;; takes an entity name as its argument
(IF (AND ENM (= (CDR (ASSOC 0 (ENTGET ENM))) "LINE"))
'T
(PROGN (PRINC "\nWall entities must be lines.") nil)))

;(princ "\rPlease wait- loading.. \/")

;(PRINC "\r2 pick door command C:DOOR loaded. Type DOOR to begin.")
(PRINC)

 

Accepted solutions (2)
1,347 Views
6 Replies
Replies (6)
Message 2 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

See the attached.  [Write back if you want to know the more concise ways to do some of the things it does.]

Kent Cooper, AIA
Message 3 of 7

Anonymous
Not applicable

Marvelous...

0 Likes
Message 4 of 7

Anonymous
Not applicable

hi kentcooper

thank you so much your reply. your explanation so amazing.I want to be like you.

i have a question about which shown below.

 

HP2
(INTERS;;;(what does that mean "inters " )
(CDR (ASSOC 10 LINE2))
(CDR (ASSOC 11 LINE2))


@Kent1Cooper wrote:

See the attached.  [Write back if you want to know the more concise ways to do some of the things it does.]


 

Message 5 of 7

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

i edit the snippet code in a more convenient way for you to understand but first you have to be familier with functions sinature\arguments

 

(polar pt ang dist)

polar function, reurns a point from 'pt' as basepoint at 'ang' angle at 'dist' distance.

 

(inters pt1 pt2 pt3 pt4 [onseg])

inters function, returns the intersection point of 2 lines where pt1, pt2 is the first line and pt3,pt4 is the second line

the fifth argument <onseg> controls the behaviour. If specified as nil, the lines defined by the four pt arguments are considered infinite in length. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil

 

(setq hp2 (inters (cdr (assoc 10 line2))  ; first point
                  (cdr (assoc 11 line2))  ; second point
                  hp1			  ; third point
                  (polar
                    hp1 		  ; base point for polar
                    ; Next supply the angle in radians to polar
                    (if (> pi (angle hp1 sp1))
                      (- (angle hp  sp1) (/ pi 2.0)) ; do this if testexpr true
                      (+ (angle hp1 sp1) (/ pi 2.0)) ; do this if testexpr false
                    ); close if
                    (distance hp1 sp1) ; supply distance to polar
                  ); close polar
                  nil); close inters
); close setq

enjoy
moshe
Message 6 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

....

(INTERS;;;(what does that mean "inters " )
....


 

Anything in AutoLisp code that immediately follows a left parenthesis is either the first item in some kind of list, or a function name.  If it's defined elsewhere in the same code, such as the (MODES) and (~=) functions in this routine, that's where you find what it's for -- Search the file for (defun) entries.  If it's not  defined within the same file, nor in some other custom file that has been loaded, then it's a regular AutoLisp function, and you can look up what it's for in the >AutoLisp Reference<.

 

[There are some exceptions, such as (vla-...) functions, which for some reason are not in the AutoLisp Reference, though (vl-...) and (vlax-...) and (vlar-...) functions are.  But (inters) is certainly there to read about.]

Kent Cooper, AIA
Message 7 of 7

Anonymous
Not applicable
Accepted solution

@Moshe-A wrote:

@Anonymous  hi,

 

i edit the snippet code in a more convenient way for you to understand but first you have to be familier with functions sinature\arguments

 

(polar pt ang dist)

polar function, reurns a point from 'pt' as basepoint at 'ang' angle at 'dist' distance.

 

(inters pt1 pt2 pt3 pt4 [onseg])

inters function, returns the intersection point of 2 lines where pt1, pt2 is the first line and pt3,pt4 is the second line

the fifth argument <onseg> controls the behaviour. If specified as nil, the lines defined by the four pt arguments are considered infinite in length. If the onseg argument is omitted or is not nil, the intersection point must lie on both lines or inters returns nil

 

(setq hp2 (inters (cdr (assoc 10 line2))  ; first point
                  (cdr (assoc 11 line2))  ; second point
                  hp1			  ; third point
                  (polar
                    hp1 		  ; base point for polar
                    ; Next supply the angle in radians to polar
                    (if (> pi (angle hp1 sp1))
                      (- (angle hp  sp1) (/ pi 2.0)) ; do this if testexpr true
                      (+ (angle hp1 sp1) (/ pi 2.0)) ; do this if testexpr false
                    ); close if
                    (distance hp1 sp1) ; supply distance to polar
                  ); close polar
                  nil); close inters
); close setq

enjoy
moshe

hi moshe

thank you so much your reply.nice information.it helps more to learn AutoLISP.

0 Likes