Jump to content

Controlling text height through lisp


dangrens

Recommended Posts

Hi.

 

I am looking for a lisp that can control text height and link back to drawing scale...Ie; if the drawing scale (dim scale) is set to 20...the text height is changed to 40..or 60 for larger text...

 

I had a pulldown that controlled this at a former place of work...User would be prompted to set the dwg, and the rest was set up for you...My lisp writing is not amazing nowdays...could really use some help...Please..:)

Link to comment
Share on other sites

This is what I use:

;| Text size - This one you can get text size by picking text, entering a value, picking two points,
   or it will calculate it from CANNOSCALEVALUE if in Model Space.  It doesn't change on Escape.
  (load "TXTsize.LSP") tas ;
  by: Tom Beauford
  Leon County Public Works Engineering
===============================================|;
(defun C:tas (/ *error* vars tnt ts txt etp style)
 (setq vars (mapcar '(lambda (x) (cons x (getvar x))) '("luprec" "modemacro" "cmdecho")))
 (defun *error* (msg)
   ;; Reset variables
   (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )

 (setvar "luprec" 
 (setvar "cmdecho" 0)
 (grtext -1 "Select Text, Mtext or Attribute. Enter for more Options.")
 (setq tnt(nentsel "\nSelect Text Entity: "))
 (cond
((= 1 (getvar "cvport"))(setq ts "0.1"))
((= 1 (getvar "TILEMODE"))(setq ts (rtos(/ 0.1 (getvar 'cannoscalevalue)))))
(T(setq ts (rtos(/(caddr (trans '(0 0 1) 3 2))10))))
 )
 (if (= "0" (substr ts (strlen ts)))
   (while (= (atof ts)(atof (substr ts 1 (- (strlen ts)1))))
     (setq ts(substr ts 1 (- (strlen ts)1)))
   );while
 );if
 (setq txt (strcat"\nChange Text Size from " (rtos(getvar "textsize")) " to :<" ts "> "))
 (if tnt (setq etp (cdr(assoc 0 (entget(car tnt))))))
 (if (or(= "TEXT" etp)(= "MTEXT" etp)(= "ATTRIB" etp))
   (progn
     (setq style (getvar "textstyle")
           style (tblobjname "style" style)
           xdata (cadr (assoc -3 (entget style '("AcadAnnotative"))))
           tnt(cdr(assoc 40 (entget (car tnt))))
     );setq
     (if(and xdata (= (cdr (nth 4 xdata)) 1))
       (setq tnt(* tnt (getvar "cannoscalevalue")))
     );if
   );progn
   (progn
     (grtext -1 "Enter Size, Pick 2 Points or Accept Default.")
     (setq tnt (getdist txt))
   );progn
 );if
 (if (or(= tnt nil)(= tnt 0.0))
   (setq tnt (atof ts))
 );if
   (setvar "textsize" tnt)
 (setq tnt (rtos(getvar "textsize")))
 (if (= "0" (substr tnt (strlen tnt)))
   (while (= (atof tnt)(atof (substr tnt 1 (- (strlen tnt)1))))
     (setq tnt(substr tnt 1 (- (strlen tnt)1)))
   );while
 );if
 (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
 (grtext -1 "") ;Clear status line
 (vl-cmdf "redraw")
 (princ)
)

Rather than entering a value or picking two points just hit enter and it will set text height from CANNOSCALEVALUE if in Model Space.

Edited by tombu
Added (vl-cmdf "redraw") to make sure the status bar is cleared.
Link to comment
Share on other sites

  • 3 years later...
This is what I use:

;| Text size - This one you can get text size by picking text, entering a value, picking two points,
   or it will calculate it from CANNOSCALEVALUE if in Model Space.  It doesn't change on Escape.
  (load "TXTsize.LSP") tas ;
  by: Tom Beauford
  Leon County Public Works Engineering
===============================================|;
(defun C:tas (/ *error* vars tnt ts txt etp style)
 (setq vars (mapcar '(lambda (x) (cons x (getvar x))) '("luprec" "modemacro" "cmdecho")))
 (defun *error* (msg)
   ;; Reset variables
   (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )

 (setvar "luprec" 
 (setvar "cmdecho" 0)
 (grtext -1 "Select Text, Mtext or Attribute. Enter for more Options.")
 (setq tnt(nentsel "\nSelect Text Entity: "))
 (if(= 1 (getvar "cvport"))
   (setq ts (rtos(getvar "textsize")))
   (setq ts (rtos(/ 0.1 (getvar 'cannoscalevalue))))
 )
 (if (= "0" (substr ts (strlen ts)))
   (while (= (atof ts)(atof (substr ts 1 (- (strlen ts)1))))
     (setq ts(substr ts 1 (- (strlen ts)1)))
   );while
 );if
 (setq txt (strcat"\nChange Text Size from " (rtos(getvar "textsize")) " to :<" ts "> "))
 (if tnt (setq etp (cdr(assoc 0 (entget(car tnt))))))
 (if (or(= "TEXT" etp)(= "MTEXT" etp)(= "ATTRIB" etp))
   (progn
     (setq style (getvar "textstyle")
           style (tblobjname "style" style)
           xdata (cadr (assoc -3 (entget style '("AcadAnnotative"))))
           tnt(cdr(assoc 40 (entget (car tnt))))
     );setq
     (if(and xdata (= (cdr (nth 4 xdata)) 1))
       (setq tnt(* tnt (getvar "cannoscalevalue")))
     );if
   );progn
   (progn
     (grtext -1 "Enter Size, Pick 2 Points or Accept Default.")
     (setq tnt (getdist txt))
   );progn
 );if
 (if (or(= tnt nil)(= tnt 0.0))
   (setq tnt (atof ts))
 );if
   (setvar "textsize" tnt)
 (setq tnt (rtos(getvar "textsize")))
 (if (= "0" (substr tnt (strlen tnt)))
   (while (= (atof tnt)(atof (substr tnt 1 (- (strlen tnt)1))))
     (setq tnt(substr tnt 1 (- (strlen tnt)1)))
   );while
 );if
 (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
 (princ)
)

Rather than entering a value or picking two points just hit enter and it will set text height from CANNOSCALEVALUE if in Model Space.

 

 

Thanks for code.

Link to comment
Share on other sites

This is what I use:

;| Text size - This one you can get text size by picking text, entering a value, picking two points,
   or it will calculate it from CANNOSCALEVALUE if in Model Space.  It doesn't change on Escape.
  (load "TXTsize.LSP") tas ;
  by: Tom Beauford
  Leon County Public Works Engineering
===============================================|;
(defun C:tas (/ *error* vars tnt ts txt etp style)
 (setq vars (mapcar '(lambda (x) (cons x (getvar x))) '("luprec" "modemacro" "cmdecho")))
 (defun *error* (msg)
   ;; Reset variables
   (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
   (if (not (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*"))
     (princ (strcat "\nError: " msg))
   )
   (princ)
 )

 (setvar "luprec" 
 (setvar "cmdecho" 0)
 (grtext -1 "Select Text, Mtext or Attribute. Enter for more Options.")
 (setq tnt(nentsel "\nSelect Text Entity: "))
 (if(= 1 (getvar "cvport"))
   (setq ts (rtos(getvar "textsize")))
   (setq ts (rtos(/ 0.1 (getvar 'cannoscalevalue))))
 )
 (if (= "0" (substr ts (strlen ts)))
   (while (= (atof ts)(atof (substr ts 1 (- (strlen ts)1))))
     (setq ts(substr ts 1 (- (strlen ts)1)))
   );while
 );if
 (setq txt (strcat"\nChange Text Size from " (rtos(getvar "textsize")) " to :<" ts "> "))
 (if tnt (setq etp (cdr(assoc 0 (entget(car tnt))))))
 (if (or(= "TEXT" etp)(= "MTEXT" etp)(= "ATTRIB" etp))
   (progn
     (setq style (getvar "textstyle")
           style (tblobjname "style" style)
           xdata (cadr (assoc -3 (entget style '("AcadAnnotative"))))
           tnt(cdr(assoc 40 (entget (car tnt))))
     );setq
     (if(and xdata (= (cdr (nth 4 xdata)) 1))
       (setq tnt(* tnt (getvar "cannoscalevalue")))
     );if
   );progn
   (progn
     (grtext -1 "Enter Size, Pick 2 Points or Accept Default.")
     (setq tnt (getdist txt))
   );progn
 );if
 (if (or(= tnt nil)(= tnt 0.0))
   (setq tnt (atof ts))
 );if
   (setvar "textsize" tnt)
 (setq tnt (rtos(getvar "textsize")))
 (if (= "0" (substr tnt (strlen tnt)))
   (while (= (atof tnt)(atof (substr tnt 1 (- (strlen tnt)1))))
     (setq tnt(substr tnt 1 (- (strlen tnt)1)))
   );while
 );if
 (mapcar '(lambda (x) (setvar (car x) (cdr x))) vars)
 (princ)
)

Rather than entering a value or picking two points just hit enter and it will set text height from CANNOSCALEVALUE if in Model Space.

 

 

Thanks for code.

 

can you guide me where to mention the height size.

 

i dont know about programming and coding.

 

Thanks.

Link to comment
Share on other sites

Prompts are both on the command line and the status bar (below the command line). If you select a text, mtext, or attribute it will set textsize to match what you selected. Otherwise it will prompt to set the textsize to where at the current view's scale it would plot at a height of 0.1 and give you the option. to "Enter Size, Pick 2 Points or Accept Default".

 

The default plotted text height is set in the line

(setq ts (rtos(/ [color="red"][b]0.1[/b][/color] (getvar 'cannoscalevalue))))

Change the 0.1 to whatever size works best for you.

 

I added (vl-cmdf "redraw") to the code in my previous post to make sure the status bar is cleared. You should add that as well.

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