giovanni64 Posted August 13, 2011 Share Posted August 13, 2011 (edited) Maybe somebody can help me with the following LISP routine: (DEFUN C:AETXT () (defun *error* (report)(grtext)(princ)) ;(setq *error* nil) ;for switching off the "*error*" Function (defun ac (v / v) (assoc v tasa)) (defun ers (x y z)(setq tasa (subst (cons x y) z tasa))) (menucmd "S=BLOCK 3")(setq asa (ssget)) (if (= asa nil)(print "No Object selected ") (progn(setq wasa (sslength asa))(menucmd "S=S"))) (setq sp '(0 0 0)) (if (/= asa nil) (progn (setq clr (getint "\nNew Color, Return, if no change: ")) (setq stn (getstring "\nNew Text Style, Return, if no change: ")) (setq brn (getreal "\nNew Width, Return, if no change: ")) (setq thn (getreal "\nNew Text hight, Return, if no change: ")) (setq swn (getreal "\nNew Angle, Return, if no change: ")))) (if (/= swn nil)(setq swn (/ (* pi swn) 180.0))) (setq z1 0) (while (< z1 wasa) (if (= "TEXT" (cdr (assoc 0 (setq tasa (entget (ssname asa z1)))))) (progn (setq cla (ac 62) ; 62=Color tha (ac 40) bra (ac 41) ; 40=height, 41=width factor swa (ac 51) sta (ac 7); 51=obliq.ang, 7=Textstyle ysa (cddr tsa) sp (cons (car sp) ysa)) (if (/= swn nil)(ers 51 swn swa)) (if (and brn (> brn 0.0)) (ers 41 brn bra)) (if (and thn (> thn 0.0)) (ers 40 thn tha)) (if (/= stn "")(ers 7 stn sta)) (if (/= clr "")(ers 62 clr cla)) (entmod tasa))) (setq z1 (1+ z1))) (grtext)(princ)) ;EOF C:AETXT.LSP I would like to only change the text hight. However, it only works with punching in a value of the color but reclusively changing the text hight nothing will change. Edited August 22, 2011 by SLW210 Added Code Tags! Quote Link to comment Share on other sites More sharing options...
MSasu Posted August 13, 2011 Share Posted August 13, 2011 The color is not changed only if is set as ByLayer since there is no sub-list to be modified by SUBST. Have made some corrections to your code, please compare it with the original to see the changes (have re-formatted also to be able to check it): (DEFUN C:AETXT() (defun *error* (report) (grtext) (princ)) (defun ac (v / v) (assoc v tasa)) (defun ers (x y z) (setq tasa (subst (cons x y) z tasa))) (setq asa (ssget '((0 . "TEXT")))) (if (= asa nil) (print "No Object selected ") (setq wasa (sslength asa)) ) (setq sp '(0 0 0)) (if (/= asa nil) (progn (setq clr (getint "\nNew Color, Return, if no change: ")) (setq stn (getstring "\nNew Text Style, Return, if no change: ")) (setq brn (getreal "\nNew Width, Return, if no change: ")) (setq thn (getreal "\nNew Text hight, Return, if no change: ")) (setq swn (getreal "\nNew Angle, Return, if no change: ")) ) ) (if (/= swn nil) (setq swn (/ (* pi swn) 180.0))) (setq z1 0) (while (< z1 wasa) (setq cla (ac 62) ; 62=Color tha (ac 40) ; 40=height bra (ac 41) ; 41=width factor swa (ac 51) ; 51=obliq.ang sta (ac 7) ; 7=Textstyle ysa (cddr tsa) ;??? sp (cons (car sp) ysa)) ;??? (if (/= swn nil) (ers 51 swn swa)) (if (and brn (> brn 0.0)) (ers 41 brn bra)) (if (and thn (> thn 0.0)) (ers 40 thn tha)) (if (/= stn "") (ers 7 stn sta)) (if (/= clr "") (if cla (ers 62 clr cla) (setq tasa (append tasa (list (cons 62 clr)))) ) ) (entmod tasa) (setq z1 (1+ z1)) ) (princ) ) Regards, Mircea Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 13, 2011 Author Share Posted August 13, 2011 The color is not changed only if is set as ByLayer since there is no sub-list to be modified by SUBST. Have made some corrections to your code, please compare it with the original to see the changes (have re-formatted also to be able to check it): (DEFUN C:AETXT() (defun *error* (report) (grtext) (princ)) (defun ac (v / v) (assoc v tasa)) (defun ers (x y z) (setq tasa (subst (cons x y) z tasa))) (setq asa (ssget '((0 . "TEXT")))) (if (= asa nil) (print "No Object selected ") (setq wasa (sslength asa)) ) (setq sp '(0 0 0)) (if (/= asa nil) (progn (setq clr (getint "\nNew Color, Return, if no change: ")) (setq stn (getstring "\nNew Text Style, Return, if no change: ")) (setq brn (getreal "\nNew Width, Return, if no change: ")) (setq thn (getreal "\nNew Text hight, Return, if no change: ")) (setq swn (getreal "\nNew Angle, Return, if no change: ")) ) ) (if (/= swn nil) (setq swn (/ (* pi swn) 180.0))) (setq z1 0) (while (< z1 wasa) (setq cla (ac 62) ; 62=Color tha (ac 40) ; 40=height bra (ac 41) ; 41=width factor swa (ac 51) ; 51=obliq.ang sta (ac 7) ; 7=Textstyle ysa (cddr tsa) ;??? sp (cons (car sp) ysa)) ;??? (if (/= swn nil) (ers 51 swn swa)) (if (and brn (> brn 0.0)) (ers 41 brn bra)) (if (and thn (> thn 0.0)) (ers 40 thn tha)) (if (/= stn "") (ers 7 stn sta)) (if (/= clr "") (if cla (ers 62 clr cla) (setq tasa (append tasa (list (cons 62 clr)))) ) ) (entmod tasa) (setq z1 (1+ z1)) ) (princ) ) Regards, Mircea Thanks for your quick reply. However, it doesn't work even with punching in a value for the color. I'm really confused and I feel so sorry for your effort. Anyway I hope you can help me so I will be able to only change the text hight. Regards, Giovanni Quote Link to comment Share on other sites More sharing options...
pBe Posted August 14, 2011 Share Posted August 14, 2011 Maybe somebody can help me with the following LISP routine:I would like to only change the text hight. However, it only works with punching in a value of the color but reclusively changing the text hight nothing will change. Can you explain that to us again? I've tested your code, it appears to be working as its supposed to. Quote Link to comment Share on other sites More sharing options...
dbroada Posted August 14, 2011 Share Posted August 14, 2011 do you have the text height set to 0 in the STYLE? If not you can't change it on the drawing. Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2011 Share Posted August 14, 2011 Give this a try: (defun c:aetxt ( / *error* _subst ang col ent hgt i ss sty wid ) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (defun _subst ( key value elist ) (if (assoc key elist) (subst (cons key value) (assoc key elist) elist) (append elist (list (cons key value))) ) ) (if (setq ss (ssget '((0 . "TEXT")))) (progn (while (and (progn (initget 4) (setq col (getint "\nNew Color <No Change>: "))) (not (<= 0 col 256)) ) (princ "\nValue must be 0 <= value <= 256.") ) (while (not (or (eq "" (setq sty (getstring t "\nNew Style <No Change>: "))) (tblsearch "STYLE" sty) ) ) (princ "\nStyle doesn't exist.") ) (if (eq "" sty) (setq sty nil)) (initget 6) (setq wid (getdist "\nNew Width <No Change>: ")) (initget 6) (setq hgt (getdist "\nNew Height <No Change>: ")) (setq ang (getangle "\nNew Oblique Angle <No Change>: ")) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i))))) (if col (setq ent (_subst 62 col ent))) (if sty (setq ent (_subst 7 sty ent))) (if wid (setq ent (_subst 41 wid ent))) (if hgt (setq ent (_subst 40 hgt ent))) (if ang (setq ent (_subst 51 ang ent))) (if (entmod ent) (entupd (cdr (assoc -1 ent))) ) ) ) ) (princ) ) Or, if you were just trying to change Text Height: (defun c:aetxt ( / *error* en ht i ss ) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (if (and (setq ss (ssget '((0 . "TEXT")))) (setq ht (getdist "\nSpecify Text Height: ")) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i)))) en (subst (cons 40 ht) (assoc 40 en) en) ) (if (entmod en) (entupd (cdr (assoc -1 en))) ) ) ) (princ) ) Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 14, 2011 Author Share Posted August 14, 2011 (edited) Sorry, if you've used the routine which I posted at the beginning with AutoCAD 2011 than the text will only change if I change the color too. So have a look again, please. (DEFUN C:AETXT () (defun *error* (report)(grtext)(princ)) ;(setq *error* nil) ;for switching off the "*error*" Function (defun ac (v / v) (assoc v tasa)) (defun ers (x y z)(setq tasa (subst (cons x y) z tasa))) (menucmd "S=BLOCK 3")(setq asa (ssget)) (if (= asa nil)(print "No Object selected ") (progn(setq wasa (sslength asa))(menucmd "S=S"))) (setq sp '(0 0 0)) (if (/= asa nil) (progn (setq clr (getint "\nNew Color, Return, if no change: ")) (setq stn (getstring "\nNew Text Style, Return, if no change: ")) (setq brn (getreal "\nNew Width, Return, if no change: ")) (setq thn (getreal "\nNew Text hight, Return, if no change: ")) (setq swn (getreal "\nNew Angle, Return, if no change: ")))) (if (/= swn nil)(setq swn (/ (* pi swn) 180.0))) (setq z1 0) (while (< z1 wasa) (if (= "TEXT" (cdr (assoc 0 (setq tasa (entget (ssname asa z1)))))) (progn (setq cla (ac 62) ; 62=Color tha (ac 40) bra (ac 41) ; 40=height, 41=width factor swa (ac 51) sta (ac 7); 51=obliq.ang, 7=Textstyle ysa (cddr tsa) sp (cons (car sp) ysa)) (if (/= swn nil)(ers 51 swn swa)) (if (and brn (> brn 0.0)) (ers 41 brn bra)) (if (and thn (> thn 0.0)) (ers 40 thn tha)) (if (/= stn "")(ers 7 stn sta)) (if (/= clr "")(ers 62 clr cla)) (entmod tasa))) (setq z1 (1+ z1))) (grtext)(princ)) ;EOF C:AETXT.LSP Kind regards, Giovanni Edited August 22, 2011 by SLW210 Add code tags! Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 14, 2011 Author Share Posted August 14, 2011 Give this a try: (defun c:aetxt ( / *error* _subst ang col ent hgt i ss sty wid ) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (defun _subst ( key value elist ) (if (assoc key elist) (subst (cons key value) (assoc key elist) elist) (append elist (list (cons key value))) ) ) (if (setq ss (ssget '((0 . "TEXT")))) (progn (while (and (progn (initget 4) (setq col (getint "\nNew Color <No Change>: "))) (not (<= 0 col 256)) ) (princ "\nValue must be 0 <= value <= 256.") ) (while (not (or (eq "" (setq sty (getstring t "\nNew Style <No Change>: "))) (tblsearch "STYLE" sty) ) ) (princ "\nStyle doesn't exist.") ) (if (eq "" sty) (setq sty nil)) (initget 6) (setq wid (getdist "\nNew Width <No Change>: ")) (initget 6) (setq hgt (getdist "\nNew Height <No Change>: ")) (setq ang (getangle "\nNew Oblique Angle <No Change>: ")) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i))))) (if col (setq ent (_subst 62 col ent))) (if sty (setq ent (_subst 7 sty ent))) (if wid (setq ent (_subst 41 wid ent))) (if hgt (setq ent (_subst 40 hgt ent))) (if ang (setq ent (_subst 51 ang ent))) (if (entmod ent) (entupd (cdr (assoc -1 ent))) ) ) ) ) (princ) ) Or, if you were just trying to change Text Height: (defun c:aetxt ( / *error* en ht i ss ) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (if (and (setq ss (ssget '((0 . "TEXT")))) (setq ht (getdist "\nSpecify Text Height: ")) ) (repeat (setq i (sslength ss)) (setq en (entget (ssname ss (setq i (1- i)))) en (subst (cons 40 ht) (assoc 40 en) en) ) (if (entmod en) (entupd (cdr (assoc -1 en))) ) ) ) (princ) ) Hi Lee Mac, both routines are working outstanding. However, now I'm completely confused because you have written a different routine and I've seen how much more I have to learn. I thought to see my old routine used to verify what I've done wrong. Anyway thank you very much for your great help. Regards, Giovanni Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2011 Share Posted August 14, 2011 However, now I'm completely confused because you have written a different routine and I've seen how much more I have to learn.I thought to see my old routine used to verify what I've done wrong. Anyway thank you very much for your great help. Hopefully you can learn from my examples and see how the code could be written differently, and perhaps spot where you went wrong in the process. I didn't have time to scour your code for the mistakes - it was quicker to write something new. Also, please read this regarding posting code. Lee Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 14, 2011 Author Share Posted August 14, 2011 Hopefully you can learn from my examples and see how the code could be written differently, and perhaps spot where you went wrong in the process. I didn't have time to scour your code for the mistakes - it was quicker to write something new. Also, please read this regarding posting code. Lee Thanks again and for the hint. Definitely I learn from your codes and I will check what I made wrong. Giovanni Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 14, 2011 Share Posted August 14, 2011 You're welcome - good luck! Lee Quote Link to comment Share on other sites More sharing options...
irneb Posted August 15, 2011 Share Posted August 15, 2011 do you have the text height set to 0 in the STYLE? If not you can't change it on the drawing.I'd differ with you on that. It's not "simple" to change the height if you use the text command. But even if the style has a predefined height an entmake/entmod can still use a different value. Quote Link to comment Share on other sites More sharing options...
dbroada Posted August 15, 2011 Share Posted August 15, 2011 I'd differ with you on that. It's not "simple" to change the height if you use the text command. But even if the style has a predefined height an entmake/entmod can still use a different value.as I posted that I thought "I'm sure it can be done in LISP". I really let it go just in case the OP's problem really was that simple but thanks for the correction. Quote Link to comment Share on other sites More sharing options...
SLW210 Posted August 15, 2011 Share Posted August 15, 2011 giovanni64, Please READ the CODE POSTING GUIDELINES and then EDIT your posts. Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 20, 2011 Author Share Posted August 20, 2011 Hi Lee, one of your routines you provided to me is not working the way I expect, i.e. changing the text style. I maybe doing something wrong at the input. Can you please explain why I can't change text style? I guess there is a mistake in your routine (if (eq "" (setq sty (getstring t "\nNew Style : "))) -- I think the eq shall be a = sign. (defun c:aetxt ( / *error* _subst ang col ent hgt i ss sty wid ) (defun *error* ( msg ) (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")) (princ (strcat "\nError: " msg)) ) (princ) ) (defun _subst ( key value elist ) (if (assoc key elist) (subst (cons key value) (assoc key elist) elist) (append elist (list (cons key value))) ) ) (if (setq ss (ssget '((0 . "TEXT")))) (progn (while (and (progn (initget 4) (setq col (getint "\nNew Color <No Change>: "))) (not (<= 0 col 256)) ) (princ "\nValue must be 0 <= value <= 256.") ) (while (not (or (eq "" (setq sty (getstring t "\nNew Style <No Change>: "))) (tblsearch "STYLE" sty) ) ) (princ "\nStyle doesn't exist.") ) (if (eq "" sty) (setq sty nil)) (initget 6) (setq wid (getdist "\nNew Width <No Change>: ")) (initget 6) (setq hgt (getdist "\nNew Height <No Change>: ")) (setq ang (getangle "\nNew Oblique Angle <No Change>: ")) (repeat (setq i (sslength ss)) (setq ent (entget (ssname ss (setq i (1- i))))) (if col (setq ent (_subst 62 col ent))) (if sty (setq ent (_subst 7 sty ent))) (if wid (setq ent (_subst 41 wid ent))) (if hgt (setq ent (_subst 40 hgt ent))) (if ang (setq ent (_subst 51 ang ent))) (if (entmod ent) (entupd (cdr (assoc -1 ent))) ) ) ) ) (princ) ) Regards Giovanni Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 20, 2011 Share Posted August 20, 2011 The use of "=" over "eq" will make no difference. The code is working as expected for me, what problems are you having? Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 20, 2011 Author Share Posted August 20, 2011 The use of "=" over "eq" will make no difference. The code is working as expected for me, what problems are you having? When I type in Calibri as a new Textstyle then it'll say Style doesn't exist. So what I'm doing wrong, please? Giovanni Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2011 Share Posted August 21, 2011 Does the TextStyle "Calibri" exist in your drawing? Quote Link to comment Share on other sites More sharing options...
giovanni64 Posted August 21, 2011 Author Share Posted August 21, 2011 No, it doesn't exist! Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 21, 2011 Share Posted August 21, 2011 No, it doesn't exist! Well that would answer your question then 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.