Community
AutoCAD Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

lisp routine

1 REPLY 1
Reply
Message 1 of 2
Anonymous
152 Views, 1 Reply

lisp routine

Can anyone tell me if this lisp routine is right. If it isn't, could you make the neccessary corrections?

 

(defun C:COMMANDNAME (\ *ERROR ME CE CL)
 (DEFUN NEWERR (MSG)
 (PRINC (STRCAT "\N*ERROR* : "MSG))
 (SETVAR "MENUECHO" ME)
 (SETVAR "CMDECHO" CE)
 (SETVAR "CLAYER" CL)
 (GC) (PRINC)
)
;
(SETQ ACADERR *ERROR*
 *ERROR* NEWERR
 ME (GETVAR "MENUECHO")
 CE (GETVAR "CMDECHO")
 CL (GETVAR "CLAYER")
)
 (SETVAR "MENUECHO" 0)
 (SETVAR "CMDECHO" 0)
 (GRAPHSCR)
 (DEFUN DTR (A)
 (* PI (/ A 180.0)))
 (DEFUN RTD (A)
 (/ (* A 180.0) PI)
)
 (SETQ IP (GETPOINT "\N 2,5"))
 (SETQ EW (GETREAL "\N 6"))
 (SETQ E1 (LIST(- (CAR IP)(/ EW 2))(CADR IP)))
 (SETQ E2 (LIST(+ (CAR E1) EW)(CADR E1)))
 (SETQ E3 (LIST(+ (CAR E2) 6)(+ (CADR E2) 6)))
 (SETQ E4 (LIST(CAR E3)(+ (CADR E3) EW)))
 (SETQ CP (LIST(+ (CAR E2) 6)(CADR E2)))
 (COMMAND "PLINE" E1 E2 "A" "CE" CP "A" -90 "L" E4 "A" "CE" CP E1 "")
(SETVAR "MENUECHO" ME)
(SETVAR "CMDECHO" CE)
(SETVAR "CLAYER" CL)
(SETQ*ERROR* ACADERR(GC)
(PRINC)
)

1 REPLY 1
Message 2 of 2
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

Can anyone tell me if this lisp routine is right. If it isn't, could you make the neccessary corrections?

....


Some things I notice, without detailed evaluation:

 

(defun C:COMMANDNAME (/ *error* ME CE CL); forward slash, asterisks at both ends of *error*

 (DEFUN *error* (MSG); if you're going to do *error* as a localized variable above, define it directly,

  ;; not with crossed out parts below, and AutoCAD's will be restored when routine ends.
 (PRINC (STRCAT "\N*ERROR* : "MSG))
 (SETVAR "MENUECHO" ME)
 (SETVAR "CMDECHO" CE)
 (SETVAR "CLAYER" CL)
 (GC) (PRINC); (gc) does not appear to be defined
)
;
(SETQ ;; ACADERR *ERROR*
;; *ERROR* NEWERR
 ME (GETVAR "MENUECHO")
 CE (GETVAR "CMDECHO")
 CL (GETVAR "CLAYER")
)
 (SETVAR "MENUECHO" 0)
 (SETVAR "CMDECHO" 0)
 (GRAPHSCR)
 (DEFUN DTR (A) ;; these are apparently never used
 (* PI (/ A 180.0)))
 (DEFUN RTD (A)
 (/ (* A 180.0) PI)
)
 (SETQ IP (GETPOINT "\N 2,5")); [not sure what the prompt means]
 (SETQ EW (GETREAL "\N 6")); [not sure what the prompt means]
 (SETQ E1 (LIST(- (CAR IP)(/ EW 2))(CADR IP)))
 (SETQ E2 (LIST(+ (CAR E1) EW)(CADR E1)))
 (SETQ E3 (LIST(+ (CAR E2) 6)(+ (CADR E2) 6)))
 (SETQ E4 (LIST(CAR E3)(+ (CADR E3) EW)))
 (SETQ CP (LIST(+ (CAR E2) 6)(CADR E2)))
 (COMMAND "PLINE" E1 E2 "A" "CE" CP "A" -90 "L" E4 "A" "CE" CP E1 "")

   ;; I'm not positive without testing, but I think "-90" may need to be in quotes, or it may be read as radians
(SETVAR "MENUECHO" ME)
(SETVAR "CMDECHO" CE)
(SETVAR "CLAYER" CL)
;; (SETQ*ERROR* ACADERR(GC)
(PRINC)
)

 

Also, not "wrong," but you can streamline your variable settings -- you can set multiple variables in one (setq) function as you did with ME / CE / CL:

 

 (SETQ

   IP (GETPOINT "\N 2,5"); [not sure what the prompt means]
   EW (GETREAL "\N 6"); [not sure what the prompt means]
   E1 (LIST(- (CAR IP)(/ EW 2))(CADR IP))

   E2 (LIST(+ (CAR E1) EW)(CADR E1))
   E3 (LIST(+ (CAR E2) 6)(+ (CADR E2) 6))
   E4 (LIST(CAR E3)(+ (CADR E3) EW))
   CP (LIST(+ (CAR E2) 6)(CADR E2))

 ); end setq

Kent Cooper, AIA

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost