j_spawn_h Posted October 23, 2014 Share Posted October 23, 2014 It works but it takes a long time to process. I was thinking my coding can be changed to work more proficient. (defun c:clj (/ c d2d d3d e) (setq layerset (getvar "clayer")) (command "layiso" pause "") (command "_.layer" "m" "s-frm-2x6" "c" "blue" "" "") (command "_.layer" "m" "s-frm-2x8" "c" "t" "242,103,34" "" "") (command "_.layer" "m" "s-frm-2x10" "c" "t" "147,39,143" "" "") (command "_.layer" "m" "s-frm-2x12" "c" "t" "255,255,255" "" "") (command "_.layer" "m" "s-anno-egtext" "p" "no" "s-anno-egtext" "s" "s-anno-egtext" "" "") (setq c (getstring "\nWhat is the spacing? (24,19.2,16,12): ")) (command "textsize" "6" "") (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 d2d (- d3d 7.0)) ;(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 "19.2") (cond ((<= d2d 132)(setq e "2x6")) ((and(>= d2d 132.01)(<= d2d 167))(setq e "2x8")) ((and(>= d2d 167.01)(<= d2d 198))(setq e "2x10")) ((and(>= d2d 198.01)(<= d2d 234))(setq e "2x12")) ((and(>= d2d 234.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 (polar mpt (dir lan (+ 1)); (* pi 0.5)) (getvar "TEXTSIZE")))) (setq hg(cons 11 (polar mpt (dir lan (+ 1)); (* pi 0.5)) (getvar "TEXTSIZE")))) (setq gg(cons 50 lan)) (setq rg(cons 1 (strcat e))) );end list );end entmake );end setq r3 (if (= e "2x6")(command "_change" ss "" "p" "la" "s-frm-2x6" "" "") );end if (if (= e "2x8")(command "_change" ss "" "p" "la" "s-frm-2x8" "" "") );end if (if (= e "2x10")(command "_change" ss "" "p" "la" "s-frm-2x10" "" "") );end if (if (= e "2x12")(command "_change" ss "" "p" "la" "s-frm-2x12" "" "") );end if (command "layuniso" "") (ssdel en ss)));end and (setvar "clayer" layerset) (prin1) );end defun Quote Link to comment Share on other sites More sharing options...
BIGAL Posted October 23, 2014 Share Posted October 23, 2014 A couple of suggestions rather than make layers just check they exist put this in a defun and check for 1st layer name if not exist then run defun. Not sure "(and (setq".... and what ? where is end of and Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted October 23, 2014 Author Share Posted October 23, 2014 Bigal thanks for the suggestion but i pieced this together and added things to it. Still have not learned enough. Could you point me in the direction on how to do that? Like a good site or something. Quote Link to comment Share on other sites More sharing options...
MSasu Posted October 23, 2014 Share Posted October 23, 2014 J_spawn_h, your excerpt appears to be incomplete, so until you didn't post it entirely, one cannot review it to identify the source of latency. Quote Link to comment Share on other sites More sharing options...
ketxu Posted October 23, 2014 Share Posted October 23, 2014 And why you have to layiso before ? Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted October 23, 2014 Author Share Posted October 23, 2014 MSasu, That is the entire lisp. It works it just takes a long process to get to the end result. I am still not that great at writing. I thought it was complete since it worked. ketxu, I layiso because there are a lot of lines and I just need certain ones to change. Quote Link to comment Share on other sites More sharing options...
MSasu Posted October 23, 2014 Share Posted October 23, 2014 Maybe I miss something, but your code excerpt had 3 unbalanced statements (DEFUN, AND and WHILE) so it wouldn't be evaluated in AutoCAD. How do you run it? What software were you using? What do you mean by "long process"? Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted October 24, 2014 Author Share Posted October 24, 2014 MSasu, I am new at this if you have not noticed. I trying to understand it, but you say the defun,and,& while is unbalanced. I am guessing you are saying that they should not work due to they are not complete (as in closed), or something like that. I load it as a lisp in cad type the clj and it works. Being that the they are as you say unbalanced could be why it takes for ever to run. That's why I was asking for help. Quote Link to comment Share on other sites More sharing options...
jdiala Posted October 25, 2014 Share Posted October 25, 2014 j_spawn_h, I'm in a mood to type so here it is. I haven't address your layer issues, you can figure that out. Read about tblsearch and entmake (layer). (defun C:clj (/ tag_beam ss c i en p1 p2 mpt d a) ;;;;; jdiala ;;;;; ;; cadtutor.net ;; (defun tag_beam ( beam ) (entmake (list (cons 0 "TEXT") (cons 40 6) (cons 41 0.80) (cons 72 1) (cons 73 2) (cons 10 (setq mpt (polar mpt (+ (/ pi 2.) a) 5))) (cons 11 mpt) (cons 50 a) (cons 1 beam) (cons 8 "s-anno-egtext") ) ) (if (not (= beam "Change Spacing!!!")) (vla-put-layer en (strcat "s-frm-" beam)) ) ) (if (setq ss (ssget "_:L" '((0 . "LINE")))) (progn (princ "What is the spacing? (1 = 12) (2 = 16) (3 = 19.2) (4 = 24) \nPress 1-4:") (while (not (member c (list 49 50 51 52)) ) (setq c (cadr (grread))) ) (repeat (setq i (sslength ss)) (setq en (vlax-ename->vla-object (ssname ss (setq i (1- i)))) p1 (vla-get-StartPoint en) p2 (vla-get-EndPoint en) mpt (mapcar '(lambda (a b) (/ (+ a b) 2.0)) (safearray-value (vlax-variant-value p1)) (safearray-value (vlax-variant-value p2))) d (vla-get-Length en) a (LM:MakeReadable (vla-get-Angle en)) ) (cond ( (= c 52) (cond ( (<= d 118) (tag_beam "2x6") ) ( (and (> d 118) (<= d 150) ) (tag_beam "2x8") ) ( (and (> d 150) (<= d 177) ) (tag_beam "2x10") ) ( (and (> d 177) (<= d 209) ) (tag_beam "2x12")) ( (> d 209) (tag_beam "Change Spacing!!!") ) ) ) ( (= c 51) (cond ( (<= d 132) (tag_beam "2x6") ) ( (and (> d 132) (<= d 167) ) (tag_beam "2x8") ) ( (and (> d 167) (<= d 198) ) (tag_beam "2x10") ) ( (and (> d 198) (<= d 234) ) (tag_beam "2x12") ) ( (> d 234) (tag_beam "Change Spacing!!!") ) ) ) ( (= c 50) (cond ( (<= d 144) (tag_beam "2x6") ) ( (and (> d 144) (<= d 183) ) (tag_beam "2x8") ) ( (and (> d 183) (<= d 217) ) (tag_beam "2x10") ) ( (and (> d 217.01) (<= d 256) ) (tag_beam "2x12") ) ( (> d 256) (tag_beam "Change Spacing!!!") ) ) ) ( (= c 49) (cond ( (<= d 167) (tag_beam "2x6") ) ( (and (> d 167) (<= d 211) ) (tag_beam "2x8") ) ( (and (> d 211) (<= d 251) ) (tag_beam "2x10") ) ( (and (> d 251) (<= d 296) ) (tag_beam "2x12")) ( (> d 296.01) (tag_beam "Change Spacing!!!")) ) ) ) ) ) (princ "None selected!") ) (princ) ) (defun LM:MakeReadable ( a ) ;; © Lee Mac ~ 12.06.10 (cond ( (and (> a (/ pi 2)) (<= a pi)) (- a pi) ) ( (and (> a pi) (<= a (/ (* 3 pi) 2))) (+ a pi) ) ( a ) ) ) Quote Link to comment Share on other sites More sharing options...
j_spawn_h Posted October 25, 2014 Author Share Posted October 25, 2014 jdiala, Thank you! That works a lot faster. And I will read about tblseach and entmake. 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.