j_spawn_h Posted April 27, 2013 Share Posted April 27, 2013 This does what I want except for one thing. I am not sure how to change it. I only want it to ask me once what the spacing is, but it is asking me each line for spacing. ;Version 1.00 (defun c:cs (/) (and (setq ss (ssget "_:L" '((0 . "LINE")))) (while (setq en (ssname ss 0)) (setq ed (entget en)) (setq p10 (cdr (assoc 10 ed))) (setq p11 (cdr (assoc 11 ed))) (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11)) (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11)))) ;(setq d1d (/ d2d 12.)) ;(setq d1c (fix (+ d1d 0.501))) (setq c (getstring "\nWhat is the spacing? (24,16,12): ")) (if (= c "24") (cond ((<= d2d 118)(setq e "2x6")) ((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8")) ((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10")) ((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12")) ((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (if (= c "16") (cond ((<= d2d 144)(setq e "2x6")) ((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8")) ((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10")) ((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12")) ((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (if (= c "12") (cond ((<= d2d 167)(setq e "2x6")) ((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8")) ((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10")) ((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12")) ((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun ;-------TEXT JUSTIFICATION---------------------------------------- (setq lan (angle p10 p11)) (setq ad (radians->degrees lan)) (if (and (> ad 90.1) (<= ad 270.1)) (progn (setq ptemp p10 p10 p11 p11 ptemp lan (angle p10 p11) ad (radians->degrees lan)) );end progn );end if (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +)) (setq r3(entmake (list (cons 0 "TEXT") (cons 8 (getvar "CLAYER")) (cons 7 (getvar "TEXTSTYLE")) (cons 40 (getvar "TEXTSIZE")) (cons 41 0.80) (cons 72 4) (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1)) ;(getvar "TEXTSIZE"))))) (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1)) (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE"))))))) (setq gg(cons 50 lan)) (setq rg(cons 1 (strcat e))) );end list );end entmake );end setq r3 (ssdel en ss)));end and (prin1) );end defun Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted April 27, 2013 Author Share Posted April 27, 2013 I figured it out now for some reason it is giving me an error. ; error: bad argument type: stringp nil But when I run one of my other lisps then run this one it works. Any ideas on why? ;Version 1.00 (defun c:cs (/) (setq c (getstring "\nWhat is the spacing? (24,16,12): ")) (and (setq ss (ssget "_:L" '((0 . "LINE")))) (while (setq en (ssname ss 0)) (setq ed (entget en)) (setq p10 (cdr (assoc 10 ed))) (setq p11 (cdr (assoc 11 ed))) (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) p10 p11)) (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11)))) ;(setq d1d (/ d2d 12.)) ;(setq d1c (fix (+ d1d 0.501))) (if (= c "24") (cond ((<= d2d 118)(setq e "2x6")) ((and(>= d2d 118.01)(<= d2d 150))(setq e "2x8")) ((and(>= d2d 150.01)(<= d2d 177))(setq e "2x10")) ((and(>= d2d 177.01)(<= d2d 209))(setq e "2x12")) ((and(>= d2d 209.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (if (= c "16") (cond ((<= d2d 144)(setq e "2x6")) ((and(>= d2d 144.01)(<= d2d 183))(setq e "2x8")) ((and(>= d2d 183.01)(<= d2d 217))(setq e "2x10")) ((and(>= d2d 217.01)(<= d2d 256))(setq e "2x12")) ((and(>= d2d 256.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (if (= c "12") (cond ((<= d2d 167)(setq e "2x6")) ((and(>= d2d 167.01)(<= d2d 211))(setq e "2x8")) ((and(>= d2d 211.01)(<= d2d 251))(setq e "2x10")) ((and(>= d2d 251.01)(<= d2d 296))(setq e "2x12")) ((and(>= d2d 296.01)(<= d2d 500))(setq e "Change Spacing")) );end cond );end if (defun radians->degrees (r)(cvunit r "radian" "degree"));end rad defun ;-------TEXT JUSTIFICATION---------------------------------------- (setq lan (angle p10 p11)) (setq ad (radians->degrees lan)) (if (and (> ad 90.1) (<= ad 270.1)) (progn (setq ptemp p10 p10 p11 p11 ptemp lan (angle p10 p11) ad (radians->degrees lan)) );end progn );end if (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - +)) (setq r3(entmake (list (cons 0 "TEXT") (cons 8 (getvar "CLAYER")) (cons 7 (getvar "TEXTSTYLE")) (cons 40 (getvar "TEXTSIZE")) (cons 41 0.80) (cons 72 4) (setq fg(cons 10 ' (0.0 0.0)));(setq r1(polar mpt (dir lan (+ 1)) ;(getvar "TEXTSIZE"))))) (setq hg(cons 11 (setq r2(polar mpt (dir lan (* 0.5 pi));(+ 1)) (+ (* 0.5 (atof width)) (* 0.8 (getvar "TEXTSIZE"))))))) (setq gg(cons 50 lan)) (setq rg(cons 1 (strcat e))) );end list );end entmake );end setq r3 (ssdel en ss)));end and (prin1) );end defun Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2013 Share Posted April 27, 2013 The width variable has no value and it returns nil which would cause the code to return error at the command line . (setq hg (cons 11 (setq r2 (polar mpt (dir lan (* 0.5 pi)) (+ (* 0.5 (atof [color=red][b]width[/b][/color])) (* 0.8 (getvar "TEXTSIZE")) ) ) ) ) ) And localize the variables like the following . (defun c:cs (/ A AD B C D2D DIR E ED EN FG GG HG LAN MPT P10 P11 PTEMP R2 R3 RG SS WIDTH) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2013 Share Posted April 27, 2013 What are you trying to accomplish ? Quote Link to comment Share on other sites More sharing options...
MSasu Posted April 27, 2013 Share Posted April 27, 2013 As Tharwat already pointed, the WIDTH variable isn't allocated, so it will generate an error when you attempt to use it in an evaluation. You stated that after using a particular routine, the trouble-maker one just start to work - you didn't posted the code of that second routine, but the reason it helps is that you probably have a variable with the same name in it, so when call CS command the variable can now be evaluated. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 27, 2013 Share Posted April 27, 2013 Try this draft at the moment after removing the width variable (defun c:cs (/ radians->degrees a ad b c d2d dir e ed en lan mpt p10 p11 ptemp ss ) (defun radians->degrees (r) (cvunit r "radian" "degree")) (if (and (progn (initget 7 "12 16 24") (setq c (getkword "\nWhat is the spacing? (24,16,12): ")) ) (setq ss (ssget "_:L" '((0 . "LINE")))) ) (progn (while (setq en (ssname ss 0)) (setq ed (entget en)) (setq mpt (mapcar '(lambda (a b) (* (+ a b) 0.5)) (setq p10 (cdr (assoc 10 ed))) (setq p11 (cdr (assoc 11 ed))) ) ) (setq d2d (distance (cdr (reverse p10)) (cdr (reverse p11)))) (if (= c "24") (cond ((<= d2d 118) (setq e "2x6")) ((and (>= d2d 118.01) (<= d2d 150)) (setq e "2x8")) ((and (>= d2d 150.01) (<= d2d 177)) (setq e "2x10")) ((and (>= d2d 177.01) (<= d2d 209)) (setq e "2x12")) ((and (>= d2d 209.01) (<= d2d 500)) (setq e "Change Spacing") ) ) ) (if (= c "16") (cond ((<= d2d 144) (setq e "2x6")) ((and (>= d2d 144.01) (<= d2d 183)) (setq e "2x8")) ((and (>= d2d 183.01) (<= d2d 217)) (setq e "2x10")) ((and (>= d2d 217.01) (<= d2d 256)) (setq e "2x12")) ((and (>= d2d 256.01) (<= d2d 500)) (setq e "Change Spacing") ) ) ) (if (= c "12") (cond ((<= d2d 167) (setq e "2x6")) ((and (>= d2d 167.01) (<= d2d 211)) (setq e "2x8")) ((and (>= d2d 211.01) (<= d2d 251)) (setq e "2x10")) ((and (>= d2d 251.01) (<= d2d 296)) (setq e "2x12")) ((and (>= d2d 296.01) (<= d2d 500)) (setq e "Change Spacing") ) ) ) (setq lan (angle p10 p11)) (setq ad (radians->degrees lan)) (if (and (> ad 90.1) (<= ad 270.1)) (progn (setq ptemp p10 p10 p11 p11 ptemp lan (angle p10 p11) ad (radians->degrees lan) ) ) ) (setq dir (if (< (* pi 0.5) lan (* pi 1.5)) - + ) ) (entmake (list (cons 0 "TEXT") (cons 8 (getvar "CLAYER")) (cons 7 (getvar "TEXTSTYLE")) (cons 40 (getvar "TEXTSIZE")) (cons 41 0.80) (cons 72 4) (cons 10 '(0.0 0.0)) (cons 11 (polar mpt (dir lan (* 0.5 pi)) (* 0.8 (getvar "TEXTSIZE")) ) ) (cons 50 lan) (cons 1 (strcat e)) ) ) (ssdel en ss) ) ) ) (prin1) ) Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted April 27, 2013 Author Share Posted April 27, 2013 I used a piece of another lisp that is why that was in there. I changed and it works great. Tharwat, Well my goal is to use this and try and merge another lisp so I can swipe a lot of lines and have it label them with a dimension and say what they are. So any lines that equal the same result they will be labeld all with the dimension. It may make since looking at my example. I am not good at lisp yet so I am doing one step at a time. example.dwg Quote Link to comment Share on other sites More sharing options...
Tharwat Posted April 28, 2013 Share Posted April 28, 2013 I used a piece of another lisp that is why that was in there. I changed and it works great. Tharwat, Well my goal is to use this and try and merge another lisp so I can swipe a lot of lines and have it label them with a dimension and say what they are. So any lines that equal the same result they will be labeld all with the dimension. It may make since looking at my example. I am not good at lisp yet so I am doing one step at a time. I am talking about the current modified lisp and I have no idea about your second lisp , so I can not guess what the second lisp does . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.