Lee Mac 发表于 2022-7-6 17:55:59

Hey CALCAD, CAB,
 
I just tried your LISP CAB, and I must say, you have tidied up my LISP beautifully... I'm loving that (or) statement in place of the (if(not))... I don't know how you think of these things
 
Your LISP functions well and my layer is successfully reset. I can only imagine that the Error Handler in my original code clashed with my lines that reset the current layer.
 
But it works now and thanks to CAB and CALCAD for both your help - all is much appreciated - I just hope I can return the favour at some point

CALCAD 发表于 2022-7-6 18:02:14

You're welcome Lee.

JONTHEPOPE 发表于 2022-7-6 18:03:09

HEY LEE MAC IT'S ME 'JTP'
 
I'm intersted in you program sounds cool .
does the drawing have to be active to work ??
I Don't really have anything to add to this post .
just thought is was cool we are, friends and your on the other side of the world .

Lee Mac 发表于 2022-7-6 18:08:05

Hey JTP,
 
Yeh it is pretty cool that people from all over the world share programs they have created.
 
My program is just for adding Centre-lines to circles, after the user has set a base variable - namely the ratio of the line to the radius of the circle (preset at 122%).
 
The drawing does have to be active, and the user selects the circles one by one, until hitting either "enter" or "esc" to exit the function.
 
Here is the final version:
 

;|         Centre-Line by Lee McDonnell               November 2008 Credit to CALCAD & CAB for Help with Development|;(defun c:cl (/ oldlay oldsnap c1 c1ent c1cent c1rad crat            *error* ; always localize the error handler            )         ;   --- Error Trap --- (defun *error* (msg)      (mapcar 'setvar varLst oldVars)   (if (= msg "")         (princ "\nUser Quit... ")         (princ "\nError or Esc pressed... ")   )   (princ) )       ; end of *error* (setq varLst(list "CMDECHO" "CLAYER" "DIMSCALE")       oldVars (mapcar 'getvar varLst) )       ; end setq          ;    --- Error Trap --- (setvar "cmdecho" 0) (mapcar 'cllayer '("1" "2" "3" "4" "5"))(or (getenv "cl:ratio") (setenv "cl:ratio" "122"))   (princ   (strcat "\nType \"CLSET\" to Change Base Variables. > C/L Ratio: "         (getenv "cl:ratio")   ) ) (while (setq c1 (entsel "\nSelect Circle for Centre-line: "))    (setq c1ent (entget (car c1)))    (if (= (cdr (assoc 0 c1ent)) "CIRCLE")      (progn      (setq c1cent (cdr (assoc 10 c1ent))            c1rad(cdr (assoc 40 c1ent))            crat   (/ (atof (getenv "cl:ratio")) 100)      ) ; end setq      (setvar "clayer" "5")      (command "-linetype" "S" "CENTER" "")      (command "_line"                  "_non" (polar c1cent pi (* c1rad crat))               "_non" (polar c1cent 0 (* c1rad crat))               ""      ) ;end line      (command "_line"               "_non" (polar c1cent (* pi 1.5) (* c1rad crat))               "_non" (polar c1cent (/ pi 2) (* c1rad crat))               ""      ) ; end line      ); end progn      (alert "\nEntity is not a Circle.")    )    ; end if    (command "-linetype" "S" "Bylayer" "") )       ; end while (*error* "") ; Thanks CAB for this(princ "\nFunction Complete.") (princ))         ; end cl(defun cllayer (lay) (if (not (tblsearch "LAYER" lay))   (command "_.-layer" "_m" lay "_c" lay lay "") )       ; end if)         ; end cllayer(defun c:clset (/ cratio) (or (getenv "cl:ratio")(setenv "cl:ratio" "122")) (princ (strcat "\n> C/L Ratio: " (getenv "cl:ratio") "%")) (if (setq cratio (getreal (strcat "\nSpecify C/L as % of Circle Radius: "                           )                  )   )   (setenv "cl:ratio" (rtos cratio)) )       ; end if (princ "\nBase Variables Set.") (princ))         ; end clset
页: 1 [2]
查看完整版本: 中线LISP错误