Rotate Text

Rotate Text

Philip-John
Advocate Advocate
1,626 Views
8 Replies
Message 1 of 9

Rotate Text

Philip-John
Advocate
Advocate

I have got the following lisp to display area inside the box. But the text is in 0°. Can somebody help me to modify the lisp to display text in various angles. i.e 90°, 180°, 270° ?

 

(vl-load-com)
(defun c:TXTAREA (/ area ent flag lst obj pt tmpH)
(if (or (not *Hscl*) (/= (type *Hscl*) 'REAL))
(setq *Hscl* (getvar 'TEXTSIZE))
)
(initget 6)
(setq tmpH (getreal (strcat "\nSpecify Text Height: <" (rtos *Hscl*) ">: ")))
(if (/= tmpH nil)
(setq *Hscl* tmpH)
)
(while (null flag)
(cond ((setq pt (getpoint "\nSpecify internal point <exit>: "))
(if (and (setq lst (entlast))
(vl-cmdf "_.-boundary" pt "")
(setq ent (entlast))
(not (eq lst ent))
)
(progn
(setq obj (vlax-ename->vla-object ent)
area (vla-get-area obj)
)
(entmake (list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 *Hscl*)
(cons 1 (strcat (rtos area 2 2) " m2"))
(cons 50 (angle '(0.0 0.0) (getvar 'UCSXDIR)))
)
)
)
)
)
(T
(setq flag T)
)
)
)
(princ)
)

0 Likes
Accepted solutions (3)
1,627 Views
8 Replies
Replies (8)
Message 2 of 9

pbejse
Mentor
Mentor

@Philip-John wrote:

I have got the following lisp to display area inside the box. But the text is in 0°. Can somebody help me to modify the lisp to display text in various angles. i.e 90°, 180°, 270° ?

 


Via user prompt before you place the text? 

 

0 Likes
Message 3 of 9

hak_vz
Advisor
Advisor
Accepted solution

Try this

 

(vl-load-com)
(defun c:TXTAREA (/ area ent flag lst obj pt tmpH)
(if (or (not *Hscl*) (/= (type *Hscl*) 'REAL))
(setq *Hscl* (getvar 'TEXTSIZE))
)
(initget 6)
(setq tmpH (getreal (strcat "\nSpecify Text Height: <" (rtos *Hscl*) ">: ")))
(if (/= tmpH nil)
(setq *Hscl* tmpH)
)
(while (null flag)
(cond ((setq pt (getpoint "\nSpecify internal point <exit>: "))
(if (and (setq lst (entlast))
(vl-cmdf "_.-boundary" pt "")
(setq ent (entlast))
(not (eq lst ent))
)
(progn
(setq obj (vlax-ename->vla-object ent)
area (vla-get-area obj)
)
(setvar 'TEXTEVAL 1)
(setvar 'TEXTEVAL 0)

(entmake (list
'(0 . "TEXT")
(cons 10 (trans pt 1 0))
(cons 40 *Hscl*)
(cons 1 (strcat (rtos area 2 2) " m\U+00B2"))
(cons 50 (getangle "\nEnter or pick text angle >" pt))
)))))
(T
(setq flag T)
)))
(princ)
)

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
Message 4 of 9

Philip-John
Advocate
Advocate

...

0 Likes
Message 5 of 9

Philip-John
Advocate
Advocate
Can you make it in both ways?
0 Likes
Message 6 of 9

Philip-John
Advocate
Advocate
Thanks..
Can you make it for fixed angle that I will set in lisp itself?
0 Likes
Message 7 of 9

hak_vz
Advisor
Advisor
Accepted solution

This line defines angle

(cons 50 (getangle "\nEnter or pick text angle >" pt))

Instead (getangle....)) enter angle in radians an that's it.

(cons 50 0.7......)

You can have multiple versions of this function i.e txtarea45 txtare90

 

Miljenko Hatlak

EESignature

Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
0 Likes
Message 8 of 9

pbejse
Mentor
Mentor
Accepted solution

@Philip-John wrote:
Can you make it in both ways?

Sure

 

(defun c:TXTAREA (/ area ent flag _Text lst obj pt tmpH gr data ct)
(defun _Text (pt  / obj area text)
  (if (and (setq lst (entlast))
	   (vl-cmdf "_.-boundary" pt "")
	   (setq ent (entlast))
	   (not (eq lst ent))
      )
    (progn
      (setq obj  (vlax-ename->vla-object ent)
		area (vla-get-area obj))
      (entmakex
			(list
			  '(0 . "TEXT")
			  (cons 10 (trans pt 1 0))
			  (cons 40 *Hscl*)
			  (cons 1 (strcat (rtos area 2 2) " m2"))
			  (cons 50 Txrot)
			)
	         )
      )
    )
)  
  (if (or (not *Hscl*) (/= (type *Hscl*) 'REAL))
    (setq *Hscl* (getvar 'TEXTSIZE))
  )
  (initget 6)
  (setq	tmpH (getreal
	       (strcat "\nSpecify Text Height: <" (rtos *Hscl*) ">: ")
	     )
  )
  (if (/= tmpH nil)
    (setq *Hscl* tmpH)
  )
(setq Txrot (cond
    ((getangle
        (strcat "\nEnter rotation <" (angtos (setq Txrot
              (cond ( Txrot ) ( (angle '(0.0 0.0) (getvar 'UCSXDIR)) ))
            ) 0 2
          )
          ">: "
        )
      )
    )
    ( Txrot )
  )
)
(if (setq pt (getpoint (strcat "\nSpecify internal point <exit>: ")))
	(progn
	  (setq ct  (_Text pt))
	     (princ "\nSpecify Next Point [Rotate]:<exit> ")
	      (while
	        (progn
	          (setq gr (grread t 15 0) code (car gr)
	               data (cadr gr)
	          ) 
	          (cond
	            ((= 5 code)  data)
	            (
	              (and (= 2 code)(member  data '( 114 82)))
			(Vlax-put (Setq ev (vlax-ename->vla-object ct)) 'Rotation
				  (setq Txrot (+ (vlax-get ev 'Rotation) (/ pi 2.0))) )
	              t
	            )
	            ((= 3 code)
		     (setq ct (_Text data))	      
	            )
	          )
	        )
	      )
	    )
  	)
  (princ)
)

 

Command: TXTAREA

Specify Text Height: <0.20>: .2

Enter rotation <0.00>: Enter

Specify internal point <exit>:
Specify Next Point [Rotate]:<exit>

 

Command: TXTAREA

Specify Text Height: <0.20>: .Enter

Enter rotation <0.00>: 45

Specify internal point <exit>:
Specify Next Point [Rotate]:<exit> Pressed "R"  and the text will rotate 90 degrees counter clockwise 

 

HTH

 

0 Likes
Message 9 of 9

Philip-John
Advocate
Advocate
Thanks a lot pbejse..
Your lisp is wonderful..
0 Likes