Author Topic: Rotate Text about the ML or MR  (Read 260 times)

0 Members and 1 Guest are viewing this topic.

Browny501

  • Mosquito
  • Posts: 15
Rotate Text about the ML or MR
« on: March 24, 2020, 09:45:15 AM »
Hi All

I'm trying to rotate text about the "Left" or "Right" justification depending how it appears on the screen.

Text in the attached image has been drawn either "ML" or MR" justified, the below is fine for the left, what do i need to do to get it to do the same for right justification. 



Code: [Select]
(defun ROTATE_TXT ( / SR TXT_INSERT)
(Setvar "osmode" 0)
 (while (NOT SR)
     (setq SR (entsel "\nSelect text to rotate"))
      (if (NOT SR)
          (princ "\nYou missed the text. Try again")
      )   ; end if NOT
  )
  (setq TXT_INSERT (cdr (assoc 10 (entget (car SR)))))
  (setq TXT_ANG    (cdr (assoc 51 (entget (car SR)))))
  (command "ROTATE" SR "" TXT_INSERT "R" TXT_ANG pause )
(princ)
)

Thanks

tombu

  • Newt
  • Posts: 175
  • ByLayer=>Not0
Re: Rotate Text about the ML or MR
« Reply #1 on: March 24, 2020, 09:58:14 AM »
Look at DXF code 72 for text justification and DXF code 11 not equal to (11 0.0 0.0 0.0) for rotation point.
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

Lee Mac

  • Seagull
  • Posts: 12356
  • London, England
Re: Rotate Text about the ML or MR
« Reply #2 on: March 24, 2020, 11:34:20 AM »
You have a couple of issues:
  • DXF group 10 represents the insertion point whereas DXF group 11 represents the text alignment point.
    DXF group 11 will only be valid when either DXF group 72 or 73 is non-zero (i.e. when the justification is something other than Left).
  • The text rotation is given by DXF group 50 (DXF group 51 refers to the Oblique Angle) and is expressed in radians, whereas the ROTATE command is expecting a value in degrees.

Browny501

  • Mosquito
  • Posts: 15
Re: Rotate Text about the ML or MR
« Reply #3 on: March 24, 2020, 02:31:34 PM »
Food for thought...wish me luck...many thanks

Browny501

  • Mosquito
  • Posts: 15
Re: Rotate Text about the ML or MR
« Reply #4 on: March 24, 2020, 03:28:57 PM »
Its a bit clunky, but works to a degree (sorry about the pun)

thanks Tombo and Lee for your help

Code: [Select]
(defun ROTATE_TXT ( / SR TXT_INSERT
         TXT_INS_L TXT_ANG_DEG
         TXT_INS_R TXT_ANG_RAD )
(Setvar "osmode" 0)
 (while (NOT SR)
     (setq SR (entsel "\nSelect text to rotate"))
      (if (NOT SR)
          (princ "\nYou missed the text. Try again")
      )   ; end if NOT
  )
  (setq TXT_INS_L   (cdr (assoc 10 (entget (car SR)))))
  (setq TXT_INS_R   (cdr (assoc 11 (entget (car SR)))))
  (setq TXT_ANG_RAD   (cdr (assoc 50 (entget (car SR)))))

  (setq TXT_ANG_DEG (* (/ TXT_ANG_RAD pi) 180.0))
   
  (setq JUST      (cdr (assoc 72 (entget (car SR)))))
  (If
   (= Just 0)
    (setq TXT_INSERT TXT_INS_L)
    (progn (setq TXT_INSERT TXT_INS_R)
           (setq TXT_ANG_DEG (- TXT_ANG_DEG 180))
    )
  )
    (command "ROTATE" SR "" TXT_INSERT "R" TXT_ANG_DEG pause )
(princ)
)

Lee Mac

  • Seagull
  • Posts: 12356
  • London, England
Re: Rotate Text about the ML or MR
« Reply #5 on: March 24, 2020, 04:54:28 PM »
Note that you'll need to check that DXF groups 72 & 73 are both zero (i.e. for Left justified text) in order to ascertain whether you should use DXF group 10 or DXF group 11 as the base point for the rotation. You may also want to verify that the user has indeed selected a TEXT object, as opposed to any other object, and provide the user with a way to exit the program at the selection prompt, without needing to press ESC and force an error (though, admittedly, a clean exit is not possible whilst pausing for input within the ROTATE command).

I might be inclined to write the function in the following way:
Code - Auto/Visual Lisp: [Select]
  1. (defun rotate_txt ( / ent enx ) ;; Define function, declare local variables
  2.     (while ;; While the following expression returns a non-nil value
  3.         (progn ;; Evaluate the following expressions and return the value returned by the last evaluated expression
  4.             (setvar 'errno 0) ;; Clear the ERRNO system variable
  5.             (setq ent (car (entsel "\nSelect text to rotate: "))) ;; Prompt the user for a selection
  6.             (cond ;; Evaluate the following test expressions until an expression returns a non-nil value
  7.                 (   (= 7 (getvar 'errno)) ;; User selected empty space
  8.                     (princ "\nMissed, try again.") ;; Stay in loop
  9.                 )
  10.                 (   (null ent) ;; User dismissed the prompt
  11.                     nil ;; Exit loop
  12.                 )
  13.                 (   (/= "TEXT" (cdr (assoc 0 (setq enx (entget ent))))) ;; Object isn't text
  14.                     (princ "\nThe selected object is not a single-line text object.") ;; Stay in loop
  15.                 )
  16.                 (   (command "_.rotate" ent ""
  17.                         (trans (cdr (assoc (if (= 0 (cdr (assoc 72 enx)) (cdr (assoc 73 enx))) 10 11) enx)) ent 1)
  18.                         "_R"
  19.                         (* 180.0 (/ (+ (cdr (assoc 50 enx)) (if (= 2 (cdr (assoc 72 enx))) pi 0)) pi))
  20.                         "\\" ;; Safer than using pause
  21.                     ) ;; end command
  22.                 )
  23.             ) ;; end cond
  24.         ) ;; end progn
  25.     ) ;; end while
  26.     (princ) ;; Suppress the value returned by the last evaluated expression
  27. ) ;; end defun
« Last Edit: March 24, 2020, 04:58:10 PM by Lee Mac »

Browny501

  • Mosquito
  • Posts: 15
Re: Rotate Text about the ML or MR
« Reply #6 on: March 25, 2020, 06:54:09 AM »
Wow. thanks for that, I'll be sure to put a thanks in the final code.....if i ever get to the full thing to work