Jump to content

Text hight only change


giovanni64

Recommended Posts

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 by SLW210
Added Code Tags!
Link to comment
Share on other sites

  • Replies 25
  • Created
  • Last Reply

Top Posters In This Topic

  • giovanni64

    10

  • Lee Mac

    7

  • irneb

    2

  • Baber62

    2

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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)
)

Link to comment
Share on other sites

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 by SLW210
Add code tags!
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. :thumbsup:

 

Lee

Link to comment
Share on other sites

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. :thumbsup:

 

Lee

 

 

Thanks again and for the hint. Definitely I learn from your codes and I will check what I made wrong.

 

Giovanni

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

:unsure:

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...