This may help you:
http://www.cadtutor.net/forum/showthread.php?t=39634


Registered forum members do not see this ad.
I know I have alot of questions, hopefully i will be able to contribute soon as well.
I wrote the following lisp
This is a lisp to draw a U-Channel of any size and thickness. if you notice I highlighted a line in red. That line is used for the size of both legs of the channel. Sometimes one of the legs is longer than the other. So I'd like a 2nd line for the 2nd leg. However I would like that line to store the length of the first leg as a default size so you can just press enter if they are the same. So the line might read as followsCode:(defun C:CN () (setq CRosmod (getvar "osmode")) (setq CRcecho (getvar "cmdecho")) ------------------------------------------------------------------------ (defun *error* (msg) ;;;error handler (if CRcecho (setvar "cmdecho" CRcecho)) ;;;resets echo,osnap if you cancel/quit (if CRosmod (setvar "osmode" CRosmod)) (princ msg) (princ)) ------------------------------------------------------------------------ (setq CBP (getpoint "\nSpecify base point: ")) (setq CL1 (getdist "\nSpecify width of channel: ")) (setq CL2 (getdist "\nSpecify size of legs: ")) (setq CW1 (getdist "\nSpecify thickness <0.125>: ")) (if (= CW1 nil) (setq CW1 0.125)) (setq P2 (list (+ (car CBP) CL1) (cadr CBP))) (setq P3 (list (car P2) (+ (cadr CBP) CL2))) (setq P4 (list (- (car P2) CW1) (cadr P3))) (setq P5 (list (car P4) (- (cadr P3) (- CL2 CW1)))) (setq P6 (list (- (car P4) (- CL1 (* CW1 2))) (cadr P5))) (setq P7 (list (car P6) (+ (cadr P5) (- CL2 CW1)))) (setq P8 (list (- (car P6) CW1) (cadr P7))) (setvar "osmode" 0) (setvar "cmdecho" 0) (command "_.pline" CBP P2 P3 P4 P5 P6 P7 P8 "close") (setvar "cmdecho" CRcecho) (setvar "osmode" CRosmod) (princ) )
"Specify size of first leg <maybe a previous size used>: "
"Specify size of second leg <size of first leg>: " i can just press enter
I can't put the variable in the <> because it will just print the variable name. I hope this makes sense, any help is greatly appreciated.![]()
This may help you:
http://www.cadtutor.net/forum/showthread.php?t=39634
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
This is how I would approach it:
Also, I would advise you to either use IF statements or the initget function in your code, to allow for null user inputCode:(setq CL2 (getdist "\nSpecify Size of Leg 1: ")) (setq CL3 (cond ((getdist (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : "))) (CL2)))![]()
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
And little info:
Specify Size of Leg 1(@ base point):
will be handy.
Edit:
What about channel rotation?
Just to expand a little on what the others said and to clean up the code:
Code:(defun C:CN (/ CRcecho CROsmod CRplwid CBP CL1 CL2 CW1 P2 P3 P4 P5 P6 P7 P8) (setq CRosmod (getvar "osmode")) (setq CRcecho (getvar "cmdecho")) (setq CRplwid (getvar "PLINEWID")) ;------------------------------------------------------------------------ (setq *error* (lambda (msg) (setvar "cmdecho" CRcecho) (setvar "osmode" CRosmod) (princ msg) (princ))) ;------------------------------------------------------------------------ (initget 1) (setq CBP (getpoint "\nSpecify base point: ")) (initget 7) (setq CL1 (getdist "\nSpecify width of channel: ")) (initget 7) (setq CL2 (getdist "\nSpecify size of legs: ")) (initget 6) (setq CW1 (getdist "\nSpecify thickness <0.125>: ")) (if (not CW1) (setq CW1 0.125)) (setq P2 (list (+ (car CBP) CL1) (cadr CBP)) P3 (list (car P2) (+ (cadr CBP) CL2)) P4 (list (- (car P2) CW1) (cadr P3)) P5 (list (car P4) (- (cadr P3) (- CL2 CW1))) P6 (list (- (car P4) (- CL1 (* CW1 2))) (cadr P5)) P7 (list (car P6) (+ (cadr P5) (- CL2 CW1))) P8 (list (- (car P6) CW1) (cadr P7))) (setvar "osmode" 0) (setvar "cmdecho" 0) (setvar "PLINEWID" 0) (command "_.PLINE" CBP P2 P3 P4 P5 P6 P7 P8 "_Close") (setvar "cmdecho" CRcecho) (setvar "osmode" CRosmod) (setvar "PLINEWID" CRplwid) (prin1))
-David
R12 (Dos) - A2K


1) Thanks for all the great help. I"m looking into that post by lee mac, thanks
2) I don't know what you mean by "Specify Size of Leg 1(@ base point):". And I was planing another line in the lisp to rotate the channel after it's drawn. I was thinking something along the lines of
(command "_.rotate" "L" "" CBP pause)
3) lol yeah that code does look alot cleaner and easier to read. I guess I need to learn to to keep my lisp's neat. And thanks for that PLINEWID line. I didn't think of that but I can see how that can mess up my channel. I personally rarely use plines with thickness but to make this a lisp for everyone it's a great thought.
I prefer to use "polar", so here is another way to approach things:
I have set the SysVars using a different method also.Code:(defun C:CN (/ SysVars OldVals CBP CL1 CL2 CL3 CW1 P2 P3 P4 P5 P6 P7 P8) (setq SysVars '("CMDECHO" "OSMODE" "PLINEWID") OldVals (mapcar 'getvar SysVars)) ;------------------------------------------------------------------------ (setq *error* (lambda (msg) (mapcar 'setvar SysVars OldVals) (princ msg) (princ))) ;------------------------------------------------------------------------ (initget 1) (setq CBP (getpoint "\nSpecify base point: ")) (initget 7) (setq CL1 (getdist CBP "\nSpecify width of channel: ")) (initget 7) (setq CL2 (getdist "\nSpecify size of Leg 1: " CBP)) (initget 6) (setq CL3 (cond ((getdist CBP (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : "))) (CL2))) (initget 6) (setq CW1 (cond ((getdist "\nSpecify thickness <0.125>: ")) (0.125))) (setq P2 (polar CBP 0 CL1) P3 (polar P2 (* 0.5 pi) CL3) p4 (polar P3 pi CW1) p5 (polar p4 (* 1.5 pi) (- CL3 CW1)) p6 (polar p5 pi (- CL1 (* 2. CW1))) p7 (polar p6 (* 0.5 pi) (- CL2 CW1)) p8 (polar p7 pi CW1)) (mapcar 'setvar SysVars '(0 0 0)) (command "_.PLINE" CBP P2 P3 P4 P5 P6 P7 P8 "_Close") (mapcar 'setvar SysVars OldVals) (prin1))
(Used some of your code David)
Lee
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper
GetDist (and GetPoint) can accept a point argument, in addition to the string. (see VLIDE help files).
Example in above code.
I would use (entlast) to capture the polyline entity, or using entmakex:
Notice that you needn't change the Sys Vars such as OSMODE with entmakex, and you can add DXF group codes to change layer/width etc.Code:(defun C:CN (/ CBP CL1 CL2 CL3 CW1 P2 P3 P4 P5 P6 P7 P8 POLY PTLST) (setq *error* (lambda (msg) (princ msg) (princ))) (initget 1) (setq CBP (getpoint "\nSpecify base point: ")) (initget 7) (setq CL1 (getdist CBP "\nSpecify width of channel: ")) (initget 7) (setq CL2 (getdist "\nSpecify size of Leg 1: " CBP)) (initget 6) (setq CL3 (cond ((getdist CBP (strcat "\nSpecify Size of Leg 2 <" (rtos CL2) "> : "))) (CL2))) (initget 6) (setq CW1 (cond ((getdist "\nSpecify thickness <0.125>: ")) (0.125))) (setq ptLst (list CBP (setq P2 (polar CBP 0 CL1)) (setq P3 (polar P2 (* 0.5 pi) CL3)) (setq p4 (polar P3 pi CW1)) (setq p5 (polar p4 (* 1.5 pi) (- CL3 CW1))) (setq p6 (polar p5 pi (- CL1 (* 2. CW1)))) (setq p7 (polar p6 (* 0.5 pi) (- CL2 CW1))) (setq p8 (polar p7 pi CW1)))) (setq poly (entmakex (append (list (cons 0 "LWPOLYLINE") (cons 100 "AcDbEntity") (cons 100 "AcDbPolyline") (cons 90 8) (cons 70 1)) (mapcar (function (lambda (x) (cons 10 x))) ptLst)))) (command "_.rotate" poly "" CBP pause) (prin1))
For a quick format, you can click on the formatting button in the Visual LISP Editor
Hope this all helps, and if you have any trouble understanding anything me or David has posted, don't hesitate to ask
Lee
Lee Mac Programming
With Mathematics there is the possibility of perfect rigour, so why settle for less?
Just another Swamper


Registered forum members do not see this ad.
thanx lee, a few questions
1) I noticed you used cond instead of if? what is the advantage of cond over if? I thought cond was if there were more than 2 expressions
2) I noticed you used (prin1) instead of (princ), what's the difference here?
3) I'm not familiar with using Polar coords, what's the advantage over Cartesian coords?
Bookmarks