Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Keeping text horizontal when rotating

9 REPLIES 9
Reply
Message 1 of 10
johnw
1329 Views, 9 Replies

Keeping text horizontal when rotating

I am trying to find a lisp routine that would allow me to rotate single letter text around a central point but keep the text (letters) horizontal as I rotate the letters about that central point. Is there anything out there that could accomplish this. Thank you in advance.

 

John W.

9 REPLIES 9
Message 2 of 10
3wood
in reply to: johnw

You can change the text justification to CENTER with TJUST command, rotate drawing, select all objects, from the filter list on top of the property panel, select TEXT or MTEXT, then change rotation to 0.

Message 3 of 10
Kent1Cooper
in reply to: johnw


@Anonymous wrote:

I am trying to find a lisp routine that would allow me to rotate single letter text around a central point but keep the text (letters) horizontal as I rotate the letters about that central point. Is there anything out there that could accomplish this. Thank you in advance.

 

John W.


A couple of questions:

 

Are you talking about doing it to one single-letter Text entity at a time, or a selection of more than one?

 

When you say "...as I rotate...", do you mean while your are rotating it, that is, dynamically, that is, you want to see it rotating around the base point but staying horizontal as you drag the rotation angle?  [I think that's possible, though probably easier for a single piece of Text than for multiples.]  Or is it enough for it/them to have its/their text-rotation angle returned to horizontal after it's/they've been rotated around the base point?  [That would be a lot simpler, code-wise, and wouldn't be much more complicated for multiples than for singles.]

 

[And I would go for Middle or Middle-Center justification, rather than Center, if it isn't already justified in one of those ways.  That should keep the overall location more where you'd expect it to end up.]

Kent Cooper, AIA
Message 4 of 10
Anonymous
in reply to: johnw

I got my inspiration for this from the c:yinyang function that I found on this site some time back. I forget who wrote it. (Whoever did - thanks, I could not figure out GRREAD until then)

 

This will ask you to select a center point about which to rotate a selected entity. (TEXT in this case - though anything with a group code 10 will do ... something)

 

 (defun c:MTA (/ cen loop tx_dxf tx_cen gr p1 p2)
 ;; MoveTextAround
 ;;This actually has a curious effect on any entity with a group 10 code.
 	(setq	cen  (getpoint "\nCenter: ")
 		loop T
 		tx_dxf (entget (setq tx (car (entsel "\nSelect TEXT to move around : "))))
 		tx_cen (cdr (assoc 10 tx_dxf))
 	)
 	(while (and (setq gr (grread T 12 0)) loop)
 		(cond
 			((= (car gr) 5)
 				(setq p1	(cadr gr)
 					p2	(polar cen (angle cen p1) (distance cen (cdr (assoc 10 tx_dxf))))
 					tx_dxf (subst (cons 10 p2) (assoc 10 tx_dxf) tx_dxf)
 				)
 				(entmod tx_dxf)
 			)
 			((= (car gr) 3) (setq loop nil))
 		)
 	)
 	(princ)
 )

 

Message 5 of 10
johnw
in reply to: Kent1Cooper

Hi Kent, Let's say I have a letter "A" placed at the top quadrant of a circle. I want to enter the rotate command and select the letter A and pick any base point. As I rotate the text, it would remain horizontal AS I ROTATE IT. Thanks for the info provided as well as any response to this portion.

 

John W.

Message 6 of 10
pbejse
in reply to: johnw


@Anonymous wrote:

Hi Kent, Let's say I have a letter "A" placed at the top quadrant of a circle. I want to enter the rotate command and select the letter A and pick any base point. As I rotate the text, it would remain horizontal AS I ROTATE IT. Thanks for the info provided as well as any response to this portion.

 

John W.


Nothing Fancy

 

(defun c:rth ( / ss )
(vl-load-com)  
  	(setq ss (ssget "_:L" '((0 . "*TEXT"))))
  		(command "_rotate" ss "" pause pause)
  		(repeat (sslength ss)
		  	(vla-put-rotation (vlax-ename->vla-object (ssname ss 0)) 0.0)
		  	(ssdel (ssname ss 0) ss))
  (princ)
  )

 

Or a more simple solution is  you could use an Annotative TEXT style with "Match orientation to Layout" 

 

HTH

 

 

Message 7 of 10
Anonymous
in reply to: johnw

I'm curious, did the code I put up the other day not work? It does do what you are asking.

 

I know it only works with LEFT justified text but, I revised my copy a little so it will work with any justification. I could post it if you'd like.

Message 8 of 10
Kent1Cooper
in reply to: Anonymous


@Anonymous wrote:

I'm curious, did the code I put up the other day not work? It does do what you are asking.

 

I know it only works with LEFT justified text but, I revised my copy a little so it will work with any justification. I could post it if you'd like.


It worked for me.  I'd be interested in seeing the any-justification version, because I tried some quickie adjustments to achieve that, but must have done something wrong.

Kent Cooper, AIA
Message 9 of 10
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:

....  I'd be interested in seeing the any-justification version, because I tried some quickie adjustments to achieve that, but must have done something wrong.


I figured out a way [perhaps different from bobdobbs's way, but...].  I added rubber-banding of the rotation angle, too.

 

(defun c:MTA (/ cen loop tx_dxf tx_j tx_cen gr p1 p2)
;; MoveTextAround
;; By bobdobbs at AutoCAD Customization Discussion Group [originally
;; for Left justification only], modified by Kent Cooper for any justification
;; and to add rubber-banding of rotation angle.
  (setq
    cen (getpoint "\nCenter: ")
    loop T
    tx_dxf (entget (setq tx (car (entsel "\nSelect TEXT to move around : "))))
    tx_j (if (= (cdr (assoc 72 tx_dxf)) (cdr (assoc 73 tx_dxf)) 0) 10 11); Left-just. vs. others
    tx_cen (cdr (assoc tx_j tx_dxf))
  ); setq
  (while (and (setq gr (grread T 12 0)) loop)
    (cond
      ((= (car gr) 5); move cursor
        (redraw); [to keep rubber-band lines from "sticking"]
        (setq
          p1 (cadr gr)
          p2 (polar cen (angle cen p1) (distance cen (cdr (assoc tx_j tx_dxf))))
          tx_dxf (subst (cons tx_j p2) (assoc tx_j tx_dxf) tx_dxf)
        ); setq
        (grdraw cen p2 8 1); rubber-banding
        (entmod tx_dxf)
      ); 5 condition
      ((= (car gr) 3) (setq loop nil)); pick point
    ); cond
  ); while
  (redraw); [clear last rubber-band line]
  (princ)
)

 

[And by the way, as with bobdobbs's original for Left-justified Text, it doesn't make the selected Text always horizontal as in the OP's request, but keeps it at its original rotation angle, whatever that is.  It could be made to force selected Text of any rotation to zero rotation, if desired.]

Kent Cooper, AIA
Message 10 of 10
Anonymous
in reply to: Kent1Cooper

Dang!

 

I did the rubber band thing too only I didn't think about REDRAW to clear the previous one so it looked like ...well... it looked bad and I took it out. (I'll put it back when I get a chance now)

 

I did pretty much the same thing to accomodate other justifications too. IE: check the 72 & 73 but, in addition to that, I also make sure it's TEXT. I liked being able to swing around other entity types as well.

 

True too on the original rotation. I just figured the text was probably already oriented correctly.

 

 

 

(defun c:MEA (/ cen loop tx_dxf gr p1 p2)

 ;; MoveTextAround
 ;;This actually has a curious effect on any entity with a group 10 code.
	(command "undo" "m")
 	(setq	cen  (getpoint "\nCenter: ")
 			loop T
 			tx_dxf (entget (setq tx (car (entsel "\nSelect ENTITY to move around : "))))
			old_cmd	(getvar "cmdecho")
	)
	(setvar "cmdecho" 0)
	(if (and (= (cdr (assoc 0 tx_dxf)) "TEXT") (or (/= (cdr (assoc 72 tx_dxf)) 0) (/= (cdr (assoc 73 tx_dxf)) 0)))
		(setq tx_grp 11)
		(setq tx_grp 10)
 	)
 	(while (and (setq gr (grread T 12 0)) loop)
 		(cond
 			((= (car gr) 5)
 				(setq p1	(cadr gr)
 					p2	(polar cen (angle cen p1) (distance cen (cdr (assoc tx_grp tx_dxf))))
 					tx_dxf (subst (cons tx_grp p2) (assoc tx_grp tx_dxf) tx_dxf)
 				)
 				(entmod tx_dxf)
 			)
 			((= (car gr) 3) (setq loop nil))
 		)
 	)
	(setvar "cmdecho" old_cmd)
 	(princ)
)

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost